|
|
p) H4 |" C+ O' B9 e- e5 d: R2 Q+ D3 t
行,这个怎么样4 I" i& T$ ]. h- n j* f
- package com.xhg78999.mtrfac.render;! c' p; H* I7 l# q4 p; N
% ]# `- q1 ~; h2 k- import com.mojang.blaze3d.vertex.PoseStack;' O) r5 u7 ]$ F2 o$ B
- import com.mojang.blaze3d.vertex.VertexConsumer;, I" H* g3 c8 T
- import net.minecraft.client.renderer.RenderType;
f7 \6 R4 I' N( ]- O% y$ h% s. q - import net.minecraft.resources.ResourceLocation;# w; u* @4 x$ r0 G+ c) Q
- - \- w9 T4 s* @9 Q( P. a
- import java.util.*;) M7 s; n. S7 M3 ^1 K2 U
$ i' V1 d$ z7 G" Z0 |+ F- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& d0 H/ K2 j% {
. C5 s- Z: [# K# q- public class LineRender{
7 {# E) |1 o- m3 y - private final PoseStack pose;
# k q7 o. `& @7 g# w5 N3 ~1 r- t - private final MultiBufferSource source;8 v' j( w1 p6 ]; R5 O+ k& t
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 ~5 i! G5 P9 d2 x) X
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# e- b# O# u. ~" W& i/ D
" D0 f$ c+ k/ f- h6 T% u4 P- . V2 ?9 c# i* N/ b: b
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 @( ?0 F2 W# b! D2 G1 g% e7 P
- if(x1 == x2 && y1 == y2 && z1 == z2){4 E' I! y% s# u9 i+ ]1 G9 {. o
- return;
' y( i+ w, H$ b" T - }
- l" M7 n N3 w1 s1 E - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 S# r9 N+ q/ K7 ]# r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 k; k4 P( J: W, I! P, B - }" J5 x/ N5 P# W8 ]6 C; q0 ^
- pose.pushPose();
( a/ E* u. A/ y) ] - final int newLight = convertLight(6);
M: y/ j: ?4 u3 i+ O: g3 |( o6 ? - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! a2 x* ~8 f- K! P - final float lineHeightSmall = (y2 - y1);
) g+ t; }7 U1 V% S' r - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! z9 T7 o+ y9 t \6 Q3 \ - pose.popPose();
7 j' n% e. ]4 B. B+ W - }
: [. g% K/ J# Z p6 j) T - 2 `) R- q8 F S, W) J2 W/ j
- private RenderType getLayers(String texture, int light) {
" j( B+ }8 w4 j5 i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));$ q! |! Y( b5 A$ p( A/ t+ a
- }1 r% }9 j& ~" c. q& R% N3 x* A, a6 x2 M
- w* @# s# w8 Y% T6 K7 A7 N- {. v- private RenderType getLightTexture(ResourceLocation texture) {
0 u! R3 g* d8 N, k% p; B. o* q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);- o- M/ D" }: g; O4 o9 g
- }
$ F, D# G$ S m. h/ M
2 v5 H. ?# V l$ f- private RenderType getTexture(ResourceLocation texture) {. w2 N( h1 Z6 l% U4 e
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 u& h- W+ A' N$ O4 [& P - }
' G# Y) I4 d( p6 \8 Z* d1 _
1 r4 \# \, o( l( C4 j- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, i4 Z! [9 z4 q5 H& o! t - if (cache.containsKey(identifier)) {
$ K7 p3 w5 e; L3 e - return cache.get(identifier);
3 f, F; l" K9 m4 w: e1 O m - } else {1 P0 v& c- x& z% ^
- final RenderType renderLayer = supplier.get();
9 L1 L J: O; C4 P# m' }( z - cache.put(identifier, renderLayer);9 z. m: q1 d/ a! t* X8 e
- return renderLayer;; x4 l8 [( X' B; d
- }
0 ?0 O- k6 |; ]8 |9 i6 Y" X2 o - }
& A- Z, M3 \' i' ~ - }
复制代码 |
|