|
|
& D- K' B7 `# j! B8 D行,这个怎么样
# _/ C3 ^4 Z8 ~) N" |" \- package com.xhg78999.mtrfac.render;
+ V+ o1 H" }4 y8 i3 B
3 `1 V# b( S% W% \8 i- import com.mojang.blaze3d.vertex.PoseStack;, \4 y, q( j# m: ^! A6 @
- import com.mojang.blaze3d.vertex.VertexConsumer;8 ?- N& k5 b; x& T6 ^
- import net.minecraft.client.renderer.RenderType;3 {, H; H$ k+ v* Y
- import net.minecraft.resources.ResourceLocation;
5 F# m( U! l+ [: B$ Z' R4 x; g
5 P+ G( u: f7 O- import java.util.*;
: |" O& c( D. r" [
. \' C* O8 A( C% f( \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ B: e0 t- J% C+ c
! u- d+ }6 f7 W7 f- public class LineRender{% d1 B+ m$ W2 H7 u( @+ L0 c* y) I; u
- private final PoseStack pose;" m; ?3 I# X9 K+ u
- private final MultiBufferSource source;
5 d; o, U/ [/ b M0 [ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 A Z4 D" w6 U( j8 @8 I' r8 Z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& c4 D( |5 X4 ^; R+ f3 u: J2 \8 G
- r) x! Y1 {+ z R0 A
6 K/ ?$ O. I3 s3 r1 ?, s% M9 p4 m+ X- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ A" M O4 A4 z4 O4 ~ O2 s* r
- if(x1 == x2 && y1 == y2 && z1 == z2){$ l) i& s/ I+ k1 d* F7 r2 j7 K
- return; j) k# [3 ~0 y! Z/ i. N G
- }
( \8 R! k: e/ }$ }4 |. O - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: \0 l: p4 I R7 ?; X# S: p5 C4 b - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 v( B- f B7 V, Y6 g/ `( ?1 x' W y - }/ g5 m- a/ \% o! b6 N# G
- pose.pushPose();* }: v) c C2 y5 }' G4 z( C
- final int newLight = convertLight(6);+ d* a2 z- A# N* j% ~' v% f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 T) M' g3 `# t! `
- final float lineHeightSmall = (y2 - y1);, J, s$ J/ o5 b6 W- b3 `
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: K& P' R ~( s, z! U5 o9 I( Z+ q - pose.popPose();
) j5 m3 D0 v3 r) E$ e - }# o* q* ^; M6 p1 `$ o$ a# W" V) C
- B0 K. A/ y) [- u+ N# ]$ h
- private RenderType getLayers(String texture, int light) {. @9 B1 B/ h2 O3 x- `+ k5 u
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
b& R% h# j Q1 e2 d( q r - }- W1 D/ o4 W* c! i3 G" }
' s. {3 {# D0 D4 I' U- private RenderType getLightTexture(ResourceLocation texture) {8 @% Z+ h( h+ i/ O) S2 l
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* W( u8 l$ a9 x+ H' H I7 x8 N - }' x. A& H! q' T% n
; y, K9 j( N3 \- private RenderType getTexture(ResourceLocation texture) {
. ]/ ]/ l3 C% ~; D* N+ ^6 H$ h/ V1 a, z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- X( \2 p$ B! |' [) t$ @5 A. k - }; c6 j; u. |- `: U
- ! x+ D& s" [" [4 r% A% e
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 A9 g/ C0 ^) p/ E7 n+ G) t6 v - if (cache.containsKey(identifier)) {
3 e6 t& ]- S3 e - return cache.get(identifier);
! _8 z7 G' G! g: ?5 v8 S' ~ - } else {/ b" N' c: C: } c7 n+ q, Y
- final RenderType renderLayer = supplier.get();
' h; D. v. y. i, S% j3 j - cache.put(identifier, renderLayer);
2 S' O9 j7 P1 e! p) j0 ? - return renderLayer;: p& [+ s8 Y n1 Y7 i- E
- }& A( m( V$ F5 ^! O' V7 P+ D! L
- }& o, x) a* l7 u8 K) `# |
- }
复制代码 |
|