|
|
3 m& N& a5 }7 a" ?, d1 N# ?
行,这个怎么样! E9 N& E: [3 N" P( ]8 q
- package com.xhg78999.mtrfac.render;7 a) n, K& K! q, P2 Q4 @. G
- 8 S) c4 r3 _( K
- import com.mojang.blaze3d.vertex.PoseStack;# {& q8 ]8 W2 t" o
- import com.mojang.blaze3d.vertex.VertexConsumer;
9 c; U: Z( o5 H+ s+ d: _: S. E - import net.minecraft.client.renderer.RenderType;. E; }8 x! k- {4 E$ ^8 w
- import net.minecraft.resources.ResourceLocation;
- I% x; L1 n D9 Y1 H8 P - : Z/ S6 |0 {& l( q6 C1 ^% y
- import java.util.*;& G, {; i2 b5 \3 R
- * {( G0 r( H c3 U9 q# W% w5 l
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# T2 A+ a. H3 l# z - + w+ J! h" E. v" }/ X
- public class LineRender{1 t3 Z, P) C# r
- private final PoseStack pose;8 T5 E0 O2 J# N3 l( o, X
- private final MultiBufferSource source;* r4 J2 Z- e+ f9 v" i9 d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 T3 U2 I& B, u) f2 _9 V. R: r6 M% ^
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 k) R3 T: i0 v3 V) |7 t' a
+ j6 p/ ]+ b, X. p& s. W, @' d- 0 l% {- _5 D5 N& D, L( F) z u
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" O# Y. Z3 u! j9 b - if(x1 == x2 && y1 == y2 && z1 == z2){
9 e" a* l# q3 i1 ~2 S6 B/ ^ - return;
. X! q+ U9 v) q/ z4 ? - }, x" E" g. w* R( K$ B$ S
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ N, Z0 s. f1 U- L/ b
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% d5 `( t+ L+ `. o! y/ Y1 L - }/ ^" b5 |8 z6 m7 _) l1 [
- pose.pushPose();
, x* E n8 z/ M' T" N - final int newLight = convertLight(6);3 e5 x4 Y3 }5 D
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ R6 j0 W1 Z) i9 Z5 b1 C
- final float lineHeightSmall = (y2 - y1);- q( F$ B0 b! i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 ?# |( d" \" m9 X
- pose.popPose();
& w1 R5 I9 B$ O& o7 V - }
9 g; m. J3 |: P* E! y
1 U1 o5 x' ]- L4 n/ Y" P8 T( W- private RenderType getLayers(String texture, int light) {
4 j4 E0 f$ T, i2 X2 G) Z5 A - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! D$ Y3 K! O- Q T/ u - }9 F6 f5 M5 w8 k) l& e6 U2 _
- 1 P& C4 S) \ a/ Y
- private RenderType getLightTexture(ResourceLocation texture) {
" F2 T* i9 T. d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 m: {3 b! v6 K0 T1 H" ] - }' k9 s2 Z+ v. J* k3 G
& H% y- R) k2 ]: Y: J- private RenderType getTexture(ResourceLocation texture) {
1 r3 y- @( a3 z: c; P+ d. U M - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 r, b6 Y8 T7 R1 J- a: Z9 O, W
- }2 T+ v; A" p* J: c
- + f- C [5 e" `3 e( l0 S8 P
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; p, C4 L% E; ?% F
- if (cache.containsKey(identifier)) {& D% j. F' [4 m9 n5 F
- return cache.get(identifier);( [) l9 W8 }* A9 }3 O: Z! P
- } else {- [1 L: ~8 g: Z
- final RenderType renderLayer = supplier.get();
4 p, t6 e. h/ f9 ?6 @ - cache.put(identifier, renderLayer);
, M( E. v( V' F5 }1 P3 { - return renderLayer; m. \. z2 i. b$ F% F5 q4 F
- }5 _1 t4 x; a( h4 w0 Q, R% w
- }
, d1 [$ Z; p; |0 e8 e9 p - }
复制代码 |
|