|
|
) A, U1 D7 y/ e5 M0 z; P
行,这个怎么样& t4 U& S' ^5 j( J- J
- package com.xhg78999.mtrfac.render;: O) _! ?# B" @6 |# C
- 4 k' t# k+ F5 F0 u
- import com.mojang.blaze3d.vertex.PoseStack;
# G* R& O7 T7 {; G3 f6 [ - import com.mojang.blaze3d.vertex.VertexConsumer; \! T r- }. U; U
- import net.minecraft.client.renderer.RenderType;
0 I) j$ l6 d/ a9 V* `. A2 U4 W* S - import net.minecraft.resources.ResourceLocation;; t% J. y' w+ l
- 3 M/ m' @; n4 P& x# ^. m5 P
- import java.util.*; G! X9 l* s6 k s" P
- ) R& I% n/ w1 t" f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! P4 ^3 X' P7 _/ P' i/ r4 K" z
- 1 n( c5 E" f6 @" S1 [( S* M+ I
- public class LineRender{
: r+ _: l- ~5 \2 |0 ]) B8 |- d$ K - private final PoseStack pose;+ ~) a% E0 D( E7 C5 P* G4 n5 U6 A
- private final MultiBufferSource source;% H) m' l" n9 M ^2 C% ?4 B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();; L1 f6 o: R+ } } ?, D
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 a8 k% S! n( Y2 J/ y2 }% U
3 n4 } m- F1 E4 G9 _2 @/ {- 7 _- y4 M% k9 }* g
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! ~" B9 t8 Y" h7 w
- if(x1 == x2 && y1 == y2 && z1 == z2){% X* _1 ~% [5 a4 F
- return;
4 p, \5 i- `" p - }
" p: x% A: x% m; w! Y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. o& M2 W0 F3 M# f( D3 A2 e1 ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" c: E: x8 d0 c2 \ - }
9 H- w7 `6 }! R0 j8 V - pose.pushPose();
/ M, d, o2 \8 {& g! r$ V+ n - final int newLight = convertLight(6);
5 h4 S6 h& u; J7 M" C2 ^+ X" D: X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 S+ ]7 {# \5 _- N$ W& k: m& [; _
- final float lineHeightSmall = (y2 - y1);
! g w! }6 f1 o# b& Y4 X8 r( D- ]* | - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# _- r' K' P0 `4 r, H5 \: O& _
- pose.popPose();
, A: \" Q0 S0 @1 N. N% y. i; g - }9 ^( V7 l! I8 N) i u
% \! w4 Q4 [2 `' q) i0 t- private RenderType getLayers(String texture, int light) {& m6 D C% S; \7 X
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 K7 g; d" A: g" ~# M
- }
2 Z- L- a% v( p" S: L
: P* Q8 c* a: ~- private RenderType getLightTexture(ResourceLocation texture) {& S/ L# q0 t% @5 l, r. n) V% ^" B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, `! G$ D) e6 G; t m - }
: g& x- G! L$ _1 l; _" |
o% |3 ~3 J7 d7 `: r, z( d- private RenderType getTexture(ResourceLocation texture) {
1 P( w+ O4 C. I& ]- z4 ] - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 Y% ~/ G, x2 {8 c# K
- }
0 K P/ {, u, p- I" W$ F - ( R# I8 X; f- ]1 H) W/ @0 }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" n8 u$ p, d5 p5 y
- if (cache.containsKey(identifier)) {
3 U6 G4 e" S4 M" N - return cache.get(identifier);
$ c- {4 Q8 q) A$ l - } else {' ?; l8 Z1 f4 T% h8 n( q
- final RenderType renderLayer = supplier.get();& D! a2 Z/ r8 B3 C4 x! a- ~
- cache.put(identifier, renderLayer);
6 d$ y0 M- x! a; P% q6 X$ b0 S - return renderLayer;9 @! C3 u$ F/ `; ~) T
- }" A0 H6 e0 F: e( T" x
- }+ M7 s) X6 b* a @9 V
- }
复制代码 |
|