|
|
) G- W0 ?" G/ G& i* ]4 s行,这个怎么样
! w6 g& b0 X6 b& T, I9 W- package com.xhg78999.mtrfac.render;. @+ q, S" b' k, R- X6 _
- " X! C; ~- Q3 b
- import com.mojang.blaze3d.vertex.PoseStack;5 d$ ^7 J/ T8 u$ ^: p$ r5 O
- import com.mojang.blaze3d.vertex.VertexConsumer; l6 |& ^2 X+ n: ? P1 T
- import net.minecraft.client.renderer.RenderType;' E0 W$ p Y2 D, x
- import net.minecraft.resources.ResourceLocation;6 m' }9 U4 ?3 Q8 x1 r1 n
- , o8 O3 Q, z: x) b0 c/ V2 P
- import java.util.*;+ J( {$ D0 o0 }" h6 Z" u# n
( L, i4 c& X( x- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* I% d/ j0 \. k6 s8 |- E6 ^+ r: S! N
0 D, L1 q" [# }( n- public class LineRender{
0 i+ A8 Q+ H) ~ - private final PoseStack pose;
" n5 U# U- \0 r; Y; C8 m; x - private final MultiBufferSource source;
: S3 l' t! w! v T. G4 p: ` - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 J, K* H/ Q; d- T7 \
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, b, f( V6 I; l$ x4 J( }3 M
+ u$ [! R" P) C6 }
+ W, ^5 o! i; M; V- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ @7 O% _7 ?3 [7 h8 U7 U" W/ [; l - if(x1 == x2 && y1 == y2 && z1 == z2){
' E. I+ a8 l0 h+ B$ ?/ ? - return;" l) b6 E; w. q" d, c
- }" t: v6 ?8 h( n3 k m3 G" t
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 _! ~* v" d; k: A
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) n$ K' V5 h2 I - }5 ]5 @$ h, D( I+ a1 s$ I
- pose.pushPose();
+ a0 a+ f( L' q6 }5 B+ Y - final int newLight = convertLight(6);
% V; x+ F+ p; }: O8 J3 P - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" j/ q: q3 O% s
- final float lineHeightSmall = (y2 - y1);: N/ r9 B4 e, ~6 @1 b$ `
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; r9 f" j a9 u! L" M2 T: H9 D
- pose.popPose();
" |0 K. r! }, a# [' X/ s) g - }3 n4 o6 z. ]! m- \ R/ c, }
6 L3 S3 @- G5 ~/ i( m( `, b z- private RenderType getLayers(String texture, int light) {
; d. P! z) K' @# {$ p0 a) _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. Q+ L$ `$ E& S G# G - }
# l" {1 i! \" X - / R, o2 ]2 I" o$ v
- private RenderType getLightTexture(ResourceLocation texture) {6 s8 J" C% u. `- ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, ^ i9 s, k/ f% `6 O, q3 x+ r3 U
- }+ G/ |7 r7 x6 R# E% u
- / f4 c+ z% }0 N( T+ G6 o2 x9 e
- private RenderType getTexture(ResourceLocation texture) {) p- X+ F1 H$ q+ S1 F$ U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ z+ z3 _/ [3 `, C4 a0 Z/ z/ @- b - }
' k" }( X( F: Z6 W+ m' z5 C& [ - " D: ~6 n1 |6 Q( ?
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 ^7 l5 V4 p" U4 R - if (cache.containsKey(identifier)) {! N3 O. B5 g2 i+ P) M
- return cache.get(identifier);6 ?" V9 r. S! l: \+ z# g7 r# c
- } else {
5 I7 c0 P# u* u: b& t$ i# m - final RenderType renderLayer = supplier.get();" l8 p5 S( A) l: v# G
- cache.put(identifier, renderLayer);
- o3 K0 {; W: f1 f6 v6 {9 ?& } - return renderLayer;
" q% Z0 U9 S" ]# I$ P$ K - }3 O3 w k8 v$ b) E K
- }* S8 P8 q( k& E2 x: A* a
- }
复制代码 |
|