|
|
2 t0 U! A" M" [
行,这个怎么样
; N! c5 |) z9 n( @& b! H- package com.xhg78999.mtrfac.render;9 p7 b8 t4 g+ r# [1 X t
^0 C5 L' |" u8 n7 z$ j' I) _- import com.mojang.blaze3d.vertex.PoseStack;+ F; T' N u4 H: ^# a I0 O
- import com.mojang.blaze3d.vertex.VertexConsumer;
6 h* d3 O: m! X$ X' U& ]1 X, e7 k/ S - import net.minecraft.client.renderer.RenderType;% J4 w4 o3 h* x2 L7 A1 }, d
- import net.minecraft.resources.ResourceLocation;. O6 ~( X2 Y5 f" C0 M
- 3 I8 Z4 o4 w8 r4 L8 m4 ]
- import java.util.*;5 b0 l: c, c; l. b) {$ L: q
- 0 f2 i* `1 K! m; [) p# ]
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 Z/ l- i; [( A3 j A/ `
$ O# ?4 m1 e0 e$ k, c% N- public class LineRender{
8 O7 Z, h! v% T- }0 G - private final PoseStack pose;9 b7 Z# C6 V- E( [% [' Q; I
- private final MultiBufferSource source;
^* ]- x. ]/ C! } C! m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 _. Q Z6 g8 H' c* }! n
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, S6 Y. P: }6 F q2 o - 2 B" I3 ^, W" H) a0 A
: l% v/ f& J* Q2 v- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 {% I- |! z) b6 g+ K3 s
- if(x1 == x2 && y1 == y2 && z1 == z2){
# m( C2 U! k c0 d. U - return;. j% l3 m$ W8 x! [' ]3 u7 K% _
- }; g6 E" j$ \0 w5 a( e
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ t, \+ \/ \& }
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( i8 U7 j" m6 n4 L& M" L
- }
4 V% M6 r1 z& s. n0 |7 ]2 \7 B; M. b - pose.pushPose();
. z, w% P4 L+ T- L - final int newLight = convertLight(6);
& ^7 G3 C8 m a! L3 q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( y+ ]3 w9 ]: u/ H2 s# D6 I
- final float lineHeightSmall = (y2 - y1);
5 D# d" z' G7 \8 C3 F7 C7 r* k, z6 I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; }) g* e0 G+ z- M' y/ F/ f- P; F - pose.popPose();
4 W+ {) A i- a- N+ X+ H- K - }6 V( M: c+ i6 {' e
6 B1 W B7 O2 G+ t( J- G% P. B) w- private RenderType getLayers(String texture, int light) {
8 U1 m5 |' @( q! f& L& |0 v2 ] - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- f% g2 m* r0 S% m) V9 K* W
- }! F& q5 W4 D& Z; p
- ; D% H3 |5 X* k O9 Q& Y
- private RenderType getLightTexture(ResourceLocation texture) {
) K% c, w" I* ^, w& } - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: k% s* ~$ \8 j7 _8 d0 Q" V
- }
0 x6 ~: J0 d/ ?0 r* l7 p& c - G: Z' j; M, X
- private RenderType getTexture(ResourceLocation texture) {
# j* f: {7 D+ p9 b - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. r* D0 `' y1 @+ }1 F% B$ H* b3 ] - }5 g! }! I, q1 m9 W) p8 r
- " i- w% Q; W/ _6 k' G8 N
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% M2 p# w+ X/ P0 A' e - if (cache.containsKey(identifier)) {
z3 Q0 ]2 k8 g2 j9 [; W - return cache.get(identifier);
) c' v" t% Y, d3 k$ G* _+ ~ - } else {
+ k! q- v( `3 ~* U - final RenderType renderLayer = supplier.get();
( U. C9 k7 i/ R( v1 S - cache.put(identifier, renderLayer);2 T) m! B' M" j8 K" v) k4 B
- return renderLayer;
_" _# p* c5 q: R" s - }8 Q* D7 g+ ^! i0 e, N& q
- }
4 G) I$ g1 F: W; K - }
复制代码 |
|