|
|
: B9 d; P5 k$ d- b* y行,这个怎么样- V- V6 q( r$ e+ K1 n B
- package com.xhg78999.mtrfac.render;
# F7 h0 B6 t; U* g# v1 s
3 Z! E' n5 |8 x5 I0 O5 A# i- import com.mojang.blaze3d.vertex.PoseStack;7 } J2 ], ~$ F" m. ~' o* R2 ^7 G
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 d0 q* g4 D* O) L; u- X - import net.minecraft.client.renderer.RenderType;
: I: [5 m+ f+ I( B# g6 t5 D - import net.minecraft.resources.ResourceLocation;
0 h# o% _$ M6 E& M5 c- o: v* t2 w - # G; M" J9 R% a! K
- import java.util.*;" I0 _) G/ C* C5 u- R6 }
- 3 ~. \! p6 E; ?, I, D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 K% B E- W: M% y7 W
- y% ?+ v/ g1 q" O- public class LineRender{4 `4 w& x' B6 R/ d1 y1 g
- private final PoseStack pose;, v* v3 @. f' ]! S* n
- private final MultiBufferSource source;
2 n) _, W9 A5 t- @& M - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) H' D7 d5 G8 S, C - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
C+ H" L! n2 V - 5 e) N& x5 [' j$ D9 Y$ X' J
7 q$ @& t: h4 Q ~- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 S$ A1 D, m: D. g# e
- if(x1 == x2 && y1 == y2 && z1 == z2){) B% N3 ?/ `" v% s8 A# n1 j' P
- return;* r- o. G. P9 z
- }. U6 O: k! O% r0 F* Z* k- P! T$ Q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% [9 s- i/ r3 A! i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ H$ z, s0 k. b$ X
- }
8 J! u5 z& L% {" a - pose.pushPose();* t6 L0 x- z0 |1 x! x1 G: j) N- D
- final int newLight = convertLight(6); z/ Z- |2 h! @2 S* S) v3 Q; j* M
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 o }$ {7 T- _ - final float lineHeightSmall = (y2 - y1);
5 O0 q, }0 I" W) O2 p7 }& p - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);. X* T/ @+ n: L
- pose.popPose();
- U5 i* _7 s, _( @" T# s4 ^* P - }
# o9 }2 O$ p) } O j# m) D# X; _
$ S! K* x- L' ?' Y' n9 u X- private RenderType getLayers(String texture, int light) {
+ X( o( y9 Z6 M8 _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. s- c0 k- @# G9 S1 x - }+ L. J4 d, G, U% ]. p2 a
}: Q7 v( U) |. x1 O. Z3 g2 o* g- private RenderType getLightTexture(ResourceLocation texture) {
; `1 F& H( F9 q5 Q+ R5 h" I - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! Y1 n2 w* T0 C, y. K
- }
9 k# a6 y% j4 P# I* u4 [+ K* L3 B4 w9 v. M - 3 C' x8 S- m( P. f* N2 i: _
- private RenderType getTexture(ResourceLocation texture) {7 t% Y8 Y6 N0 d0 Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 H3 h* Y* [5 B: s. I1 k! X6 p - }# _7 Z! j2 ^4 f
4 |7 V, m/ I7 E2 Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 [- }5 l' @* u: u4 Y/ f1 C
- if (cache.containsKey(identifier)) {6 J# U* \% Z/ F( U4 a- C
- return cache.get(identifier);7 m3 b r4 L! v, z, s) M: _+ E
- } else {0 K& S$ w/ a8 m4 Z8 w
- final RenderType renderLayer = supplier.get();
: R6 Z \; F" ` - cache.put(identifier, renderLayer);
+ ]9 ^" S) i9 H6 p" k8 \5 [ - return renderLayer;, W9 p% A9 _% A/ D! F
- }
7 x/ D/ s, X5 N3 O% g1 t4 J: X - }
- J/ W% I# U# }; L# ^* i" u" a - }
复制代码 |
|