|
|
6 ]6 d& S8 L6 z/ ^0 E) @
行,这个怎么样
9 j4 ] q" s$ Y5 u! C& q- package com.xhg78999.mtrfac.render;1 J% e C& h5 O+ s
9 R3 P* i) y& b1 A' E/ R; J- import com.mojang.blaze3d.vertex.PoseStack;7 |/ [4 D; z0 Y A b5 u
- import com.mojang.blaze3d.vertex.VertexConsumer;5 d& K) L8 ^+ Q8 u# u
- import net.minecraft.client.renderer.RenderType;
3 o, v, Z9 R& t - import net.minecraft.resources.ResourceLocation;% v" ~- r( c3 S5 E7 m2 b+ f
- T/ E9 s* y: I5 B& U9 @
- import java.util.*;6 m" b \" M$ ?
% E( P) B/ {( i% S3 S. Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! j7 P$ ~% I( O! R' t
5 l* q8 c" a* o9 {) n; j7 I- public class LineRender{
& b3 V9 h6 N1 ~* i l- y; m# ~ - private final PoseStack pose;
: j9 b6 q e; \: a" O7 } - private final MultiBufferSource source;! v( a7 Z& h4 `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 P/ S) c& ]# Q+ J) w - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: Y4 R \! W* T0 e
0 A+ i N. M% G( t% a- W
P5 ]" w" j7 v( w. `' C- _- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' a0 J. F& |- i; f8 J4 H5 P
- if(x1 == x2 && y1 == y2 && z1 == z2){/ p. {: d( W) m0 i
- return;& S5 E3 X; t5 w4 i- y4 k' }
- }
% c/ @' a% ~8 ~0 \( y( X: Z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 Q) H+ W4 B( } - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& E" Q5 p, P' I* ?+ ]6 Y3 E4 K
- }: Y! | Z) Y) u% C, ~! X6 r
- pose.pushPose();9 H6 M& q1 m4 a
- final int newLight = convertLight(6);
6 B! X3 @- }: |, @/ w - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 K) Y1 a( t5 v: R - final float lineHeightSmall = (y2 - y1);
7 U5 V+ E7 S6 X+ e9 F, W - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
g% c0 y6 [' R! F6 N" `! D - pose.popPose();( \( h* I* m& q! O9 E, c
- }
2 O5 h# H! U1 c5 I# o
% b2 ^, s+ X n- private RenderType getLayers(String texture, int light) { T% R, f Q* A
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 M8 @. ?0 l, }- p" Q - }
& P: X' V. ?/ o - 3 A# P# ?7 N1 T$ n q, J8 p( U/ R
- private RenderType getLightTexture(ResourceLocation texture) {+ v Y+ e2 ~- ^; c1 Z& [- Z6 R9 e- a& T
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, C; J7 q- }8 Q" A& K
- }! t: X- {. |+ \" w
- ' ]1 g' |* ?& N& W0 O' D& O
- private RenderType getTexture(ResourceLocation texture) {: ]- `8 g; P h5 }
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 k$ _8 Y3 S. S' X I
- }
. l: g2 |& L2 t$ U - ( c2 i, e" ?* s8 @
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ S9 J6 N! f1 Q8 [ - if (cache.containsKey(identifier)) {1 A( F; t0 u9 q& Z4 k5 |0 s" H! w |
- return cache.get(identifier);
F- o1 y5 w) S4 }9 p- ^9 b - } else {
0 N6 V0 h( j+ p; r. c; x* A - final RenderType renderLayer = supplier.get();
. @4 Q9 X' a0 G! U( c% L - cache.put(identifier, renderLayer);
& o3 C" I& p$ y- q7 ` - return renderLayer;
; X2 w* ~/ n* `: T - }
9 o }# H- x, X# W- n - }% N% S+ \/ j; k. ?% t
- }
复制代码 |
|