|
|
0 F$ e4 I$ p! R8 }6 O8 K9 r
行,这个怎么样( l, O' |7 h3 }) I. K1 B
- package com.xhg78999.mtrfac.render;
% J0 I! `+ q, | - . j1 d" z, D7 O" Z9 Q) ]
- import com.mojang.blaze3d.vertex.PoseStack;
0 b; J. L2 l3 H' d9 x: m+ M9 S - import com.mojang.blaze3d.vertex.VertexConsumer;
+ Q6 p: X3 M2 {& a" C - import net.minecraft.client.renderer.RenderType;
% ^# p6 M5 j! k/ `' {6 x/ a( W+ R - import net.minecraft.resources.ResourceLocation;/ ?$ l. U& Z1 B* F
4 i4 `/ O0 p7 K- z/ I- o# s$ K5 Y- import java.util.*;
! m3 o0 N ]6 o6 q: p - 4 K; F. j& J5 t3 {7 j3 x, `& p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
4 i. h$ R0 Z4 s" O5 T, t4 d
+ m: \5 {* b+ {: m8 b7 w- public class LineRender{" Z1 u6 n# o, A9 B8 ? K% j
- private final PoseStack pose;9 I& e+ Y! u) m
- private final MultiBufferSource source;2 |0 F1 Q! R! l6 @% C
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();. S- `6 e, ^$ i4 u9 T1 e9 x
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- Q# |7 j' ?* X8 `/ q. `
8 n M) n1 }3 v
9 s: U( H4 l0 c% c2 p+ b7 @& o3 z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& n$ ?. Y- i( ~( x" _
- if(x1 == x2 && y1 == y2 && z1 == z2){
6 r4 v" m* @9 l" y- b1 ] r - return;; Y! k$ D$ v1 j. r4 d
- }
' p6 x1 P0 l8 U# E& J& {$ \ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 b3 F# L/ K' ?* J% R- C - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 h/ F L2 R4 `- C$ i
- }# P' ]( [5 R6 m* k. t
- pose.pushPose();
$ R8 _8 _+ R. ?# A1 `: k4 j3 [' E - final int newLight = convertLight(6);
2 Y$ l) Y V: P0 P$ G, x" ? - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. B1 Q \, e- Z2 a7 W' ?* p4 a! h4 ?
- final float lineHeightSmall = (y2 - y1);
, y+ X+ j3 J8 g/ C$ L- b - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( \' I: f$ s; I
- pose.popPose();; H% Z1 z/ Z" o
- }
- Q5 q+ F& g4 b% A
" b2 Z6 d8 M C* P, N/ X6 h$ E- private RenderType getLayers(String texture, int light) {
* U, C- H; ^4 H( Q( a% x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 C! _8 M$ @+ z+ r3 R5 i. k - }
8 V: U0 b4 ~) F6 U) r* X
2 o' O9 N5 \# w: S R4 m$ v- private RenderType getLightTexture(ResourceLocation texture) {+ X! T/ t" f, a7 r! N
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( P3 \7 H7 G' K5 X- A - }, _! ~, j* y1 K! p2 t \' D( q
- 6 ^$ S( |* E! k: V
- private RenderType getTexture(ResourceLocation texture) {6 n" }' M& E+ m3 g/ Y/ E, [" E
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
1 A L( ?* q' M' ?7 H; C - }
# g4 j+ q# m1 B
6 U( f# h, f) F3 R: q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 n4 S2 h1 X2 \* B" ^5 N
- if (cache.containsKey(identifier)) { ~1 V/ }3 n$ e( u+ c; f. i, b+ V) y2 Y
- return cache.get(identifier);! R6 O9 H$ S' Y8 e U/ y* f
- } else {
9 e* K+ V9 z& Q5 ~" A+ m$ x7 J - final RenderType renderLayer = supplier.get();
( g2 | V: D# n1 z6 u7 C% ^; Z; F: _ - cache.put(identifier, renderLayer);$ p- o" {5 B# L. O5 ~* u# i! x
- return renderLayer;
$ D& W0 m! r2 o \# `. |& e6 s W# \ - }
, G; y& G" e2 M# e - }
" S, [1 ?1 W! l - }
复制代码 |
|