|
|
" l: h0 T1 x- Q' w+ a
行,这个怎么样* m6 _- l3 H" d' V4 M! r& ~' U
- package com.xhg78999.mtrfac.render;
' _% e- G5 f/ y" b# S2 L- w - % N: q, G$ h' b% }* G8 H
- import com.mojang.blaze3d.vertex.PoseStack;
0 _4 Z6 R3 R3 t6 y1 v - import com.mojang.blaze3d.vertex.VertexConsumer;* E- s7 }) r) @# g8 G
- import net.minecraft.client.renderer.RenderType;
( ]1 A/ h/ j+ | - import net.minecraft.resources.ResourceLocation;
; N) s/ y0 B; A - 9 T! a4 J" U1 C$ u6 q* J
- import java.util.*;; E7 k" l ?9 E+ o
- 1 A2 m3 Z0 U9 p. K9 m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. y5 ], h6 B6 _4 K9 Y) x
* `# Q# B2 ^# T- public class LineRender{, C8 z' J# C5 v; a
- private final PoseStack pose;
6 q( A8 x9 }$ @1 s8 b6 V0 g - private final MultiBufferSource source;2 x1 `' B% c6 b j
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();' n: V) w6 R4 x, b1 l
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 ]. h: q& H# J4 J- m; O5 D
- 2 B! w) m2 i- F- t' ^: b7 t
- 7 N9 J5 [- N7 b. A" g8 C
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* D. h: C/ y% k. t7 |; [
- if(x1 == x2 && y1 == y2 && z1 == z2){8 f% `# V: N% S
- return;
" c: h1 Z6 ]1 }- P% t - }8 o# _" v6 G0 N
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* r! k1 J. |. ?$ O7 z Q2 y' u - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; }) Z6 Q6 @1 M, t- ^# m5 b
- }8 r9 z8 e: h' T8 F0 k) t
- pose.pushPose();' F2 i3 g& _' S; [- s
- final int newLight = convertLight(6);
7 l# n! |) v2 ]& D0 S, K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) w! e' s! t% S% T7 C - final float lineHeightSmall = (y2 - y1);
# F+ ^9 l3 S8 M" _# M( g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 r1 e6 d( F+ G$ Z( M1 ~2 O; K z! V
- pose.popPose();
2 N s& {, ]- A/ |# x1 _5 q4 V, @2 c - }3 P: A& ]- I2 {, h6 B
- , X, A+ ^- ~9 Z& O! H+ h
- private RenderType getLayers(String texture, int light) {. @( g6 y! c$ H0 Q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- ?& e4 K% f+ x/ ?6 V - }$ E* N$ L2 K; p
) P: `3 W/ ]% D+ b) X4 x: I& m0 k- private RenderType getLightTexture(ResourceLocation texture) {; s+ ]7 _! y8 m( i
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 h1 `9 f6 F1 k
- }
7 ?) o& k; d; H% V - * W* Y$ s/ P' t: V
- private RenderType getTexture(ResourceLocation texture) {
$ D, S" ^9 m( F- s1 l& d3 L- R - return this.cache(texture, () -> entityCutout(texture), CACHE_B);. L9 c' _( B, N+ Y
- }/ G. h. M1 J6 O! P
- & { Z/ t! m# e
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; q: x4 v% c$ n8 s! s$ x - if (cache.containsKey(identifier)) {
$ R& O q0 g: z - return cache.get(identifier);
8 D5 g, r1 C7 ^ q; }! v" F! f - } else {
1 w$ A) p8 Z, z3 T* y) k6 u - final RenderType renderLayer = supplier.get();% T: s* m3 `7 Z8 p# o; p+ t
- cache.put(identifier, renderLayer);
0 V/ d1 o8 B6 q; b" ^# V - return renderLayer;
6 {; Q7 k( c- @" s' K- z- P3 e* t- Z - }
3 Y4 g7 u- l; } - }" H* Y- X$ I. {: ]+ n& ]* ~
- }
复制代码 |
|