|
|
& u4 P: z. F9 H( I
行,这个怎么样2 L$ L4 c1 C- }% }+ h' k
- package com.xhg78999.mtrfac.render;
% b: B3 H) S2 E- V R. F, x
T" h9 n2 O/ y+ N' U- import com.mojang.blaze3d.vertex.PoseStack;
) C4 u& k( U* Q' j - import com.mojang.blaze3d.vertex.VertexConsumer;
9 p: m) I' h9 T! h, O" Z5 n - import net.minecraft.client.renderer.RenderType;, J4 o! o* r% i6 v3 c
- import net.minecraft.resources.ResourceLocation;
7 S9 O5 T& T* |% d$ [8 p - ' F5 z2 p7 e* o
- import java.util.*;& ~5 k( {$ ^, P4 o! [- J
- 7 @) p7 P! k6 I
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(9 m; S5 n0 @8 p a" m" f
& P7 f! L( V7 D+ {, N- public class LineRender{$ f2 T" e; f( C8 q
- private final PoseStack pose;
" P$ e/ Z4 V5 `2 g - private final MultiBufferSource source;
: d: v/ d) R# x2 [5 i( N0 u$ C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* ]1 W5 Y3 o, b. k7 n6 C) W8 [ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, M: t' M' g! U$ a5 s
( q3 P% \( E; h/ \
* P' {$ M2 g7 B0 `" b- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* a. I6 D: n6 ~2 m, m- w - if(x1 == x2 && y1 == y2 && z1 == z2){8 R& V+ G9 E# f6 s
- return;
! K- |* } F+ |( f - }# y4 E2 `: R0 t4 J0 Z& }
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 B2 ]% b* \2 h& t, \) } - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% V& @5 x5 H( d9 L5 x9 R7 r
- } q2 K" }. Y) n. l8 |
- pose.pushPose();. u- ?* D% N# G4 h
- final int newLight = convertLight(6);; h) m w" O/ W; D! O
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
. Z0 i( ^! q) d3 l$ O; W - final float lineHeightSmall = (y2 - y1);! V1 Y( b, J! z8 y7 G9 }' ] `
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( I. r G$ a/ \2 m( m V, F
- pose.popPose();' f& D3 e' Q7 V& `, O @0 }
- }7 S4 C0 }( i0 S3 d, b. v% P
- 3 M$ y! H4 i. n: c( \4 U5 N. b0 L
- private RenderType getLayers(String texture, int light) {4 ~9 r1 i2 X( X& i6 T
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ }5 _" f) s0 N, i Z - }! @2 E& a, s; t/ g
/ f2 N$ O$ n4 n* p2 D( ~+ N- private RenderType getLightTexture(ResourceLocation texture) { C# |- ~$ b; H0 r' }
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' E3 I9 L, F3 t z1 O
- }
2 V& \* b( C( h0 @# z - 7 X( M9 }* L# J+ g4 o
- private RenderType getTexture(ResourceLocation texture) {
, |: f# @ c0 f$ U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 F9 a3 m* y( k4 g% Y
- }1 m1 R- T- f; T' b8 d
- 3 l3 n6 z4 h p3 ]! W s( a
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' \2 i6 D) O% e$ `; \6 W
- if (cache.containsKey(identifier)) {
& E5 m* z$ h0 @* D5 n* l3 ~; s - return cache.get(identifier);0 A. s, f) W' X2 _. T; c
- } else {
1 r$ x0 s% F" Z4 `0 Z - final RenderType renderLayer = supplier.get();- [& E; g' u. R
- cache.put(identifier, renderLayer);
* D$ d) M, O4 h: f& p - return renderLayer;
1 b" J$ x$ y3 y* E( X4 e. F; P( u - }
8 W" C ~1 R0 l8 J - }) q' p3 C: F% b& g
- }
复制代码 |
|