|
|
2 D8 H* O* m( A: U, S7 M ~行,这个怎么样4 ] k8 P9 K& u4 L2 e, H
- package com.xhg78999.mtrfac.render;' P0 _8 V( `0 T' w
; P) h5 d0 l4 Y- R. O" u6 k- import com.mojang.blaze3d.vertex.PoseStack;& P8 @1 D7 t+ ?( l% r
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 T' b& a& [2 S - import net.minecraft.client.renderer.RenderType;
1 B7 B$ C9 O! G2 C - import net.minecraft.resources.ResourceLocation;
2 F$ ?( b1 z0 a& t& r - 6 J6 i" q! F. `7 j
- import java.util.*;( O' j) {% B# K/ @% U
- $ [1 V& ?3 B7 `; i
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; A9 l! D& ~7 ^ w: G2 m6 o4 s
8 M/ E* H u' ^7 s% S% ]: N- public class LineRender{
! i# a6 A V( w - private final PoseStack pose;' G4 q/ z* H$ t; P% s H, s) |, _1 q) _& N
- private final MultiBufferSource source;4 a3 ]9 ~4 u' z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 o: c! |3 \& H2 y5 o
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# }0 `( v* g0 W( Y; v
3 K- d: s2 i! o& s( G3 c W3 x: I/ m- % B0 y+ ?1 n) ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 S( n, I; ^8 F
- if(x1 == x2 && y1 == y2 && z1 == z2){; X; {) o5 z4 b
- return;
& t# J+ E+ d% L% h - }/ }; ^# p- L( M& L
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: W: [4 L5 h7 z1 I& O( z7 Y L# W
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% W- s$ v+ w& [
- }
% }. f* S/ R3 c" | - pose.pushPose();7 V' Q7 X, ^1 X" k* [( s0 O8 l* W
- final int newLight = convertLight(6);
L7 N3 N6 Y) \7 Q. l0 l% y, T - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 @" @1 G& V8 y8 T - final float lineHeightSmall = (y2 - y1);$ g) ~9 c# r& K \1 W* N
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 O9 L, c3 L! x# Y/ }9 O! ^ - pose.popPose();
# B( w: ^2 K' k' |$ q; M - }
6 J# T0 S- ~* O% `& T) j( a - / y ^* F+ \* a8 P% l4 y8 U+ o
- private RenderType getLayers(String texture, int light) {$ q2 w# P" e S. t
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
T. S# B3 d% ?- k. ? - }) X2 C, _/ n" x3 k. A
- 8 V1 a9 B6 G/ n/ \/ p2 g) ?
- private RenderType getLightTexture(ResourceLocation texture) {
. q9 t) H# v. ?) c4 U3 N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% Z" X( Q1 G; U, ~ - }, c5 o, Y* U5 D- J
- 4 y% T$ r; Y4 X% n) m
- private RenderType getTexture(ResourceLocation texture) {4 D6 u% B1 W- z5 B6 ]$ E) g/ x+ P
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, B; u. b# w$ Y3 ?* J. x& W1 v) D$ s, m - }
0 m# u& y H2 H& q$ b - 0 x7 p9 N" s- n8 ^; v
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 F3 \/ _* F( @' n$ t3 A: v
- if (cache.containsKey(identifier)) {+ E: ?1 g% ?) n0 u
- return cache.get(identifier);! h3 T# X( C- y$ Y! x
- } else {
+ ~6 Q* S9 i& w - final RenderType renderLayer = supplier.get();
9 B+ F0 f( e) m - cache.put(identifier, renderLayer);4 R" L& j7 V+ J5 p1 a: e
- return renderLayer;. a0 o2 f% i5 r1 o( U, f/ ^# c" ^& X
- }* Q! C. n" j+ m4 P- B
- }
9 u3 q4 F* r& U* k( T/ z - }
复制代码 |
|