|
|
6 L; S" N* R7 ]# n7 `+ a
行,这个怎么样4 C+ q' r# J1 A# {
- package com.xhg78999.mtrfac.render;
2 i: y9 D3 c, N& Y - D) ~+ u6 F3 q. J% x
- import com.mojang.blaze3d.vertex.PoseStack;
5 F9 Z4 p; R" b& | - import com.mojang.blaze3d.vertex.VertexConsumer;
& ?; k- u0 S: } - import net.minecraft.client.renderer.RenderType;6 |: |( N6 B z0 T; G" |
- import net.minecraft.resources.ResourceLocation;7 W( W5 ]' Q) t" J
. g5 s+ b& c; Z8 s* J/ X4 S- import java.util.*; |" w) L. u3 p2 m& z& `
- " b5 m4 [7 G2 `1 Z( `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 a# Y1 P% c, T- C( l6 X) W* g; a
% C; h6 R6 b- N* }- public class LineRender{
$ J0 Y- D- T2 B! j: o, Q; A; D4 x - private final PoseStack pose;8 M8 m7 K, ` w( F, L
- private final MultiBufferSource source;
0 n& q+ Y% ~6 |9 s# l. t* n! y. V - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 K( d* A) W0 ?2 @) B2 ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 W; J" n' i# p- x2 U [
6 d8 B' {1 M$ M3 d, x- M- : W6 w2 i; l7 Q- i2 e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% c# f2 c# Z8 Y
- if(x1 == x2 && y1 == y2 && z1 == z2){
# J: S8 e$ R/ t- R. N - return;
/ Y$ i+ {4 X+ c/ M( T. x - }7 H+ P' l% ?3 m; T
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- D( b3 c$ c0 W9 E/ E - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 g. S% r: Y/ @6 {, |% D
- }3 l7 }; g3 D" Y+ j$ H7 ^
- pose.pushPose();/ a* H: ^9 v, v6 ~* y
- final int newLight = convertLight(6);
+ q# H8 Y" |3 H& g* K' \+ ~% r8 u - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));4 W2 [9 k# D' _/ z7 G/ |
- final float lineHeightSmall = (y2 - y1);/ @% j7 A* z. z* Q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 T8 V! i4 W: |
- pose.popPose();2 a# }8 j) p6 v7 @8 F
- }* }9 ]) ? I5 F* Q& L0 K- j
- 3 Z0 m* a( c( a5 s( q5 F
- private RenderType getLayers(String texture, int light) {
; S: w/ I3 r: q8 w9 A, L! Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ v* j7 j2 X. a - }
+ M+ m9 O; i& z' | X7 | - / u! V# B" ~6 s U
- private RenderType getLightTexture(ResourceLocation texture) {
9 d$ \9 q. S- j( P7 \/ L - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& e3 {1 @4 |& E$ R4 c3 Y - }
' O* y3 h9 V8 n/ F$ |. g" T% T - ! D$ u$ m F, W; K% c8 q. e9 k
- private RenderType getTexture(ResourceLocation texture) {* L: q9 H! ] J" j0 B5 C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; u) _0 M! N# k" y9 L) s/ l3 ?8 j
- }
, N6 i8 r. {% [/ h4 g* z4 r
" a& R0 o6 S7 j( H) v' H- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 ], Y+ n @9 X) y0 } - if (cache.containsKey(identifier)) {
, K6 t2 D9 y8 a2 p1 R% f% {2 ?! q - return cache.get(identifier);
8 e' a$ [- i9 _% o4 t7 i$ N - } else {
5 p% l y. [" c$ X: x( K - final RenderType renderLayer = supplier.get(); _% t/ l0 K# m7 K" k
- cache.put(identifier, renderLayer);
5 \5 C4 n7 v. c - return renderLayer;
+ N8 S( J* p) n - }
. F2 B4 o, F$ t, F$ } - }
# x$ Q( |6 Z5 `: k5 w% c3 q F - }
复制代码 |
|