|
|
( [& Y! G* M; b% e7 j
行,这个怎么样
+ m* O E# `" c- package com.xhg78999.mtrfac.render;
6 n! y% Q0 @- e& @# w5 m: ], c - : w( w- l3 D* V8 G5 P$ q% F, b
- import com.mojang.blaze3d.vertex.PoseStack;
) I L: Y+ C3 W3 j1 Z m; ^ x d - import com.mojang.blaze3d.vertex.VertexConsumer;2 q6 A/ C% d4 E7 n8 p) g
- import net.minecraft.client.renderer.RenderType;
0 H. z% I8 O, T( [5 t3 M3 z - import net.minecraft.resources.ResourceLocation;( l7 G) T% m! X' p: N6 K5 x8 T% ~
- " G4 m6 S( Q; W* j4 p
- import java.util.*;# ?+ C$ J0 e3 j* t$ Z& _5 Q0 |6 s) G
2 X+ C6 j* c) }9 ?' t* |! W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
c9 E! S1 q+ N8 o8 _
+ B+ Z) j/ e% l8 i, \- public class LineRender{
* x% f9 [: [8 w8 C - private final PoseStack pose;
8 z: j. ~) ?3 g" n, d - private final MultiBufferSource source;" {9 j) T' C0 r& L' Z' L# A
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) `' t- T% d* r9 H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- d8 i$ b. q+ c# z: B
6 h# _" v' ~6 M2 T5 h% d) i
9 Y7 }0 [7 F) t* e- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 x; J# V$ u7 y+ H - if(x1 == x2 && y1 == y2 && z1 == z2){
4 l5 \; }& F- t8 g& u { - return;8 C% {8 | \! c4 F& d4 W5 \
- }9 J5 O* }5 q5 A. H( r E; Y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% H. w! h$ O9 [% P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! M# [6 w W1 ^) }- f U) c2 L } - }& c$ {7 E* e& O4 I( G
- pose.pushPose(); T& l- Q3 d& ^, ~
- final int newLight = convertLight(6);1 {5 ~2 b6 W& a; q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 _' N9 E5 W. M# @" ?- S8 h! W$ B
- final float lineHeightSmall = (y2 - y1);
/ D( W6 h7 P* o& ] - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& o+ M) E% f: q, p/ Z* c: G) @ E
- pose.popPose();2 ~ N7 X. c* H5 m0 R8 t$ V
- }" f+ Q+ k( |4 C( G7 L
* l, a: [( \( n( h- private RenderType getLayers(String texture, int light) {
- y) p' [* Q6 S$ ?0 W: b7 t - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! E) p8 k( Z% q4 u( Q
- }
- v% H" i. G. _ - ' Q2 U) Y" ~: |, g3 Q% ]7 r
- private RenderType getLightTexture(ResourceLocation texture) {/ P" [ g6 u2 q- u
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' x9 ^ r& a1 r% c T* [& B* e, O" j
- }7 D+ \& B; {. v) V
- ( r+ _% W! w& A$ S, \! G
- private RenderType getTexture(ResourceLocation texture) {
8 l0 p- e# J& o7 g9 ~/ p: X - return this.cache(texture, () -> entityCutout(texture), CACHE_B);" p' m, m1 U' o5 x1 ^5 H
- }
% q. l$ I% W5 H! u: y, f- D# q
4 b5 M) N0 p( A5 ~# Q0 J5 E5 @* e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ z8 F9 B3 T& L7 u& i - if (cache.containsKey(identifier)) {
N- v* [- K% V& h6 y9 L: x! N+ o - return cache.get(identifier);4 l+ x% M* D" {! u }/ B
- } else {
) r9 z# ?* x, H1 C0 f - final RenderType renderLayer = supplier.get();' p9 O; D; |# V; G
- cache.put(identifier, renderLayer);
+ c" d. E3 ?1 c, s9 }7 }$ v - return renderLayer;# ?! V3 w! b9 m( G$ P4 C% a
- }
4 j. n. {' k; G* C1 J( F" p - }* j F s) M4 b
- }
复制代码 |
|