|
|
2 ^; z+ w1 R" i1 P* [4 a N/ v
行,这个怎么样, D& s( ~+ |. `) g
- package com.xhg78999.mtrfac.render;
9 U5 `% q, U, n$ p* O' ]
/ ~4 d! }9 m6 m( E% i& J% v- import com.mojang.blaze3d.vertex.PoseStack;
2 F- B/ I( u8 S! J- o! _. r( p - import com.mojang.blaze3d.vertex.VertexConsumer;* K" V2 A& n# i) ?
- import net.minecraft.client.renderer.RenderType;
& K! G) m$ S, \& h% p5 A7 f - import net.minecraft.resources.ResourceLocation; v5 Z! ?2 ^ V" h$ _* C
, J7 I# ?. `* ]+ H& F# A- import java.util.*;
i" C' a# w) Y0 u6 L6 T( u
* I# M) I5 ?$ Y( W. U6 ~6 F. T- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
W9 c! [9 ^2 \- g# J' J
# t: n( H) }- c$ E; S& B ]- public class LineRender{$ m2 b1 ?; r( r& c7 i) b
- private final PoseStack pose;
2 g- |' s8 G9 p( ~6 o0 ` - private final MultiBufferSource source;0 d# A* K! K. [) \ V
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ M* T5 N+ B0 V3 N - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* t4 o3 I- R2 X$ w0 w
2 W+ y% X1 h" o8 ]2 R6 c
, ~! \% d2 v3 ]! e% |' [( N- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 T' `( u3 i' j" ?0 ~
- if(x1 == x2 && y1 == y2 && z1 == z2){
4 I' H5 j2 C0 H% Z( m1 `, v; H N - return;
) T& E/ h7 y$ f" i$ s - }% u4 \ M3 z9 p S9 ]" G
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) P2 A4 h5 }5 q( V
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* ~$ i# ~7 ^" i; Y4 t$ { - }+ P7 t" ~; T" w ]8 P" Y
- pose.pushPose();6 D9 g1 S( I, x
- final int newLight = convertLight(6);. y1 f" t' o0 f% ]6 @! |1 F+ h
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
# `% h9 X. i. K7 n+ v; V+ o - final float lineHeightSmall = (y2 - y1); q( c( w0 g; B" C8 H
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 {* O( x( S. B7 w1 f# ?" r6 b+ H `/ A
- pose.popPose();6 k% x4 T" L* c, q# `; [0 l1 m4 s
- }* f5 n/ k0 F2 {. r# U- L' i7 N
. l4 s# ]$ B" l3 [& j% v& y- private RenderType getLayers(String texture, int light) {
- ]1 G8 P& r9 x# y3 n( F - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 a' J$ l% q% Z/ q, n# c, i
- }& W+ [) y. v5 P' A0 t
- I& E( ~' j1 v: T5 G# h- t2 A& T
- private RenderType getLightTexture(ResourceLocation texture) {7 \% Q" H7 \3 T1 s$ p Z1 Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 n( L p$ r- S - }
s* [ R4 A% T' [! c& C* s
, U6 O- u+ x R4 F2 W6 ^: m7 H! d- private RenderType getTexture(ResourceLocation texture) {. _5 }- t4 \+ F y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% b. I: N, N, G! _" {! W( V7 P - }
0 I! q- q3 ~8 C! m5 ]% s - 2 d0 \9 B* W. y5 J3 p/ s, |" e, I
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 u/ O' M$ X, t$ ~1 B4 K- s3 C6 J j
- if (cache.containsKey(identifier)) {" r: x: [: h+ i' I
- return cache.get(identifier);/ p X1 l5 N0 s/ q! ?- k, W! e
- } else { J& H7 J! A3 i N6 }) R7 m5 ^
- final RenderType renderLayer = supplier.get();' O! G) D/ j' q' j8 u+ g+ X; d/ L$ K
- cache.put(identifier, renderLayer);- [8 @# X |/ Z* V. _4 w. S
- return renderLayer;4 p( ?& x" h, K0 i: C" E8 Y! V
- }4 q: V# z& H' F, e- S
- }
x. ~% }, E; T- H. r3 p - }
复制代码 |
|