|
|
- J4 U8 ~) J6 f" A+ J) u6 q
行,这个怎么样% O' _2 E3 B( s
- package com.xhg78999.mtrfac.render;3 @# f1 e; B: K: V, x% V" y
- + r' M9 W/ d, }( k
- import com.mojang.blaze3d.vertex.PoseStack;2 P9 n- j) j. K* U: P: C) \4 V: ?) k) Z
- import com.mojang.blaze3d.vertex.VertexConsumer;- R8 A% r! s7 g2 V0 M$ |
- import net.minecraft.client.renderer.RenderType;
" ~9 T" h3 y& Q9 y$ U8 I - import net.minecraft.resources.ResourceLocation;0 h9 d% ]* w0 z1 L' N! i; a
- L P k0 I c+ |) s
- import java.util.*;+ g8 P$ u) x% n( p3 s% @
) x( ~ {8 J: B) x- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! x% J) G; G8 c$ Z+ C
3 A! N7 l6 G) t, y+ g/ |& z0 K- public class LineRender{
" V, Q* u; J; I1 r - private final PoseStack pose;
8 S9 E; I! Z3 j1 ~: _* p- D - private final MultiBufferSource source;
3 X4 g, G$ y5 ~: H - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ t z2 s/ L$ L; p; l: ? A5 m* J - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& ^. W$ a, H+ L/ U. V3 n - 3 X( N/ e3 r% }& j2 ?
- 7 Q4 ^2 B* f) d0 k1 u: I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 V% ^7 h5 `0 q! I% R - if(x1 == x2 && y1 == y2 && z1 == z2){) X4 f! \1 {( ^% x4 f" r
- return;
) L |& c" r( _+ x* y - }
/ N2 ]( u* h! l( ^: [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ s- k, y) s' H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 x: P" c; F" A7 T& o: w
- }
' x' ? u) X$ h$ y - pose.pushPose();- C6 [- F$ i* q4 t* j& c, {3 |
- final int newLight = convertLight(6);8 H' x N2 E w: m2 N
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));- [$ B6 p' O* U. Q7 _
- final float lineHeightSmall = (y2 - y1);
D( U' N8 G7 s! B h4 X: w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. L$ {$ X) N7 ^" d- ~' l - pose.popPose();
! C2 |7 z5 \; w6 V* `( L# J - }
8 p& t/ C, M+ N* b
. p6 r7 B/ K8 Y6 x. E- private RenderType getLayers(String texture, int light) {& t( o" z; `1 F
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 O( R1 D/ ]9 u3 w7 V& x" u5 S
- }
) s* u% `. c0 _) K' D K - 5 i2 |8 I& `9 C3 p& V
- private RenderType getLightTexture(ResourceLocation texture) {
2 k; s7 n2 F C, L% ~- |! L" D - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 k I1 _( _" ^. q2 h- ^9 l$ t
- }1 [' P$ E) H1 J: g/ m- k
- 9 M2 s6 @2 H. p' \5 `
- private RenderType getTexture(ResourceLocation texture) {, s' ?6 r+ h4 O$ t+ Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# v+ i+ h/ P S! G
- }+ X7 W* z/ P$ q" t+ }: D
6 B$ U! P8 n9 I- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" f- l" A; ~9 R
- if (cache.containsKey(identifier)) {- {6 O- _7 L" B9 x4 ^, J
- return cache.get(identifier);, I: H* q, c. w, {0 q) P
- } else {3 J+ _' @/ ^$ ^* \: N" v
- final RenderType renderLayer = supplier.get();
" H) ]3 Q, u' ~! S - cache.put(identifier, renderLayer);
/ x9 `" s) M; G5 W7 } - return renderLayer;
- ~, b3 T- }# p( Q" H* T8 i, j% i8 H - }
S+ O2 R/ X% N0 j4 ]$ z$ o2 x - }
/ v& b/ @, k- J6 { - }
复制代码 |
|