|
|
# I5 {4 K" r P行,这个怎么样3 q* r) `( e! i$ p, n' W. ]/ j
- package com.xhg78999.mtrfac.render;
/ t" q" A. n- Z* T* D9 q, y3 P! J - ( ~% q5 N, c3 c0 H( H
- import com.mojang.blaze3d.vertex.PoseStack;( A; y C* @ k
- import com.mojang.blaze3d.vertex.VertexConsumer;2 |2 \4 Y( N' w: h
- import net.minecraft.client.renderer.RenderType;
6 H% c$ f) c* ]& }5 C. d0 c - import net.minecraft.resources.ResourceLocation;# ], F. R! z c
- & g3 D% w Z( [) p
- import java.util.*; U1 f$ ]3 G/ J( k& ?
- 8 X% B+ V4 y$ M _0 k4 N0 ?2 c* Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ B+ i! e+ }) p6 M1 } - & a- s2 f( x S" }$ C
- public class LineRender{
4 b5 a$ K: D8 z1 g; q - private final PoseStack pose;6 z( I. z. h" }5 e; w, ^
- private final MultiBufferSource source;
% b" e) ]) N# M; [ R- i/ Q% q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 X( X, a* y# h+ O7 c2 m - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 c5 u# x) ^. M( B1 f+ k
- ' o/ q& J( n( U: L0 `) F2 K! J
$ v; Z r- J! `) z6 u: X- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- \( I& w- q, c# o
- if(x1 == x2 && y1 == y2 && z1 == z2){1 x' Q1 |5 O A+ K2 ] D" v2 ^
- return;# N- e+ y: z6 a' K
- }3 j- O+ q" H0 @. a8 H' a4 i: v3 U
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
@' P8 g" J, E* L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
G: @: J6 r7 `* O5 X - }
7 i" h. M) Z% B0 a& X! l - pose.pushPose();3 {9 h8 b; `, S2 l
- final int newLight = convertLight(6);4 X2 ^2 l5 q, ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
& q( X/ w" C, }; d# ?. K& f7 F - final float lineHeightSmall = (y2 - y1);
% d. }; S b7 M" u! E - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; m2 V- V# ~' l' f9 s7 t. q" K) T
- pose.popPose();0 x5 Y, z9 M2 e9 o" ~5 n# h8 G
- }
! _2 m5 Z! p/ ]6 l5 c2 @+ ^$ S: T
/ I# K9 M$ E* n1 v& t9 p& b- private RenderType getLayers(String texture, int light) {
7 E' ~: k( j# D; J+ k/ ] - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 t/ S" Y d4 q3 V* }6 d9 K
- }
5 h# G9 Y$ V; c4 m `9 }1 I% Z
2 V- i+ z* V1 M4 a# H8 f" K: ^- private RenderType getLightTexture(ResourceLocation texture) {$ M( A3 ?# ]5 k. c. [0 u# u& U. z& _
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# v4 G, ]& n9 G T' a - }; q3 z" a+ v7 l. O, i, u2 _& V
* w( v7 x# j& B" b- private RenderType getTexture(ResourceLocation texture) {
) O$ ?; T' E/ b/ g& Y, S0 ~4 ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);" q$ v2 o6 a t( i
- }7 n$ } X; E$ k" P+ W0 a
" o) y3 \6 H Q' _/ C% T' t/ ^ O- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% D/ C# K& T1 L8 H( Q
- if (cache.containsKey(identifier)) {
; r1 u/ \$ M0 d1 [1 W - return cache.get(identifier);3 K% D# j# x6 K, ~ e+ f; m$ o
- } else {0 [" ~9 o+ r i/ A* J$ q
- final RenderType renderLayer = supplier.get();- [+ Y8 i6 d9 U' O( Y# ]. ]
- cache.put(identifier, renderLayer);0 z" \* g5 K" `) h$ {2 r
- return renderLayer;
9 e+ Q7 }* Q0 b- S+ K - }
3 A9 [% Z# {# V - }
. M: q# g0 i) ~6 r8 Z - }
复制代码 |
|