|
|
: `' K- j5 I: { ~) t+ x3 n* y- w) d
行,这个怎么样$ T& W! g0 V. U/ O1 t4 k" `
- package com.xhg78999.mtrfac.render; m$ S3 I C, J F! l: W
- $ p, t& ~- s* l6 _% a+ m8 R
- import com.mojang.blaze3d.vertex.PoseStack;
% V9 V) x8 z% o* t8 } - import com.mojang.blaze3d.vertex.VertexConsumer;
3 O& T: N) |4 q: p& ~: W - import net.minecraft.client.renderer.RenderType;
5 w8 h5 H4 R2 q1 O5 y - import net.minecraft.resources.ResourceLocation;4 J& {5 v9 w$ ]- C5 e3 z- e
( ` w; m2 _0 R6 S+ g6 k- import java.util.*;1 R: b# d5 j+ Z! l, j
G9 v6 _9 U! r; i7 e) U$ m- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ x/ K/ l) y" v8 T
- + \' S- g! c0 h& m/ }
- public class LineRender{( N0 f4 [# b! `
- private final PoseStack pose;
7 l- m! ~. S+ X+ G, U$ X; Z - private final MultiBufferSource source;. `* k0 c% |3 S& V' O! e7 c3 u+ E+ V# M
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 E1 B! P2 a* N0 E6 J0 U: b
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ l: W( e" w i+ R
J) @, a6 \. M- ' ]$ i( J8 W4 q! S. L
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 D& p+ i8 ~7 K( ?- m: o - if(x1 == x2 && y1 == y2 && z1 == z2){1 n6 O8 B9 ^# x( s* A# G6 S" x/ }
- return;, N' g' w6 T! j' t; u6 m2 ?/ R4 e
- }0 T0 a$ t8 B9 ~2 A: a
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ Y \) B. d5 e2 A
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
+ G& M* T6 s+ J. ]" u - }
) `* _* h: J, q; `( v2 R - pose.pushPose();# ~; y! S; |1 S
- final int newLight = convertLight(6);3 K' h9 T& }3 b/ |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: j. a, E. L( C- X
- final float lineHeightSmall = (y2 - y1);; ^6 X9 V' l3 w! E! H* I
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) B+ U) @( @! I5 o - pose.popPose();
) q# G! h4 ~2 ~9 ]& y3 k, a - }
5 p, Z! U+ Y0 ]6 G! M8 N' \
& X' q9 z* t3 n$ X, E2 V7 v- private RenderType getLayers(String texture, int light) {
J0 r H3 X! @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; K1 p- e M- l( T3 c0 o
- }
2 |+ R Z5 [5 R1 [- e: e( W9 ^ - + r/ \2 u9 E$ W5 u7 b6 Y0 y
- private RenderType getLightTexture(ResourceLocation texture) {/ w* J! k5 I" r/ _- x6 \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 h! I" s5 }/ F6 j - }
2 O+ L/ o* `% m t2 M: H: h
* T' I- o7 a# M3 w0 W/ B- private RenderType getTexture(ResourceLocation texture) {
" \3 w- H9 Q0 I6 S! c! m - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* r9 ?, Y0 Z+ u5 o" u' k - }
% c' f; G, r2 ~ - - K6 v4 T _% B% C# @& `: [8 Q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' u4 |& P% X" o1 M" s8 | - if (cache.containsKey(identifier)) {" L/ S( u: B/ o" V' {# T
- return cache.get(identifier);
$ u# y5 W' V( x' H0 Y8 V9 R# \1 |* v - } else { N% i, w! j8 ?6 z/ f
- final RenderType renderLayer = supplier.get();( W+ V Q" ~8 ~5 x; W6 e3 B
- cache.put(identifier, renderLayer);% N- x- D4 s( H4 u; f6 f
- return renderLayer;, m" f8 Z! o' M6 _& Z0 i& i
- }. I( g e' [5 f0 Z: H
- }: P. I5 H8 L" R2 b% G
- }
复制代码 |
|