|
|
: v( P/ S6 D' o1 ]* K1 x% z行,这个怎么样
0 h9 k: B$ o, p4 o5 F2 M- package com.xhg78999.mtrfac.render;
) g/ b" C: F* f% B. @ - % Q! H( Z F( K: E
- import com.mojang.blaze3d.vertex.PoseStack;% y% T0 k' g2 X- B; p" Y7 _- S
- import com.mojang.blaze3d.vertex.VertexConsumer;
/ Q9 _* u' [9 b - import net.minecraft.client.renderer.RenderType;
6 n8 W, X" S* ] - import net.minecraft.resources.ResourceLocation;
* Q+ c6 }9 s( y2 I/ I
" M3 d% j, d3 [* W. e- import java.util.*;
y a2 x5 c% \
1 b) X( O# a) k. A+ k- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' u5 @) c: }3 W+ }: v
- 1 X$ c/ r7 L) q* B9 L
- public class LineRender{ S' v9 l3 N! W* k9 J: u
- private final PoseStack pose;& p& p+ o' X9 d% X' w$ k* S3 V
- private final MultiBufferSource source;
* Z1 ^& T' y9 h% y9 @( l$ r - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 U! \9 F! Y! m! S2 a
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
v% f0 Y9 V- W, {- u - # {1 ^* w x. ]3 X
- 4 _* Y8 u$ N/ {2 L2 q* w
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ T# g7 g' f0 ]$ S+ j6 Z - if(x1 == x2 && y1 == y2 && z1 == z2){; C, f# {* ~. L; K( T# P
- return;# H7 b, Z) H' H
- }2 K0 f, {$ }) ]% L1 Q% _
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
) M- b7 M! F9 h/ i& d - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" d+ s1 B/ C9 ]8 E7 N1 e5 |6 ` - }
& P# V5 R9 l3 Y4 s) Q - pose.pushPose();
, s+ D4 r/ L$ {4 S) Q$ f6 ] - final int newLight = convertLight(6);
# C+ j, s5 U" @7 R! E* A/ r3 ~( r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ e+ `6 K. w) P1 I; r8 Z
- final float lineHeightSmall = (y2 - y1);- p! u* ~" z( q+ K* w: q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 }9 U; Q6 J% Y" P( F7 G% P$ I0 L
- pose.popPose();
1 t0 a! S+ h; l) Q5 k' H4 P6 [# T5 B: N - }
9 Q' G, P# z) N6 q5 p
1 [: c2 r N Z% [+ L, c; q% d/ ~* h- private RenderType getLayers(String texture, int light) {
( Q7 I5 m8 {! A5 N; f% t: { - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; ?4 y* F4 Q: \5 ?. y
- }
! s2 c+ J9 R8 b% ]
- {8 t4 L* u1 Y) e8 h- private RenderType getLightTexture(ResourceLocation texture) {
, `2 d2 M) j; O% _ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 c( n- S: T, l( v. b. L - }
8 F k T6 _/ A! T5 ?2 j
' K) l' P: Q. L I% T4 y- private RenderType getTexture(ResourceLocation texture) {' p8 r. s7 D8 J3 T5 o2 a9 Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 ^. O1 E; t2 k; [# q) ~8 G9 r
- }
+ y% q) W4 g* o, Q% G
1 ]: m8 |! \6 R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ g' K5 H2 e+ e1 p$ A0 r& }4 p" m, h6 P - if (cache.containsKey(identifier)) {. N- C; J: e% m# g
- return cache.get(identifier);" Z7 a; w7 E3 [' n! A! ~( f
- } else {
5 K1 i7 w: e" p7 |3 `6 W Y - final RenderType renderLayer = supplier.get(); L) v2 x) |2 U+ I; ~
- cache.put(identifier, renderLayer);& @( Q/ n' U |' k4 ~0 H/ k* e: M& s
- return renderLayer;
0 b8 c5 w, c/ D1 y6 h9 o3 ? - }4 _0 }- j3 Y: B
- }$ c |; S; ]- b; r o. \+ e5 @
- }
复制代码 |
|