|
|
& \6 n3 t2 o0 H, u C+ O+ U z
行,这个怎么样( }# E% w% ]# p) X3 _& r1 n3 F, K) V
- package com.xhg78999.mtrfac.render;4 v, f2 |; C# o; `; ^
/ A# h- j3 ~; R2 y D2 A8 ~- import com.mojang.blaze3d.vertex.PoseStack;2 F! w2 e% T8 ~3 e9 ]3 l
- import com.mojang.blaze3d.vertex.VertexConsumer;
* r+ u8 U' P! D& G6 d8 n - import net.minecraft.client.renderer.RenderType;
$ ?+ E0 D: G& A' p9 J. P - import net.minecraft.resources.ResourceLocation;. M/ x, c* D9 K% x& U/ q" {! i( |
- / |1 b9 u2 H; Q* K; T
- import java.util.*;
4 c" R( B* }( d; s7 R3 C' f
. E4 X, l% B$ p) M- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: E( M9 \; r8 q0 W5 j+ X
" A' e) Z& ~3 u) I: G- public class LineRender{
6 \3 R6 K4 P2 B! g, r( v$ O& l - private final PoseStack pose;
4 w: D8 y+ b# g( d - private final MultiBufferSource source;
0 D" o' |3 [; m- r9 ]. Q$ \3 t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& l+ w! x) m0 t/ w& |/ ^. H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* ?0 d7 \/ u/ [# u - & w7 Y0 r$ U; f
- 6 E# Y- I0 V5 m; n; x1 @6 v/ E2 n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! X8 g* g/ X. ?. c- l, N
- if(x1 == x2 && y1 == y2 && z1 == z2){1 v/ e& y1 u0 S m7 h1 f& [
- return;, @! R. `- x; j X( \" Z
- }+ ?- u9 U) q4 q* a! C- R1 e! `
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){3 \$ V9 F+ j4 _' V q; w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) Y' x4 a: c T. S - }
8 I; \% a# L! E' V/ q4 D4 z - pose.pushPose();
- e1 K% N( U8 V8 n - final int newLight = convertLight(6);
. R& P" z' \- Q u# _( h3 }. Z - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( u2 A) b8 }8 J8 e+ E - final float lineHeightSmall = (y2 - y1);
8 G/ U* V. I+ a5 c - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; @2 m. z+ e) {) H
- pose.popPose();
$ C& s- x% Z% X7 H) Y, C5 F - } U5 [+ t* P3 p7 B+ w# \' I
- & A. t; `8 W9 e# a4 E
- private RenderType getLayers(String texture, int light) {. g0 ~; s( g& s
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 D: I2 i' Q' d: j! B% P- C! O2 J: z- t - }5 c6 j( H2 B4 q" X+ f8 c: c& T
a2 \! G$ s/ B* T5 f- \) E2 ^- private RenderType getLightTexture(ResourceLocation texture) {
8 R" w8 k. z) Z3 o - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 J: S, O7 [+ g - }
7 G, K. r% q! n$ b; Z+ |5 ~; h/ ?
1 e8 S' C* a8 ?" q1 n7 c( j) p* \- private RenderType getTexture(ResourceLocation texture) {6 _8 w4 D& p6 Q( d6 {" G( N1 j) _
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ F( J6 H- c3 w! }
- }
( J) E& b2 B6 H+ b* D5 V: y" C
$ c2 u8 c, x& n! |- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
I Q7 k8 t( c7 ^7 A - if (cache.containsKey(identifier)) {
" ]. ?, m6 X& {) y2 O$ e2 x - return cache.get(identifier);
& ^7 H$ p2 ?% m/ x - } else {
F; |) [! e! ~* e6 s1 E - final RenderType renderLayer = supplier.get();
6 [! s/ B6 S$ M( G0 K3 j - cache.put(identifier, renderLayer);5 d4 H) w7 a7 ]& k: y
- return renderLayer;
4 Q! c( J7 [% a. K! h) C9 ^ - }# h- _6 H* K& T
- }
R6 {: N2 [. R" N X9 B% J - }
复制代码 |
|