|
|
5 W% D5 ]/ b$ W! H' ^ B; L
行,这个怎么样6 i# U2 ]3 c$ n0 p
- package com.xhg78999.mtrfac.render;
D; Y9 p# _0 {- s/ y2 }( M/ s' V4 f
8 U: Z2 C+ }4 P4 I6 A, i* A- import com.mojang.blaze3d.vertex.PoseStack; Y% e# \! d1 O- c3 c! m
- import com.mojang.blaze3d.vertex.VertexConsumer;
8 I2 @# p! Z Z6 V/ I* Z - import net.minecraft.client.renderer.RenderType;$ f0 [7 c4 D$ s
- import net.minecraft.resources.ResourceLocation;
$ Y' E S1 e: R. b! j8 \8 v
$ H4 w0 `+ |8 b+ S* D9 z- import java.util.*;# z8 z9 a+ {1 R* n ]( ~4 h
0 X. b6 i* I$ e* [/ q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() d5 ^; ?; [- _: w0 j
- Z! ?% [" J* K) y5 \- public class LineRender{& a: S0 @6 V& c% u6 p
- private final PoseStack pose;0 t- t% ?8 ]6 o7 a4 P
- private final MultiBufferSource source;
" s2 g" ^% E8 I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();( X7 _( C8 m1 s8 j( A
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' o8 m" x( V4 I% V# N - ' P8 L- u! F, D/ Y. `' F! w4 ~
- 5 L" x& I* k i. Y/ u) t
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 G/ z6 \8 k; c" o9 z& Y' O7 H
- if(x1 == x2 && y1 == y2 && z1 == z2){$ `" B/ R8 r- t/ N% e8 L' b
- return;
8 w7 D/ E1 G$ ?& I, p - }, C6 ?7 e5 N, y: |5 n3 @3 V
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( e) m9 t/ i9 J5 T0 U, J: F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; s$ c2 u; M$ w2 x. S - }
8 n- [& [: M' n - pose.pushPose();5 p$ h* A& ?6 {" g$ O7 e# x
- final int newLight = convertLight(6);2 `1 M4 X$ I- @; s2 s/ ?
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ f- a; X! O1 I; o; s - final float lineHeightSmall = (y2 - y1);
2 E. H1 M. P/ S9 P. M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) j- o1 _0 k& f: X
- pose.popPose();
) D9 C1 w/ c4 _$ ^) a, g - }
9 C/ p9 h; n% r( c' [8 s* y - 3 X: p1 m0 t: D& u# H% N) Y$ _
- private RenderType getLayers(String texture, int light) {
1 a/ M0 w+ s& a- X6 U1 c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" B5 y' t6 _/ X- V. g" S5 m+ F - }) y# W2 u) m; j: S1 E9 ?$ t/ A
- , Q, n: C# a) r2 @8 F' Y' v( U' G- P
- private RenderType getLightTexture(ResourceLocation texture) {
1 W% ~" e- h- i# }' g# O& e6 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) I9 \9 D/ X" S - }
& ~1 d' l# H4 d: d* f - * F( h0 U9 K. Q8 F$ ]
- private RenderType getTexture(ResourceLocation texture) { d- J. }2 T. J, t7 k
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 G1 r6 y5 f# r- U% B5 E+ A# B
- }8 R, H! w% Z" M9 Q6 { N/ |
- ( C3 ]1 {6 s/ F! s7 J8 D8 p
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 A9 C% H$ W0 j4 ~5 H& D0 R& i
- if (cache.containsKey(identifier)) {
# B, [! f- L" `" D B B - return cache.get(identifier);
! l7 ?. W3 X6 v$ l( m* G - } else {
5 M1 D! G! n& u5 I) j - final RenderType renderLayer = supplier.get();
, g5 V# |2 N) c; N4 o) y- A - cache.put(identifier, renderLayer);
* d- v3 ?( s% R+ Q& `4 C9 F2 c6 N* @; F - return renderLayer;; \3 f$ U8 @5 r5 f7 o5 N6 @1 s# |
- }" U2 }' s2 P' e; e
- } h# @! K' q/ }6 M" q9 I" y
- }
复制代码 |
|