|
|
* X& B. O9 w/ Q' ^. i) u行,这个怎么样
7 C' A& a- ]3 R: k, A4 z; I- package com.xhg78999.mtrfac.render;
2 n+ F6 Z' ^$ n1 L# I6 O ]0 H8 j+ G
- B$ c$ W; j( e3 A7 V- import com.mojang.blaze3d.vertex.PoseStack;
% V. p6 I1 Q7 i6 j6 D3 B- y- l - import com.mojang.blaze3d.vertex.VertexConsumer;
3 k$ J4 S1 `; H( B4 f# R9 |1 j - import net.minecraft.client.renderer.RenderType;
: J, @8 D: D5 A! d' s$ w - import net.minecraft.resources.ResourceLocation;
7 o% k+ v6 m3 |7 |! P
$ h* l* l" j7 H! ], T- import java.util.*;, T) {/ p! P2 ^( D% X+ Y4 X
- % [: f& A8 n& A0 c7 T5 e
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 T1 [3 J* {+ @, O
) D: p$ l! \- q' |: q z- public class LineRender{/ l& ]. D T. F! Z
- private final PoseStack pose;' W6 I, ^1 X* F ^4 l, ~
- private final MultiBufferSource source;
0 {* o3 u/ R8 V( h% R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 J8 T- T; B* }8 y9 S- V
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();0 x# [! h* K: L( y/ P5 h; q
: ~2 g* E$ L- U0 O$ ]- # ^' @4 r* ?9 V" z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 r$ V3 }3 [" C - if(x1 == x2 && y1 == y2 && z1 == z2){5 M6 {! m) S8 D1 \
- return;
' L1 B- N% m1 o9 p- b2 e - }% _6 Y7 L: Z/ R* j: c0 y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){& ]. \8 p. C" D; o
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 P e8 n, O- r3 D4 {
- }" ]# b" v. b2 u5 Z, U6 J
- pose.pushPose();
$ j7 n X! |4 q - final int newLight = convertLight(6);
D6 F- ~8 k: v1 Q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
a' p/ @: W. v - final float lineHeightSmall = (y2 - y1);
- M- l9 r2 z+ Q( K+ F6 A - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( h4 Q6 T7 s8 E3 J% ~
- pose.popPose();
1 ?! n: c5 P5 F4 u, z3 t - }
: c) |- e- h; {: H3 m
( n- u" `+ z4 c/ ^4 u7 Y r2 h- private RenderType getLayers(String texture, int light) {6 p8 |6 `! P6 b1 H8 _) c
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- X5 t8 K5 g0 [+ } |
- }
* j5 s) [+ [8 K- e! } D+ ]& p! m - 8 Y: c$ k5 z) O
- private RenderType getLightTexture(ResourceLocation texture) {
8 i2 p4 a) A( A* ?* h! F* t - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% S$ Y# O2 f+ \+ o1 |+ |. L' D; G - }- _9 w6 r8 L6 J2 `' M3 @4 S
. t- W: {1 l+ {$ i" T& s- private RenderType getTexture(ResourceLocation texture) {
3 Y3 ?5 P! l& W( H' }: ` - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
7 {( r$ M& j$ x! q9 T! t3 I/ k - }
( t9 b J; H/ Z7 G; d - 6 C# A1 S( Q) y( }0 \$ r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
0 O! P! ?+ S3 ~8 D0 s' b6 C9 p- h - if (cache.containsKey(identifier)) {
0 s$ a6 `4 \% {+ G8 S+ q q1 n; { - return cache.get(identifier);
/ D( j+ w7 W: @8 I" w& u4 J - } else {% }$ j$ |4 w/ [+ k6 R6 Z/ d" X
- final RenderType renderLayer = supplier.get();
8 k3 E/ v4 W8 f) t& B - cache.put(identifier, renderLayer);
4 O* V1 p" O$ b8 Q4 v1 u - return renderLayer;- J9 j$ W3 w2 |' ]& b* |7 r- X& I
- }
2 Y9 l9 y0 F1 ], q - }
" N1 z# b1 ?" h! M9 I - }
复制代码 |
|