|
|
6 T6 k" m6 e/ L3 j行,这个怎么样) d: P$ ?, X. J$ j
- package com.xhg78999.mtrfac.render;- r! h. Q$ P8 V/ T& k$ h
3 K& J8 F0 b0 o6 b- import com.mojang.blaze3d.vertex.PoseStack;
8 p3 q% j1 b; @& m& e$ v! S - import com.mojang.blaze3d.vertex.VertexConsumer;' x# S+ w* K- g2 E8 m4 o
- import net.minecraft.client.renderer.RenderType;2 d; }* j4 P# H9 A6 Z
- import net.minecraft.resources.ResourceLocation;
6 L$ ]7 |9 z6 D! M2 Q W1 T
9 v6 S- R& W/ P6 ?2 L7 G" ~- import java.util.*;
0 ~8 x0 S" o, l# {5 m9 k" c' D* B - r* ]! K- D- A
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ q3 M, F* g1 X
/ _; V {) }0 F3 k# D: Z: c+ F- public class LineRender{5 \5 u* A* H% @) }& c
- private final PoseStack pose;0 [8 }- F5 j4 f8 g4 o8 Z
- private final MultiBufferSource source;4 T4 h! s2 L$ Q& ^
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 T' V2 X/ s/ p* `/ {+ g1 N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
h3 ?# l; S& k) W+ P- B - 1 k( |4 _4 ?2 y% x0 I5 S6 D
- " O# h& O7 w1 C
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# O" _2 f4 Z2 C4 T: f3 E) S- S* h7 X* j
- if(x1 == x2 && y1 == y2 && z1 == z2){0 J+ N9 r& h5 X3 `8 ~
- return;' o5 f) P3 v6 G; ^ C) K
- }! g- I: `0 Z8 V
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
+ H7 `5 n( Y3 M5 E( G3 c% i# w4 E% C - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 B# S6 r$ Z7 @" Q* _7 M
- }5 V6 P7 x4 r! T7 R) |. u
- pose.pushPose();6 T/ @6 a$ C% T/ r& i* S
- final int newLight = convertLight(6);
0 O) n. G( e5 A2 r1 n; ?' f0 V) o+ g - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 Y0 k4 j# h) ^# b - final float lineHeightSmall = (y2 - y1);
4 S' U6 e7 k3 ]: e) j& j2 m B - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 Y* |2 s9 H4 S- j8 E3 _ - pose.popPose();
% ^* B8 N Z; B& i) I, ` - }
" o; b7 s q# j1 k
2 V& U/ M8 X8 \" y6 v9 n- private RenderType getLayers(String texture, int light) {9 s$ k8 o5 Q# \# W1 ^5 y7 E% V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" P: ?* `6 K, ?: C/ D5 k. K- \
- }
* k' [; x% h0 A - ; M; H7 s4 m! Q! [8 I$ Q
- private RenderType getLightTexture(ResourceLocation texture) {
3 L) u& G* V9 T5 A% t( _ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) G' t0 ~0 Q$ a( J& v
- }
: C# U- R- F+ B, H0 Y
# N4 m! D7 T* U- private RenderType getTexture(ResourceLocation texture) {( J2 G! Z; `: }1 u3 {& e
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);/ V+ A9 g& L/ S2 M3 ] k1 _! Q
- }) N! n( L9 p6 x* Q0 e
- ; n7 C' H8 \" Q) [- Z6 a2 t
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
C5 E0 g" U# u, n8 q H - if (cache.containsKey(identifier)) {1 E% e N2 H: k% {/ q3 C; A' Q
- return cache.get(identifier);1 R# ` L9 e$ N" I6 u( \$ e2 M
- } else {$ b% [% M" H* ~
- final RenderType renderLayer = supplier.get();1 M' D5 W# f& L6 A5 _' [& x% v
- cache.put(identifier, renderLayer); V5 h# F- a2 \# {! F7 h0 n
- return renderLayer;$ y0 ]" K2 _2 P( k2 m
- }
0 @2 t5 h0 d3 l: h% f: { - }7 M/ i) ^# z3 |: x) Q
- }
复制代码 |
|