|
|
* o+ g4 f4 Z* F- P) Y
行,这个怎么样8 O* z, S1 d8 Z7 o. n3 K% `1 ~0 _
- package com.xhg78999.mtrfac.render;
8 Q$ C: W6 K1 n5 ?" k- k
/ D. \9 H7 B+ x1 F" I- import com.mojang.blaze3d.vertex.PoseStack;
+ B+ t: z! d5 Q - import com.mojang.blaze3d.vertex.VertexConsumer;! H2 d! w: M- u. T3 g
- import net.minecraft.client.renderer.RenderType;
. V1 }& h. z8 D5 u6 ?6 _/ w - import net.minecraft.resources.ResourceLocation;9 Y8 y/ Y; I1 L# k' K9 u/ w5 D
- 1 u1 W6 `* ^8 V& q+ z5 x: d: q
- import java.util.*;# G8 l% m1 b5 m: C; \6 v
- 2 p$ {& d6 I$ {
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& _- U q. ~% @" ] A2 l
6 b5 y/ j/ B+ U" a" {! V8 D- public class LineRender{4 u3 f4 _7 E, ~1 H( b1 ]
- private final PoseStack pose;
n$ v9 t) N2 j1 N7 o, `/ |: R - private final MultiBufferSource source;
& i" z& x" Q! C9 e$ w5 f - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 V# o3 x. }) S% u - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( B# h0 x b6 Y; c9 W
- ' y6 @: _0 Z" W) ~
( H% D! G) ~. g3 w B- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ O% o5 i. t& Y- x
- if(x1 == x2 && y1 == y2 && z1 == z2){
+ o6 c2 ^, i5 a: Y4 Z% g9 l. w - return;/ s" }/ c2 J1 H# W
- }
; q0 S! e8 E8 x$ C' g - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 G% X$ t3 I- d: E1 x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); f* `5 N/ n& r) Q" C- e7 J% `
- }. Z- R8 X' N8 P
- pose.pushPose();
, ~, |7 a$ {( ^& m - final int newLight = convertLight(6);
9 X. A% D4 u( k; \8 Q% u - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& s# J. s9 q9 n6 |8 t$ ~$ l
- final float lineHeightSmall = (y2 - y1);
9 ~9 V4 ~/ ^/ _3 d0 u - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; y6 h9 N% n, M! t( T6 \ - pose.popPose();
: i, {1 m; B/ `$ V# T2 r" L/ A3 r+ w/ | - } Y" [+ D! _, B" \* h4 E. c. Y
# r. |& u8 m/ t- private RenderType getLayers(String texture, int light) {
, W4 m" _0 x: E& [& |" n: ^ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& Q9 k; q: Y1 Y7 `, U8 a
- }1 }. o6 _) ~- X h
; U2 g" t4 m) I" y3 [/ r/ m: V2 f- private RenderType getLightTexture(ResourceLocation texture) {
) P* Z; J/ f- W' \- C. Z# G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 }% B6 e$ k; R1 ]- q% j3 W0 p, i - }
9 O% ^& o$ O$ i+ Q* p. l/ M - 7 J- f" w3 w: Y! ~/ P( M
- private RenderType getTexture(ResourceLocation texture) {9 @! K6 G* O# O4 l: Q7 n
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 n8 c+ w6 G7 t, K$ c - }: y" [- L( q: U
! ~( v0 f ]# n; |2 w% [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: a2 L+ P) L7 Q1 T
- if (cache.containsKey(identifier)) {3 }% o8 g F+ W* d- u. }0 |
- return cache.get(identifier);8 z6 ]+ [5 m/ [. b& K1 d* x) @
- } else {. E6 j% l, t" g' b8 a$ V) Q
- final RenderType renderLayer = supplier.get();
5 b% I6 P; M5 Z& | - cache.put(identifier, renderLayer);
, c. x8 M$ B8 p; N" ]" t - return renderLayer;
4 Y4 j8 ]) t+ {) t$ F1 w. \* c& M! } - }0 `/ [. v0 }2 Z7 ^) I* E" N' _- r* W
- }0 l2 Y2 K7 f3 f
- }
复制代码 |
|