|
|
2 D* \ y) _8 ^. S0 O
行,这个怎么样" j: M- d4 O! N( ^) R& V' S3 h& U o9 |" x
- package com.xhg78999.mtrfac.render;0 j, J* l. n& w [! h0 g; F3 G) O
- , e- f% ?' h. X0 y- S: h, D1 Z. u
- import com.mojang.blaze3d.vertex.PoseStack;. ~5 Z3 W% `: B9 T0 Q; y
- import com.mojang.blaze3d.vertex.VertexConsumer;9 Z+ b) X- y0 H$ Y" n- O5 K
- import net.minecraft.client.renderer.RenderType;
`# g2 m, T+ K2 c - import net.minecraft.resources.ResourceLocation;
2 d6 r. n, p! J$ q6 K" y9 q
2 Z8 K4 |% f5 r6 d- import java.util.*;; ]2 _) c. t8 [8 a
- " ]# [" |/ t- A6 _3 a
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 I; f3 Q! x0 R8 I8 L3 T5 n
- . _& ?* ?: C p0 M, i7 b* I
- public class LineRender{
9 } V6 X7 l) O - private final PoseStack pose;, g5 g" ?; v) a0 M
- private final MultiBufferSource source;- Q, A7 ^1 S1 b; C
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ K* r. P( u- z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 A1 z3 D; M$ s+ Z
$ L! O# w% m6 t$ O& D% ?: W
/ V8 u7 A6 R8 |* _- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 p% [5 o; i4 b/ i
- if(x1 == x2 && y1 == y2 && z1 == z2){. D7 V% }6 |4 `+ B; u1 h- D
- return;
4 P4 A3 ~. {( }( s- e+ F) J' E - }
5 z3 b/ }4 v' F1 H; k* F& E) \8 N - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 I( s! r$ U1 Z& s$ V8 o
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 U% H" N9 j. u% j - }
4 r S: d8 W0 @ - pose.pushPose();
" A- W8 d+ K2 v8 } - final int newLight = convertLight(6);
2 F3 Y/ H3 p( g# z - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 L4 b! ]0 d( Z3 H% b5 }+ ?: S - final float lineHeightSmall = (y2 - y1);8 P$ I3 s& C7 b9 i3 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 t: v- A; O8 E K3 F O9 B
- pose.popPose();
& C( ]% E- n' K+ J' b3 N! L. h& K& r - }
! S( n7 n% }4 L S
7 t: ^, B2 y6 U- private RenderType getLayers(String texture, int light) {! z0 d# o5 y4 G* _0 V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 l& v; V- `1 B- K - }
: Y* x1 w$ }: E% t6 } - + F- F0 Y ?( G: }5 I: `8 F7 m7 s
- private RenderType getLightTexture(ResourceLocation texture) {6 q. I% [1 K! r4 D# \% P7 e/ _$ z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 f" o. V- I* \+ L! u
- }
, N! x, F; N* s2 l8 u; U - ( g" p) P! q8 e0 u
- private RenderType getTexture(ResourceLocation texture) {, o8 t% N& q: S) `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B); B8 G7 m" c0 v
- }
+ J0 z) }: _: s$ x7 I - . \6 l8 ^$ D/ q2 D6 e3 _6 ~
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: s) P4 h6 n, g- U9 w( H, X/ @ - if (cache.containsKey(identifier)) {
@3 G$ s; I3 F& V - return cache.get(identifier);# g) Y1 K: u5 _" |! w
- } else {$ T; r6 \+ y9 ~
- final RenderType renderLayer = supplier.get();' V8 N; u0 r* a) g& A+ o; {
- cache.put(identifier, renderLayer);
8 |5 r |( ~9 i! E4 Z5 y/ x* y6 M - return renderLayer;8 t" Z3 ]( @! \9 K) x. C+ _
- }
0 v# G6 k: T0 P, G6 ` - }/ ^1 \3 x+ K& E1 A( n+ B% @
- }
复制代码 |
|