|
|
9 _/ ]5 v$ P: ]; P9 P! y: n: @行,这个怎么样
6 }" m/ S8 G2 K+ _- package com.xhg78999.mtrfac.render;
+ t9 i3 n, e. ]. V1 P; A - & O+ H% a5 } J8 h
- import com.mojang.blaze3d.vertex.PoseStack;9 G1 ]; d- `% ]! Z/ y
- import com.mojang.blaze3d.vertex.VertexConsumer;, G* ?/ C! }, ~; j' N2 c9 w
- import net.minecraft.client.renderer.RenderType;5 \+ m+ \1 M* S
- import net.minecraft.resources.ResourceLocation;7 A% V3 D3 P+ z5 l) U
; R9 g: G+ Q1 r0 g! X) T8 ~- import java.util.*;
% _# z7 k6 R; J- j: W
% D6 A" Q- }9 c% a; X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 d3 l' U+ q1 q" w% @* G: I, T6 c - # y- ~( J- |* j3 i4 v
- public class LineRender{
5 P! e6 f; p* b. y4 a/ `& Y/ M9 I - private final PoseStack pose; ^1 }7 R0 O) F* H4 a
- private final MultiBufferSource source;
0 e2 q0 E: v- W - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
. u f6 O4 g8 a7 V* N - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 ^8 j+ {3 @8 ]) @% H4 a
8 L' L2 X2 F7 p9 H. ~: o, H; k. O
/ E7 o0 Z' j) h' ]7 \! y- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 B0 [1 w% {& ~9 }* F7 i9 V
- if(x1 == x2 && y1 == y2 && z1 == z2){7 N% P" h& ?( s2 `
- return;5 H% O) }( K( V9 ~; m: P; G
- }
9 t) r H; A( _6 ?* b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: D$ F+ Z" C# X I: c" z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 T% Z: Z% s# L/ o5 T6 t - }9 V" Y3 m J) l" _5 U, Y2 O" x1 \
- pose.pushPose();
7 j2 U% J3 g5 J- t - final int newLight = convertLight(6);( N7 I. F8 j; d8 W( }8 h
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; m5 R( u- N/ K. A
- final float lineHeightSmall = (y2 - y1);
2 g G$ Q3 F `. h E' z8 e: M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ u4 F2 T+ F+ P v! I9 W
- pose.popPose();. {; h3 P$ |& F. I) I
- }
( t1 q7 d, U& Y& y" T% H" F" X k6 u
7 D4 K8 {/ W3 d$ e- private RenderType getLayers(String texture, int light) {/ q7 \8 a3 j, [4 \/ K" p" G
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: ~8 Q# u4 k- O; }9 m3 ]! o. P& [
- }% f7 v8 Z6 r+ R+ k" N
' [ b' p. }% H' j) f; S8 e1 m" e8 M# T- private RenderType getLightTexture(ResourceLocation texture) {. \6 b' e: G6 \* F: e" `
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! s0 o# F, @! e' K$ Z$ R* H0 { - }
3 K4 y* r \: c [$ z8 M5 j% a. }
$ s$ k8 p! P8 b9 w* J, S- private RenderType getTexture(ResourceLocation texture) {9 t. p' m) @/ o# m/ W
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ [/ r4 ]/ f# ^$ z7 f
- }" C" P0 m3 z) X3 f- {+ Z" h
- ( A% G; `' P4 g% U" G/ B2 C
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 N+ |# ~5 Q7 f+ E9 s/ @- b' L ` - if (cache.containsKey(identifier)) {
# o @' M( z! Z3 `/ h$ B - return cache.get(identifier);
2 W! @. c2 @% I/ Z1 O0 H' @; M" l. E8 n - } else {7 U2 ]: ^3 a8 x' e
- final RenderType renderLayer = supplier.get();- M" T) }* j; F; l4 C0 a t }
- cache.put(identifier, renderLayer);* y3 |' s. p: N/ ^# G
- return renderLayer;2 G. U! M1 ^0 r& ?7 V- Y ^3 M
- }
0 S G% {( M {8 @3 @1 n8 o - }" \; U& j( U$ G: j. p. k
- }
复制代码 |
|