|
|
$ J% i. @ b% J0 [. i* p# _9 v行,这个怎么样6 }& O' h/ b P2 N
- package com.xhg78999.mtrfac.render;# \& B3 B" v+ F% U5 B" i: D
) w0 n4 H; e2 }. \ @- import com.mojang.blaze3d.vertex.PoseStack;
' ^, t5 D$ v' g: o- g2 ~ - import com.mojang.blaze3d.vertex.VertexConsumer;+ p- W# ]% u U( k# _+ ?
- import net.minecraft.client.renderer.RenderType;/ D a/ y& F5 a+ z, I7 Y7 @ P
- import net.minecraft.resources.ResourceLocation;+ s7 e" O" Y/ ^" `
! I* p5 y8 S( x% Y- import java.util.*;
" \# w4 g5 Z$ a: I* @5 w4 E* Z7 c# w
' m% `9 k: h% l% S* h- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. r0 X; t6 T; r, _8 ^$ k. j! n, Z9 T - 3 y" G8 t/ t2 L h d, Q7 x' ~
- public class LineRender{. @6 a* N7 @) w0 b' d
- private final PoseStack pose;
( w' h' I/ z) r+ i2 q - private final MultiBufferSource source;0 b ~5 b5 P$ l( a/ `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 Z- B9 F' C; }, c b& J
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();7 a, P0 I7 u; x `6 ?+ l$ r
# w& x9 m) G; a- ) z4 Q' V% N2 o
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; L5 ~/ b+ k# x. o- l0 g- g - if(x1 == x2 && y1 == y2 && z1 == z2){
8 A8 Z" S3 D& p9 H* d$ o - return;! `( D1 D4 ]8 y
- }) m8 |. W6 W$ ?# F& ~
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
g2 q4 \* k( m: T - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- X* p$ ?& g1 N9 B
- }
9 g/ T7 C) I o( G9 U - pose.pushPose();# l; L0 D: z5 c0 B* Q) [
- final int newLight = convertLight(6);
; I, S3 Z7 l7 z& n+ D - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ [/ ]% s+ j& ~" G) y - final float lineHeightSmall = (y2 - y1);
3 O) b$ S: w4 x- D1 O( s - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 b+ t R0 W- X4 N9 V* x - pose.popPose();8 `, ^$ c" F) K5 j6 G4 R" ~- a
- }
1 Q6 o7 q) H/ @ n3 T, D - ( w S: e+ s% t' x
- private RenderType getLayers(String texture, int light) {
" n% u2 E8 ~4 E9 g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));2 r# Y% f N# S. m" `7 Z5 e
- }/ e( t' m) {$ ?7 [5 \$ Z/ k
- ( i) w" d( o" R! q l `3 E7 P* S ]
- private RenderType getLightTexture(ResourceLocation texture) {& C; R+ S8 n5 `) O4 V6 Z8 N
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, c4 p8 u3 q7 g9 Q& n. ~) E
- }
7 V+ E* V1 k' S% K - ( k1 L1 _. h9 y. E# U0 T
- private RenderType getTexture(ResourceLocation texture) {3 P/ }+ ], ]' M! L. g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& o3 R! m% [* \% Z - }" c& _) ~1 ~9 l2 i( M( k r
- # s8 ]# a( |; _ e2 L. m7 T+ G
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 z, a) K; O6 t: X - if (cache.containsKey(identifier)) {
5 a7 B8 v2 j+ c6 q( t6 K+ B. [0 D - return cache.get(identifier);
1 L& d9 E7 i+ ~9 E - } else {9 x1 c! d. ]. e
- final RenderType renderLayer = supplier.get();- B, S) W2 ^. f' B+ l& L, {
- cache.put(identifier, renderLayer);* B- \( d4 [: P5 H" V% y
- return renderLayer;
% H$ T0 s# a! y* a4 o {% p - }* e3 g( q" S& R1 V9 v5 x L
- }
3 ~9 ^2 {) T0 J* @$ s. I" e/ J1 ^) p; h - }
复制代码 |
|