|
|
: Q: B5 ~3 R' m3 i+ C4 ?$ q
行,这个怎么样
& G9 Z) A4 D! j) b0 f- package com.xhg78999.mtrfac.render;2 Q* Q" [0 o Y0 t5 z* P; |% X4 b
- $ Q/ T7 w% v: J
- import com.mojang.blaze3d.vertex.PoseStack;5 \- X9 Q2 k2 l; y5 l
- import com.mojang.blaze3d.vertex.VertexConsumer;, P" j) Z& @9 [3 d+ e
- import net.minecraft.client.renderer.RenderType;. D( i2 t+ j7 D
- import net.minecraft.resources.ResourceLocation;' S& C' }* c9 c* w C1 s2 s. ]
, C% f( g" j$ E: ~( n1 w# z- import java.util.*;2 {1 T1 \1 _, Y( n; s G
- % h) M* r/ d- ]% f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" E2 _. A7 \+ e: k9 B) Z2 L. J5 ? - 4 b$ m6 F9 d! y
- public class LineRender{
; M, @: S4 [* l1 i% Z" c1 p - private final PoseStack pose;& M/ N f6 b; {$ n5 f! M
- private final MultiBufferSource source;
! D) a0 O3 p& q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();# l* w# i: ^' J, M( r1 K& v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
2 _7 S4 E+ `4 h1 Q9 t6 g% x4 H) P - J. u! ?7 m( W* A3 H
- . Y$ x+ x0 E2 d7 c& p6 f: T6 `
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ C8 K' f" I; D5 M% E
- if(x1 == x2 && y1 == y2 && z1 == z2){: g H/ D3 N- U. b' i
- return;
3 S8 ~6 a. q# b6 ]5 Y1 F' Z - }
# i7 @& m8 H# D. C9 o- R - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 H: l+ ~+ q: p q: g5 c/ P5 c
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: S5 J, w- f! b8 O3 L8 |
- }
# b7 A) S$ O3 y2 X) L - pose.pushPose();
8 n, g5 w; k% ?+ s7 G8 w - final int newLight = convertLight(6);0 e2 a+ z- C6 i: S
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* ]- {( P3 W% I w4 Z. [ - final float lineHeightSmall = (y2 - y1);
; u# ]& D4 N( @/ O) ]% X. t - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& a; A1 H5 {5 W) @
- pose.popPose();' D, G" B# T% @5 T; x, k s! y
- }
/ M) E5 V# ^" t, _ - $ ]* G; a- u! n7 J* S D: ~+ |
- private RenderType getLayers(String texture, int light) {
5 U N+ U+ I; A' }. m/ c0 P - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: M. s/ \! n# Z+ X$ t: r
- }' {/ D8 ]1 y* o) C6 }( m
' f2 E& `2 V) G r/ X- private RenderType getLightTexture(ResourceLocation texture) {
5 O7 b/ {! g1 Q& V: M0 Q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' ]$ z! o, j5 \! [ a' K& G
- }
. a( l6 f: b q6 l1 _! K. G- H
8 ?% B9 x0 [+ Y: {: v& V+ b- private RenderType getTexture(ResourceLocation texture) {
; J. y, w0 f2 B' E" C1 ?% w* D% H$ _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);9 G1 g) M4 N) h7 e: z- {* ~: i }9 h
- }3 r+ p8 K- ]% a" I; L3 i# _: p" S
$ d0 E# f% u ^. c; y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* `( d% O) S! B0 x
- if (cache.containsKey(identifier)) {, u1 Y) j* Q, G$ l( j! I' o" J
- return cache.get(identifier);& V( m2 ]0 P( R2 v; u
- } else {: S3 m0 N3 n7 ~ }1 Z- _. A
- final RenderType renderLayer = supplier.get();
- t/ [5 z/ x$ k; V* l$ K - cache.put(identifier, renderLayer);9 R# ^9 Q* h& L3 C2 ]& n& W/ ^
- return renderLayer;
; m. N' \8 |: I/ J - }
4 ]% K S+ M2 b4 S - }3 Q( g2 h# s0 ^) T
- }
复制代码 |
|