|
|
. Y9 L4 N0 B5 f; c( W行,这个怎么样$ ?4 w* h- f) T7 T
- package com.xhg78999.mtrfac.render;. v! ~7 O: ^# J, c1 u z; c
% L( G3 j( p( k: N- import com.mojang.blaze3d.vertex.PoseStack;1 n. q3 \: N7 m, `
- import com.mojang.blaze3d.vertex.VertexConsumer;
' a2 }* F" e2 r0 X - import net.minecraft.client.renderer.RenderType;
7 Z$ X7 o+ q9 p* P. N; }. ` - import net.minecraft.resources.ResourceLocation;$ j* g* S* X4 A; ?
; F$ K3 Q+ B" d$ ~' R- import java.util.*;
' t7 y9 K$ E8 b, w4 t) F, |
" b1 M- O: X0 {4 Y% ?; M) P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) l) n, W) l- l- u, t( k* H, I1 j
; a% K4 [2 z* A- public class LineRender{1 D) [1 S/ u! I ~$ j
- private final PoseStack pose;# y: `1 l) v' x) n, n
- private final MultiBufferSource source;
" z8 t. t8 a0 a* S& U0 U - private static final Map<String, RenderType> CACHE_A = new HashMap<>(); Y+ r! F* a) \+ Y# g5 l% R. `
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ V. |0 q+ i+ K+ A
" f6 { I# E; f. X$ F" v, V- 8 `* g3 z9 f3 ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& u" B! N7 V4 v0 O( _2 ^
- if(x1 == x2 && y1 == y2 && z1 == z2){/ Q6 U) j8 V& C+ O T
- return;' N; f* i4 j( i5 @" P c
- }4 ]+ H+ p* n6 p+ K2 S* T/ O# ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 s( R& D3 V3 R9 `( g' f( V4 j6 \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! i+ F( r2 V5 z7 ^3 G* o
- }0 G+ N! e1 k& S2 ]( G# z
- pose.pushPose();( ]& i2 w4 k4 V7 M+ c
- final int newLight = convertLight(6);
7 X' w1 W8 l" f - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) G [2 C) q* U - final float lineHeightSmall = (y2 - y1);
1 {. o* @' \2 W, R# {2 H& ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 O4 p. f( Z6 Q% @/ e/ j - pose.popPose();
I w) c% H H Z3 F* i% \ - }% u2 l- ^1 g7 R1 e% `/ I! O
! X; Q, }* M3 \5 }# I& h- private RenderType getLayers(String texture, int light) {3 e5 B; Z/ |% R' |$ w
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" R4 l6 |% m3 P: s0 ]* P5 N - }
6 I# v7 m( u: x$ U1 b I2 @ - ' n% C2 \3 W" Q6 W! E, c ]9 ?0 k
- private RenderType getLightTexture(ResourceLocation texture) {9 |; Y4 `5 z; r3 U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* z7 D! ^: i% o/ V. N7 s% g - }
2 o3 q2 t) N* {( u* ~, ^+ D
7 |3 i& k& J/ Y& D: \/ Y8 G0 V- private RenderType getTexture(ResourceLocation texture) {3 u S- y! p( u5 W+ U) R8 X! H* T
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ B: c/ @% P! s3 D - } E, I) E' A( s4 F
- / D7 k- F8 X3 H. K9 {
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 q' A H! A9 P% @+ n5 j$ b
- if (cache.containsKey(identifier)) {6 X& l9 J. H: n3 x3 G1 D
- return cache.get(identifier);! K' u0 Q6 _" _+ M, f
- } else {. o9 V5 W5 D4 Q
- final RenderType renderLayer = supplier.get();
$ O& Z, V6 t+ W" e9 \6 {, q - cache.put(identifier, renderLayer);
% @1 w7 U. w L1 D) [/ Y - return renderLayer; ~) _, Q8 `5 e& @8 k
- }1 S+ O3 x* F/ O
- }* h8 T+ E# P; t6 n
- }
复制代码 |
|