|
|
6 Q( D, @' F0 Z2 e3 i! P9 V, C" ~行,这个怎么样. E5 S2 X& k0 p0 e
- package com.xhg78999.mtrfac.render; D; ^) `7 \. h9 t6 H) }6 i
9 ~2 ^- ~4 q* R+ X- import com.mojang.blaze3d.vertex.PoseStack;, d+ _1 M ~+ H$ g# G% \
- import com.mojang.blaze3d.vertex.VertexConsumer;$ k5 t8 B& \" N
- import net.minecraft.client.renderer.RenderType;4 u; O. H2 Y5 x7 `, b
- import net.minecraft.resources.ResourceLocation;
! ?4 F/ J* [) K& B0 b3 [ - 8 U p ~% W" Q9 P0 T5 T
- import java.util.*;% B( B6 K: M% J7 t
+ R. I: q4 _9 X# v" q; n9 Q. N# A' b, z5 \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 N2 r# V; [: B - 3 f7 C" c1 \. U" k9 X5 i/ M$ j5 s
- public class LineRender{% H$ I v, p2 z, B1 S& Q2 X
- private final PoseStack pose;5 m( w2 Q! n& q" Y+ w. o6 [& z7 g3 J
- private final MultiBufferSource source;
$ ?6 D6 u& j( U, h) K* B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 x4 W. p) `& j. R& v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& w' N& m6 A9 K" I5 C% w
R8 a3 c( b$ w' `3 u- ; x" C7 v) I# H1 T u) v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* E# P7 c3 b i) d/ _8 v9 i - if(x1 == x2 && y1 == y2 && z1 == z2){' v" x/ `. i! w4 k- f! g0 K1 N
- return;
5 k$ i9 j. L7 f1 t8 P A - }
) ?' H4 [+ E2 n" ]. w - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 A2 ^' k" ]: e& y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ d6 g% O. L; ]# V( ?1 @5 F
- }
1 k& W, b; R5 H) U% C ]% h8 m - pose.pushPose();
: b4 I* O2 A% A; R; }- L - final int newLight = convertLight(6);0 y S# v% k8 H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));4 A" |. N8 @& B' T
- final float lineHeightSmall = (y2 - y1);
* ^& u# Q5 J/ Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ K8 t: _8 f( L - pose.popPose();0 e7 P3 J& H, e+ z& m. n4 v+ I
- }
/ ^+ J6 w/ T9 H6 r% x5 L - ! ~$ M6 s; r1 W( w" C
- private RenderType getLayers(String texture, int light) {
' M& k1 K: P, b- _% m - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));. }0 e$ |. S+ P' w9 ^
- }
3 f7 M) g; e. X" [' S0 i, t! o
0 m& t* |1 v$ ]4 @2 |- private RenderType getLightTexture(ResourceLocation texture) {
# w" q# K8 F$ D5 p) }0 ] n - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& }0 g7 \8 G0 U - }: Q. w1 Q' d) k. V* [% z( z
- + Q9 p+ o* @2 R2 W
- private RenderType getTexture(ResourceLocation texture) {0 t8 \- o9 m9 V/ i
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. o$ z' L' D3 j, N# W - } J) @( P1 z' i9 S
- ) w: w3 h7 T5 o) E% c0 I
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' X1 V% i- Y4 ]* ]7 j. b, h - if (cache.containsKey(identifier)) {
0 t+ b/ l% G; G - return cache.get(identifier);
7 ?3 ]) z) q( C& ]% P - } else {6 s! {# |6 m8 X' m7 [; T
- final RenderType renderLayer = supplier.get();
1 B0 I$ W$ E& Q0 @2 j - cache.put(identifier, renderLayer); q% x" l, j+ M* m- v
- return renderLayer;- O* y6 c+ D5 \' {
- }& y, ^$ k* D ~+ m7 c. M3 a
- }: u" ]% B4 Y* O% ]
- }
复制代码 |
|