|
|
3 y! c" K, P3 I行,这个怎么样
& s8 y1 p: C& t: ^9 Q- package com.xhg78999.mtrfac.render;
, `( ^$ N% ^0 W9 B/ Q5 T - 1 \9 N+ y0 _5 S; |% C
- import com.mojang.blaze3d.vertex.PoseStack;
3 o( g5 ^( p6 r# Z+ Y - import com.mojang.blaze3d.vertex.VertexConsumer;
; g% _0 ?, I0 u6 j" c0 n" p+ g - import net.minecraft.client.renderer.RenderType;
: P2 d0 l; q. U! d; z6 F- B - import net.minecraft.resources.ResourceLocation;
0 l0 o" N* w, u+ V' u& R0 h7 M
' N5 E1 d& [! W4 p: R. `! o- import java.util.*;- T1 z B; P }3 s8 |- n1 Y! E- j1 ?
- / k+ }7 v- b$ i& d% ~3 P' t6 ^- b( j
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! Y, }6 V; X8 Y7 u - 9 w8 ?% h+ r5 }* ?
- public class LineRender{8 n: X2 i' R! [. H$ E! q g
- private final PoseStack pose;+ ?; F1 }5 Z2 M4 {
- private final MultiBufferSource source;
- j: i7 M) i& I1 W: m9 e. Z( q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% N8 {* u- l7 y% y) Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 x! ?- s7 o5 U1 D( L; K( p' k - 8 r. c# m5 c/ F6 m
- % r1 c& x, t" j& u% N8 G# s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& _" q8 {2 Q# J+ p9 n
- if(x1 == x2 && y1 == y2 && z1 == z2){
& u1 l/ r8 t j9 _, @$ D/ \ - return;
* U% C7 x6 ^& g: p K( a - }
( m8 l" V* E6 }; U3 `( a0 o+ \ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 F/ p, M3 [- i* x/ F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: W/ i" B7 H4 g4 N
- }' L' a# r6 o7 T$ w2 R
- pose.pushPose();
3 F2 N8 V) f" Z1 y - final int newLight = convertLight(6);
: k5 M$ w0 E3 {, M4 @5 @0 m, e - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ k7 Q9 t% \! N- G - final float lineHeightSmall = (y2 - y1);
" k1 E8 n& `9 V1 b% z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 I: | w5 ?1 ]2 E8 b& N4 s, |0 k - pose.popPose();
; A! \7 d# t/ a0 A' G& z1 r. [% o$ { - }) e. \2 v+ {. p3 Q6 [& |/ N; g
5 n6 N3 o6 H- u. U; I5 k4 U6 S2 X- private RenderType getLayers(String texture, int light) { y! m3 X# Y. ]
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 V9 Y" ~2 i2 \% }. B7 b
- }! H; I0 ?' @( l: V& R9 j. P- _
( z5 ?* e0 n- r9 J- private RenderType getLightTexture(ResourceLocation texture) {, @' ^; }' x+ V! w
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 c% W9 w4 ?! p( a/ J0 i! Q
- }& g! K" c7 W% V; C; g
& M9 m- k$ G6 N& s6 ^4 j- private RenderType getTexture(ResourceLocation texture) {9 Z, S' k- f; f' E5 M0 S
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; \5 u/ S/ A: V5 r0 U4 l. V; @9 b - }
- d# k7 o5 T( N4 k& q/ C
( N4 ~! Q8 n; B9 ?5 @/ U- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ Q0 R" R% v1 B- B9 K7 s9 m - if (cache.containsKey(identifier)) {
+ { b0 A* }# Y# R( I6 e, j - return cache.get(identifier);
4 r5 _8 \7 o' P5 q" l0 @% S - } else {
5 p+ c U4 h* e: N& D - final RenderType renderLayer = supplier.get();
/ H1 F7 v7 R& d( {8 |: K - cache.put(identifier, renderLayer);
6 D4 f5 J- ?" V& B8 s* V9 C1 X - return renderLayer;
; q O% @4 J( ~* t: R; _ - }
2 ~; E0 @/ X- t - }* P+ @& D3 f' U% s
- }
复制代码 |
|