|
|
- U* Z+ l0 }, Z( ~4 O: R
行,这个怎么样% e0 x) V$ x2 M& q Z8 f7 E
- package com.xhg78999.mtrfac.render;
! Z( x. a: U) [1 Y9 B8 q
0 i f# Q6 Q- E. ^: e- import com.mojang.blaze3d.vertex.PoseStack;' d: L) S( {& Y/ j% z
- import com.mojang.blaze3d.vertex.VertexConsumer;
U" \0 Z; K9 B; ~! i - import net.minecraft.client.renderer.RenderType;
6 @0 y; Z4 ~+ u" o6 u - import net.minecraft.resources.ResourceLocation;3 H3 o! Q- B" m! E; i! }
- ' |2 a( n% Z% R! I, C" f) v% I, D$ I# d
- import java.util.*;" C' ^5 u9 _6 K* M. I _5 A" S
- 3 v. c7 u2 w% u* _/ B
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ }' T8 Z& n$ ]% ~5 `( z
- - Y' Y4 A$ j2 }9 R$ w! r4 J
- public class LineRender{: ^8 I& Z7 @( r
- private final PoseStack pose;
. {/ n2 J1 V1 W6 x( q9 ?0 j; W - private final MultiBufferSource source;
0 I$ K( w. j) a# b - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 e( X5 _7 b# j+ V3 }9 u6 Y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) J1 i2 x5 n0 P+ J% w9 u
- 2 M1 ?3 e% ~9 b8 Z
! R9 `, W+ s7 m0 Z9 |# z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
% {* e) U' Y, {5 n2 C* J% h - if(x1 == x2 && y1 == y2 && z1 == z2){4 F- f. |2 l0 |
- return;7 g- Y% u* {* _3 n
- }$ i" }/ Z2 C* V; j5 ` E: M3 I. H
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: S1 T3 `& f7 ~' U" G4 s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");+ J: Z2 P; ]2 y9 D. b
- }
' Q6 G. A* Y( C [ C P - pose.pushPose();4 L2 O! K* i' D3 n! x
- final int newLight = convertLight(6);7 |: N+ a9 _9 z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ m* [/ I6 \4 a0 A1 l
- final float lineHeightSmall = (y2 - y1);# E, R: e0 i! G$ t5 o1 z5 ?$ o
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. F% @# N3 f0 _# R- Q; b# h - pose.popPose();3 o e& O8 h3 i, O
- }
* n% o2 @6 T0 y* D# q
8 U! m+ b/ i. F3 n6 Q/ Q$ B4 O- private RenderType getLayers(String texture, int light) {
' d) Q. i) S2 w( k+ T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));1 _0 `/ i7 d+ y* f5 n3 G! T" w' O- ]
- }& S) T( {, @+ ~+ t& p, V# t3 ~
- 5 X* ], e/ p, W* |0 r
- private RenderType getLightTexture(ResourceLocation texture) {4 z# k8 P1 V3 a7 ?2 R
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. K! A1 |4 F, o# M/ W
- }
- z: S8 a/ q& o& ?' R - 6 F7 u+ y( [ j* e4 B4 W
- private RenderType getTexture(ResourceLocation texture) {$ O2 `- z: s4 g( X& E" j$ Z* P
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% ], |5 R/ F# }4 J - }4 ^) u1 F7 `9 s" c: \
- % M4 {* ?) E( ]3 ]# F, h7 a
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 M9 T$ B' O O- H# Q7 Q - if (cache.containsKey(identifier)) {- S! u5 w& }% G9 W) T! C
- return cache.get(identifier);; J9 {. u: t" A. J$ i$ O- I
- } else {
6 R' a1 q! g; g5 g% U; D; _ - final RenderType renderLayer = supplier.get();
# H5 H) i. t0 U- q) C. s( V* O$ n1 G - cache.put(identifier, renderLayer);" k \3 r* e h: k
- return renderLayer;2 @# w6 X- x( i9 k! {8 E( |2 u
- }; A4 F& {" E8 e0 W5 Q; `# ^$ Q, K
- }
5 I# W1 o: N/ \( W6 x - }
复制代码 |
|