|
|
/ ^$ O0 l) A" j0 ]$ y行,这个怎么样5 I# L+ b5 [" u) U
- package com.xhg78999.mtrfac.render;
! G5 Q( ~6 |4 A* n" Y
3 m! [" d0 r: ^* @( T- _- import com.mojang.blaze3d.vertex.PoseStack;
^1 x: O7 z4 V* {) |3 ~ - import com.mojang.blaze3d.vertex.VertexConsumer;
% O8 p ~. f+ ?9 T* ~1 N9 ] - import net.minecraft.client.renderer.RenderType;
* g2 L" M6 t2 m/ Q - import net.minecraft.resources.ResourceLocation; u/ b* {. }1 n7 m
- 1 N- |7 k6 G o# y
- import java.util.*;+ k- s6 p9 B# A6 F* t
0 C2 I+ M* j* {. Y: y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 [; Y. u: u0 U# S/ l
: j: b% U2 j2 I% N$ J# _4 j6 ]$ X& q! j- public class LineRender{, f1 ~) m8 q' M. g! a/ o( h2 d& R
- private final PoseStack pose;
) v+ }, T2 g9 n) M( `8 U - private final MultiBufferSource source;
# @ g) J7 P0 N2 |: t/ t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ U1 X! |* a! Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. Q* Y5 ?- C7 V# T" l4 j
: ~6 l3 g `& G! b8 L! i0 L- ; M, |6 W+ j! G7 i) u! t2 }) |
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 Y/ W# Z0 B/ H3 P8 P. S" Z# V- G - if(x1 == x2 && y1 == y2 && z1 == z2){
& H2 L, c6 @/ ~( ] - return;/ T/ T- m# b% @. O. h$ D* C
- }6 P {0 S) i2 A
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% n+ ?( p& j4 Y) V3 D7 F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ r" t4 q0 f Q3 r/ } - }7 z/ @& p( c; \$ a/ S$ t! @
- pose.pushPose();
+ m# C/ V) l& M8 r( W* _3 r: O/ [4 w - final int newLight = convertLight(6);' v3 x8 \) W7 ~5 H2 U3 `- C
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% B' {8 K3 v+ \2 J& A( | - final float lineHeightSmall = (y2 - y1);
! h; ]8 e; g+ S6 w& v$ ^5 O0 z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% t' R* e9 O5 k5 W$ k
- pose.popPose();7 S! T3 l0 s+ r: x. {! g
- }
' y$ ?/ X) W0 \! y
5 @7 d, Z/ n! c+ |/ }+ C) ~2 }; o0 D- private RenderType getLayers(String texture, int light) {
: H5 q: ]5 I! Y% N* ~# E: @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));( p0 j& V( n- S
- }
2 N! ^3 z6 f7 T5 _; l) I+ M+ G - 7 T; u+ G9 m- }- s$ t+ |8 i) V
- private RenderType getLightTexture(ResourceLocation texture) {
( ]$ E8 o4 w) X8 q$ k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* o+ G0 J0 ^7 @! W" z
- }
# g( J* ^, h3 q9 @/ J - - x1 f- \1 ^. P
- private RenderType getTexture(ResourceLocation texture) {
- D- C1 c W/ C' V! [& y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
$ `$ [) m6 f/ W4 F9 F+ O! o - }1 B' R$ O5 B3 r4 R
* n( k- ?: s; a; T( K0 \- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* {% h# B0 Q0 I! ^5 @& t1 \
- if (cache.containsKey(identifier)) {$ V4 {: `6 N$ T1 ^% H' O+ H g+ f
- return cache.get(identifier);
) B# G1 e$ o: s: u. K - } else {' K1 x2 O% Y. u" I
- final RenderType renderLayer = supplier.get();2 [0 X( A- \6 t! _8 d2 {! a0 k" U
- cache.put(identifier, renderLayer);
2 m; r* N, Q& I/ }# W. ^ - return renderLayer;
* [- ^6 G. o' Z, o# S# C( K% d - }
! V, C: ?+ J* W - } a! {& r2 I9 x5 x0 P, ^0 c- M3 s! {+ r `
- }
复制代码 |
|