|
|
; {* N2 T& J- h! A B1 q
行,这个怎么样
B2 @/ \; J, l. I! L7 o9 G0 W# H- package com.xhg78999.mtrfac.render;2 G. c5 C( r% p( S
' x8 H7 f% t! U3 S h( h; p- import com.mojang.blaze3d.vertex.PoseStack;" e) o5 Y# H& a2 O* M& f
- import com.mojang.blaze3d.vertex.VertexConsumer;- }; F, G# P/ s0 @& ?
- import net.minecraft.client.renderer.RenderType;: Z. J2 j, s2 D3 f, [: ~' e% i$ A
- import net.minecraft.resources.ResourceLocation;9 g; K" C6 m- p0 n
4 ~$ e/ d# b/ X$ ~- import java.util.*;
# ?" Y1 j4 i8 Z& g
$ L0 P/ E5 i) X4 G J7 v( M/ P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ ]: @/ o# ~: U7 H9 `
4 ^" z+ D& U5 B6 Q- public class LineRender{; {$ B1 l8 F3 e
- private final PoseStack pose;
# Y- T% p1 U( G1 `! S$ q( i) H2 a - private final MultiBufferSource source;' F# o% f- t" G* @
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, T/ a, I$ ~, B - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( k+ {2 _1 X# P9 }8 l0 W5 O
& T5 o) R% h9 W/ z3 q D- + {6 y2 a( j* w* Z/ {
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! }1 C, N7 r5 j I4 b+ T P! P6 u
- if(x1 == x2 && y1 == y2 && z1 == z2){" A6 ~! T' P Y8 B' W! a* q
- return;
a. G7 m0 Y8 j% R! K - }, a( {; C- T+ q& K7 H- S7 J( t! B1 I
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){3 E4 o2 b7 i4 _0 [( f
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");* P3 M# c& `3 n4 }5 @; o0 b
- }! @+ G* \# v+ T% c
- pose.pushPose();
) I' d- L) ~# ^ - final int newLight = convertLight(6);$ y7 I" j- @* T* W- {
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% r8 ?! K$ L- J
- final float lineHeightSmall = (y2 - y1);- l2 A* o7 ]3 |# Y1 ~. I+ S- Q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 _ e+ `3 k5 p+ B z; |
- pose.popPose();
$ w7 n; P4 R& X* E3 X( Z- u, n P - }
( b! y. s- c/ s' C+ a
! `& C4 g4 v+ ^* y, z( L- private RenderType getLayers(String texture, int light) {
% c. q9 `9 w1 ~7 D$ ^4 g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 c. V; H# H- N4 b; ~" X7 o
- }
7 M+ \, X1 j( A% a* a3 x0 O
7 r* L2 f l7 x- private RenderType getLightTexture(ResourceLocation texture) {( Q! B) u+ ~- C& M. \; e+ K5 Q- K
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! i$ R6 k& r ~0 V. X - }9 ]& Y5 G; g D! i
4 c* I7 ^3 ~2 } o8 G; ?- private RenderType getTexture(ResourceLocation texture) {
5 h5 s3 o B% S A" P) H& s. }1 Q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" P8 \2 l. J, x* L3 J - }
5 M- T D7 T+ K2 N0 ] - 9 J6 [6 b" L5 @6 F& k& r4 h$ ?" S) R
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* }; i; F9 {4 j: `6 q" p - if (cache.containsKey(identifier)) {
2 Y+ t* A2 J- k. e6 F - return cache.get(identifier);
4 Q3 Y% T& a9 s* n7 l" T - } else { H3 n8 b7 U* B" j
- final RenderType renderLayer = supplier.get();
9 o/ p2 O: N! Z) ^9 s2 y" l - cache.put(identifier, renderLayer);
0 N* n! M- s9 [9 d2 l* u% d - return renderLayer;) S, g/ \7 `& u1 ?3 g
- }5 X; H- ~3 G; M* K
- }
7 R8 c+ a: }' f" v) ?. n - }
复制代码 |
|