|
|
& g; ]# g! `' G3 g" j7 Y& L: i8 v
行,这个怎么样
" B5 R6 f. O& M; m5 A: ]- package com.xhg78999.mtrfac.render;
% V+ t0 W8 K; N. @/ a8 d
8 p6 C* _" |! D J7 W3 m- import com.mojang.blaze3d.vertex.PoseStack;
$ V8 \9 E/ Q# L. l$ o - import com.mojang.blaze3d.vertex.VertexConsumer;
N- J) t2 U# ]( \( J6 u - import net.minecraft.client.renderer.RenderType;8 j4 O; W1 I9 h: |: ~, W
- import net.minecraft.resources.ResourceLocation;
% n' o( T$ h7 {; x- x
& E. O4 |* }+ |- b9 u- import java.util.*;
4 I4 k3 V# k5 d0 I; n/ |
2 r" A9 v" X6 W* Y6 |2 k3 @- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 R; g A, s4 o# P2 k8 x9 V
* E" f8 k) O; @; o g' s7 _- public class LineRender{
# q# v" q5 Z3 l) h& F F& U% _ - private final PoseStack pose;$ [& m3 _* k$ f8 b6 l; }
- private final MultiBufferSource source;
/ D% d# B% q! [' L; K" @4 F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 o0 ]2 o, a/ Z2 i6 u% H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" [% o. C) U: g1 u- \ - 8 m- ~( P0 S" E i% O2 |: M& t
- 7 N+ Y# m. }0 Z/ |2 r: q/ p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: \& H" i" n4 h! |6 } - if(x1 == x2 && y1 == y2 && z1 == z2){& c$ l7 J N! z
- return;* W% _" _: O0 n* C: ^, o8 p' i
- }7 F6 @, l/ b2 S n- ]* v
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 \: \6 J. L! S! g4 b% l. R, k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) h Q9 f2 O/ u9 b - }: _' O( r! M; Y1 ~0 ^& z" s
- pose.pushPose();
. b# p: X; m! d$ n1 W - final int newLight = convertLight(6); M1 F8 m* T L3 k6 u) h' a% l
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 H1 n# t8 c0 `# k' o0 ?8 A - final float lineHeightSmall = (y2 - y1);8 i( ]4 t" A# g7 O9 H5 q- e" Q" V" a
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 I) M8 u: N3 c- k, ?4 c4 w3 q - pose.popPose();
+ R8 P2 `! }6 [8 Z - }. y6 ~1 I1 x5 k% J: o- Z% P
& P" _" s) K, b" r" @9 o* D0 ]; D, b- private RenderType getLayers(String texture, int light) {, m2 C8 z* |4 `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 u" h; ^+ a/ K/ y8 v
- }
. M# I$ Z& M' `7 @# i# Z6 O - " F, F7 h- g3 i# \7 ~) b7 y
- private RenderType getLightTexture(ResourceLocation texture) {! ?1 i% c: }0 g9 u1 U: n; [# c3 R
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) h6 l" s( s6 m9 w0 N
- }. o2 v. c( M6 L9 x* J2 Y
- . f+ z' J( b0 k0 [& n6 e! k
- private RenderType getTexture(ResourceLocation texture) {" G7 R0 `1 u" R4 |2 b
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 i% S( k, D' U" _5 I7 m& P - }
5 x& z& W/ Z! J3 B, D/ }
; v2 O* W4 o. o" U( V- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ r5 f" Q) V2 v9 Y. @$ `3 P - if (cache.containsKey(identifier)) {
{1 x$ f! |4 n. ?9 n4 i - return cache.get(identifier);; ^, g q6 f) |, M% E; @
- } else {
! B2 Z; p. W# B3 _" @# M5 r - final RenderType renderLayer = supplier.get();
8 l7 E- f9 Z3 G* N/ P - cache.put(identifier, renderLayer);
( A# w9 I$ ]. x - return renderLayer;
( Y. R7 [ C$ y" h; K2 O0 ? - }
O1 n) U8 {9 [ - }
8 w. o T# F% e8 Q& O1 ]* O - }
复制代码 |
|