|
|
( w6 l4 d5 t5 Z5 }$ k* b& z, [行,这个怎么样
1 e. \9 H# @( J8 x3 F Z- package com.xhg78999.mtrfac.render;
* E0 _$ ]8 J, G1 ~ - 1 Q U# ?( h1 p% p/ a7 w7 i
- import com.mojang.blaze3d.vertex.PoseStack;
/ r7 f0 y( y; l3 H - import com.mojang.blaze3d.vertex.VertexConsumer;# W. _. b4 }, H1 j" U/ |
- import net.minecraft.client.renderer.RenderType;
( P$ m7 ^# Z. h( |& v - import net.minecraft.resources.ResourceLocation;. Y u* L, F; n3 F0 w- J5 [
- i. M4 U/ Y$ F( n- }4 t- import java.util.*;' `+ G8 S b8 e: `# d* L
! V, ?( O8 L7 @$ ?. `4 i- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: v3 L e, h+ X, ~
# U: p m: Y8 A, C: j! f5 W, m- public class LineRender{9 W- _: I' i- Q0 B
- private final PoseStack pose;
{. ?0 k2 N- R+ p- B - private final MultiBufferSource source;1 k: {2 p9 u% W
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; o# j0 ]: a: ]9 S! @& s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! D/ l+ U$ w, ^! ?. ?' S" U4 d
- _- v2 @& [# ]8 w
- + Z" x' h+ o" J- R0 C! P( l) O5 Y* o
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 O2 u0 F$ p7 y* k. ~
- if(x1 == x2 && y1 == y2 && z1 == z2){* v: j% ~( J. y5 R2 s
- return;3 _7 E0 A, ]( L0 ^; X7 ?2 F
- }9 O$ G# k& h. S; Z& f* h
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* }9 i5 J' T$ ~' Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 @& q7 V' e$ h8 G3 m% H
- }5 G# Z$ @& @" G3 G0 ?3 j% t
- pose.pushPose();9 [7 o7 N3 b% E) B0 Z; d( o
- final int newLight = convertLight(6);
, ]2 Y& U& C" V$ z- W - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% S4 F z* z H/ r% x. D
- final float lineHeightSmall = (y2 - y1);8 }3 V) s3 }4 h0 P% v& ]
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 U- I# R8 k+ h Y! N y
- pose.popPose();
! @. i; _1 \# T, m - }
1 ?$ n7 F7 b* r - ' v7 [* o7 g, M9 e, a+ c; g
- private RenderType getLayers(String texture, int light) {1 X% B+ p9 n9 }) }" ~" E+ `4 H. n
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));( f: w1 q" ^+ W& G* x
- }0 O5 P/ x& X4 r; w' e
! B2 `: Z* I, {2 _- private RenderType getLightTexture(ResourceLocation texture) {! w; y8 m# l' X# x6 h" q
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) Q/ J& q/ z+ B9 |
- }1 c7 ?! s5 j+ [; O2 a
( i. d x5 Q! U$ q( c9 q- private RenderType getTexture(ResourceLocation texture) {# y. D5 o. A8 y+ O7 f1 H
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ L \/ w- Y0 T. w - }6 n( w3 e! X/ V* H
- . U0 g# z. w: }/ i; e
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 {5 t: u; `. i2 W* i
- if (cache.containsKey(identifier)) {
# Y* w6 g0 U$ E- m - return cache.get(identifier);2 N A% {. V( L/ b
- } else {4 g/ l9 d' z* T* A- l4 P
- final RenderType renderLayer = supplier.get();7 W/ r2 g, c' a) M
- cache.put(identifier, renderLayer);
- p! `7 \4 O# @3 a2 |9 O, m - return renderLayer;
5 l" I+ D" s' s! T( J2 R! ~ - }& C3 B" a" _& R/ j1 u3 t. ?+ O7 K+ H! t
- }
- x+ W8 B" I6 `0 _2 C - }
复制代码 |
|