|
|
* N3 X t, X. ~) a, W/ h }8 M行,这个怎么样& |# [, a: K' t2 ]) f
- package com.xhg78999.mtrfac.render;
7 l8 U5 Z9 i+ C u: ^: ~# ~ - 4 t; {4 F7 w. j8 `9 \0 ?( Z4 {9 k
- import com.mojang.blaze3d.vertex.PoseStack;' o3 y9 ?, q+ r6 h1 A! f5 b9 U
- import com.mojang.blaze3d.vertex.VertexConsumer;
1 S" Y; q* z- @ - import net.minecraft.client.renderer.RenderType;" n& s( H. o" P7 ^4 x3 k" |' l
- import net.minecraft.resources.ResourceLocation;( P$ \% P9 D! Q3 ^ z/ ~
% ~8 E7 ~# q; v- w# H, X% p* n% x6 U- import java.util.*;
! |2 m$ S4 `5 y! E; f - 6 X' p: |8 |8 G3 z+ w
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 J6 i$ f+ S1 Y; M
- 3 A: U8 E7 C7 K2 c4 S4 `9 _ x% i, J
- public class LineRender{+ J- r" ~) m" e3 a
- private final PoseStack pose;, m0 A$ {/ }" W2 {' a, r
- private final MultiBufferSource source;! m/ ~2 E0 t" @, b/ X5 h
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
6 R: Y! K( h5 I0 _0 h - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- O, Y0 l, _( j( F$ v% \( l) N
6 w u) ^4 u, e! c3 @: {- ) c6 h* e9 U/ ?6 t2 y& k# d; W
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){, ^8 m$ \0 t \6 j! v
- if(x1 == x2 && y1 == y2 && z1 == z2){
4 `- l; B+ L/ x - return;/ a0 D! r2 A( F' g0 u
- }' r2 B+ y: }4 X5 u) M3 V
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- l* h. t. h: _/ A1 {0 b9 Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- N6 G, N; B* [ - }
: O1 B& \7 ~. C* @: D: B) \6 [ - pose.pushPose();
! Q5 p' `3 P5 m: R% x: R% b, k - final int newLight = convertLight(6);6 t- | r0 z# n' J1 m: m5 I, e
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 Z9 e/ C/ K X, q3 n, i. d
- final float lineHeightSmall = (y2 - y1);% b, _+ w) W4 O% n/ o5 l! m: X: A
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' }2 a2 {" q& T% c: z - pose.popPose();! r$ E! t0 ^# ~
- }
7 ]4 s6 @. K1 @$ X G0 H
, z) Z3 \7 l( p- private RenderType getLayers(String texture, int light) {5 I/ D4 N1 v. x! e F( v
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" J( u8 ^; G( Q% M* P
- }
( J9 C5 B! n0 l
U0 |% O& V: \$ n' U- private RenderType getLightTexture(ResourceLocation texture) {2 [; C8 U- ~* ~0 D/ v8 I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ d3 {/ e: ^6 d0 w, y; z - }
: f% H8 A+ e) `* {* z - 3 H3 q4 _' h/ z& g, @& ^
- private RenderType getTexture(ResourceLocation texture) {
9 C2 m6 N2 |2 H5 X0 V - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 d- S4 n6 u S/ g - }
# O7 [- y* D3 m2 T% Y" Z5 t: D - ! M; ~) n9 q/ Y: H, H+ f
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. m7 f$ _1 h3 S - if (cache.containsKey(identifier)) {9 _# d/ i; g ]' l% V, D) G
- return cache.get(identifier);
- M$ H3 O5 l1 b, w6 h- O H: n$ C$ z - } else {/ `. i9 C# J" U
- final RenderType renderLayer = supplier.get();3 ]0 S9 B% ]7 d6 K) e9 O
- cache.put(identifier, renderLayer);
$ P' B" J! u4 U - return renderLayer;9 f3 m+ Q' f# _3 R8 ?, n
- }3 K+ x; c4 V0 U2 R7 |3 L: N
- }
! f, i3 W- q% g! a) U. U9 f - }
复制代码 |
|