|
|
8 q$ `) X4 A$ _行,这个怎么样2 Z/ w* S h, s) {& y
- package com.xhg78999.mtrfac.render;( X% b0 c1 H9 s* e
; e$ S' |, g) p* z- import com.mojang.blaze3d.vertex.PoseStack;! i" k: O; L5 k. t4 R( E
- import com.mojang.blaze3d.vertex.VertexConsumer;+ H7 _+ J T8 Y" E. P4 V1 `( A
- import net.minecraft.client.renderer.RenderType;
) q" }' r. B4 p5 a( @+ @7 J - import net.minecraft.resources.ResourceLocation; h* F: N/ ^; w* B9 H
$ O& C' o# P. v- import java.util.*;
9 x1 l) \) ?9 h3 [% _ - ) y6 @4 ? k( h3 n. i1 P5 T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
H9 W X1 I; `9 F7 ^& |6 D, X - 8 K# m" k1 s; _+ l% ~# A* g8 V, V
- public class LineRender{
5 ]# J7 g: A! A0 R( s: K7 [: U5 D - private final PoseStack pose;
/ s! ?& b* o% S) P( ]( s; {1 Y' Q; X' [ - private final MultiBufferSource source;4 ?, r3 m: f+ C) X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) u9 O" X, t( K+ [/ \4 K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
u. u6 ^# z, W - ( z8 Q8 z2 _1 K
+ } P0 ?7 Y" w) u- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ y1 t* y7 l# {( u9 q
- if(x1 == x2 && y1 == y2 && z1 == z2){: o' {8 C2 _( U4 n- a% r6 D
- return;4 u' e% x6 v8 E9 [" l
- }
4 G& `9 o# u8 q# P9 u% J, b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){5 z) _7 X Q2 G, N; T
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 `. {0 r8 N5 r
- }$ S9 x5 E1 N8 e2 O
- pose.pushPose();
- t+ L3 z1 N$ X1 X: H - final int newLight = convertLight(6);
. _6 H( n$ Z( e8 \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" M. q- F1 @) f
- final float lineHeightSmall = (y2 - y1);
) _# j* F* V8 ~2 H! W9 V - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- b7 Z) R% Z: a* n5 x - pose.popPose();
& q4 R0 x P+ O. ]! G; c - }
, G# A' \5 W7 q3 w! R: H* Z6 H) \
9 }8 Y, V8 G" U: c3 P# s- private RenderType getLayers(String texture, int light) {- t3 t- ?8 y' ]# f; }
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 c7 i/ w: l! ^$ O5 o. r" S$ S7 i
- }
1 O ?& @6 g; g2 m( f - / r. `6 j, Y: y8 W
- private RenderType getLightTexture(ResourceLocation texture) {+ ?1 B# m1 y3 z2 z" C. E5 _& S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! I! l. K. [% i8 N9 K
- }
& g+ Q; u- M! k
9 L& f8 Y' H2 } m2 t) [4 C- private RenderType getTexture(ResourceLocation texture) {' `' U* x: F6 X
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);9 \; m8 N. N" e
- }: I9 v; u3 N% `
& C1 ?! I6 a F; A! r4 y1 O% _% f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* g: h( x- d2 g - if (cache.containsKey(identifier)) {
4 b9 Z, l ^' ?. V5 C+ Y* k, s3 p - return cache.get(identifier);
9 {" r9 V7 ?5 V2 J G/ M3 P - } else {3 }" Q% g$ N7 m9 M1 J9 v$ n
- final RenderType renderLayer = supplier.get();
9 d/ ~5 P. B* F" \2 I5 W& y - cache.put(identifier, renderLayer);
6 k- j) n6 N' B3 Z8 C' c" v' k0 r - return renderLayer;
/ N& g6 Z9 `+ l9 b% |$ p - }
4 K- ]. y& |" w; e - }
1 q3 \( x- w4 c! j5 E' i - }
复制代码 |
|