|
|
9 v, e% a" R* k. E. L( _) g3 L7 L行,这个怎么样0 C" G" |' ?: l% k
- package com.xhg78999.mtrfac.render;' l+ j. B* Z+ a# n! H L
# U, G3 p9 x# n8 N& Y3 i/ W- import com.mojang.blaze3d.vertex.PoseStack;+ O2 {% r- m( s3 y& ?
- import com.mojang.blaze3d.vertex.VertexConsumer;7 s. \) R% V. A. D+ U
- import net.minecraft.client.renderer.RenderType;
! n& O) l% O9 k% A& H& h - import net.minecraft.resources.ResourceLocation;
f/ r5 |0 g" i* |; M, J
7 j( y2 B& Y) z1 Z) G9 [* b- import java.util.*;8 }3 p( J8 v& X. C: c/ Y& g O
- 2 b* _1 }3 Z/ v9 P h* N' Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( Q! M3 V3 T& e
- : E- G4 l7 |5 x+ G
- public class LineRender{2 z6 t. I+ T" r2 [8 y
- private final PoseStack pose;4 [, o2 p. B5 l. q2 z7 n
- private final MultiBufferSource source;8 P' ]* m2 n! K9 b
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();' C3 o/ K0 S, y2 v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 S7 s D6 l/ \5 p& Z& L) d% R
- + l- m; l) S9 p) W
- 7 z3 U( _; {9 V; `: ~ M4 e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ T* b& y6 ?. V) n8 T2 M
- if(x1 == x2 && y1 == y2 && z1 == z2){
, |" y; v! \7 `8 h1 o - return;
' Z7 m# [* ~! w- i' _$ y: I2 x - }1 K2 e+ [5 }: j& M: |8 b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 j" C2 q3 x1 B! o: H+ D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 g% K8 J5 v* U, T! T2 j5 A - }. W* J# J. _' w- \) Q
- pose.pushPose();6 s% k/ Y, {; E. x3 o
- final int newLight = convertLight(6);
& C$ g, L( V- K$ n9 w, F% m; [6 K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 D; {( R4 ^% s. S* d; r! v7 n1 D$ V
- final float lineHeightSmall = (y2 - y1);- F' @% `7 ^2 a' H1 E5 {4 H! u4 [
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# c1 L' d, r* ^+ ^
- pose.popPose();4 T6 ?4 E E' w# W2 J0 I0 |) X
- }
; S0 a' f' ~" y# A - % w& `* D! z# z) u, q
- private RenderType getLayers(String texture, int light) {2 t: \5 A: q7 \% z# ^, d2 E
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 ~7 g8 s; f) Q* J - }
& c+ l( v- R8 |$ r
& n% }3 o" [1 Q3 A) b7 H4 B/ ]- private RenderType getLightTexture(ResourceLocation texture) {
- ~; T; f" n" [( Q& ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) i+ n4 H% `2 @3 Q; Q3 y
- }
8 V1 z8 j! D" E& l' |4 R0 t, C - / R& j% I) k- v# W5 W( x
- private RenderType getTexture(ResourceLocation texture) { Z" I9 T+ ~8 V( e: U0 C' ?" g9 M: A% ]
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 y2 ~" ?5 T9 v% n* u+ E - }
+ t. V" J; i# n" ~$ ?4 l - % D# A5 H/ }8 C" K
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. z6 h/ h- i9 \9 ^) _ - if (cache.containsKey(identifier)) {
2 [0 L; H( z5 M q( C. J( F2 N: j; N - return cache.get(identifier);
3 P c0 S5 j, V2 W4 ], p - } else {7 E# t- z/ x$ V- o
- final RenderType renderLayer = supplier.get();1 {" h; G- _0 |0 g; _
- cache.put(identifier, renderLayer);; M+ e0 n4 j% p; a
- return renderLayer;/ ~" z B6 Q: g3 v2 o; J
- }6 D/ O9 D* R# {( O! x3 }' q
- }
8 f# |' b$ G t2 W- f, E6 p - }
复制代码 |
|