|
|
% O3 j3 L% `2 o7 G" P" n$ A( z. T
行,这个怎么样
' T, ^( s E# [. O- y+ C: _- package com.xhg78999.mtrfac.render;
9 t" D/ V, d# m# Q! }3 i/ d& @ - / W5 o, f5 x8 I) Q$ R: D
- import com.mojang.blaze3d.vertex.PoseStack;* v/ u6 f1 w- z: R
- import com.mojang.blaze3d.vertex.VertexConsumer;6 J0 N6 s4 u$ c& q
- import net.minecraft.client.renderer.RenderType;$ }/ @& Y1 r' T; f3 W! i" q
- import net.minecraft.resources.ResourceLocation;
3 a& x. f" ~5 T. z) {' Z1 a& \ - ! I, L5 P3 \- L/ U- [9 F
- import java.util.*;
8 X1 C3 |1 J) u, C, [2 w
5 U% y4 K; a: E) {4 _) d) A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 |7 L. I" V: r6 Q) r! l) A
& F- W* L+ L9 ], r* o2 M$ Q- public class LineRender{6 x5 a* D( n7 \% M/ D( e
- private final PoseStack pose;! G9 i) W2 E, _( f
- private final MultiBufferSource source;9 U) S; p; h" b7 D+ }8 [+ ]- `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( b0 Q! j5 Q1 H6 _' Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" C4 M1 G+ M) p: c8 D; q0 K
4 O7 S% Y1 S- Q" M" M. B4 Y- * K& Q( r% A8 d6 {" K
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 p# @# k" c4 l" P) B9 J5 K8 ]
- if(x1 == x2 && y1 == y2 && z1 == z2){
( W8 e3 k4 b3 l" s4 I! X# C - return;4 Y8 H7 l ?1 R6 k5 {
- }* D% \" C. k ?4 ]) R; [( f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 s# l5 [! P4 Y$ B2 ^
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! L1 @1 L$ T, \3 \' k. C - }
# C. ]8 c1 t- ? - pose.pushPose();
0 m( o0 |4 J& ^' M% S1 ?! W0 `+ b8 a - final int newLight = convertLight(6);
( M* C* n! B& j; r5 \! O; q3 M - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: Q9 e d/ Z, j) v s* V
- final float lineHeightSmall = (y2 - y1);( e3 W$ m" {% x$ W3 f u' ^
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# Z8 U: T4 @ h5 L8 k m* v - pose.popPose();5 v. t1 Z) ?" t5 R* z
- }, w* Z, [" z- `9 B9 }: O/ `8 t
- & K2 U; X0 {3 Z$ J! ~% K* J& Z
- private RenderType getLayers(String texture, int light) {
0 A2 ^; H5 a, R& U& E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. H! @( @$ y; {8 X: N) r - }
$ x5 ?, ?, g5 T8 R8 F' V( B - 0 ^! U7 v# H, V4 ^3 i) d
- private RenderType getLightTexture(ResourceLocation texture) {
: f% K2 [+ Z4 ~ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) m M6 L2 S, r+ x4 U8 S
- }+ w' D# g4 o/ N; j3 g+ W
- 3 b j. x9 ]% g4 G8 r3 [, S5 W
- private RenderType getTexture(ResourceLocation texture) {4 w1 |# C& R) D- D9 F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 z8 Z+ w* |0 l9 ~3 m7 o - }' W, u( O( h) T5 ?6 B0 R z
- : w$ a) f* `* o1 y# u# r5 a
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { l1 G8 f: v4 m* G% M3 T
- if (cache.containsKey(identifier)) {" x+ l& _/ s( J5 i1 A
- return cache.get(identifier);" k- w, T# N4 \! w
- } else {
& s$ n# ` P# V, ?$ E0 ` - final RenderType renderLayer = supplier.get();
( z% G, ~/ V0 H0 y. T, y2 Q/ ]: `: B - cache.put(identifier, renderLayer);- E' v9 y6 J( y) Q% i, x, p' ~" x1 R
- return renderLayer;4 b& x4 @' D, p2 J
- }
$ a" h( C1 L0 w. J2 w - }" p* ?3 C! j% Y' Z" j1 h
- }
复制代码 |
|