|
|
1 `; Z' n/ X9 Z. e& C9 m4 c行,这个怎么样
5 i M. ^! z2 w- package com.xhg78999.mtrfac.render;
! T: ^6 h+ }) b4 W
! M- H- U2 a9 M1 ]8 a+ D5 \- import com.mojang.blaze3d.vertex.PoseStack;1 B$ H% Q1 T: m) F6 G
- import com.mojang.blaze3d.vertex.VertexConsumer;
$ Q' j0 H9 G) R l9 k% J7 | - import net.minecraft.client.renderer.RenderType;1 w6 v! U8 g M4 T
- import net.minecraft.resources.ResourceLocation;
8 [3 n( r U1 A0 g) t
# y2 W; P* p) x" }5 ]- import java.util.*;7 E5 a9 O8 f6 \1 J3 F
- * ^2 H* W; Q* c4 d% H9 Z/ y! G
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() ~- B- l+ Q& E1 p
- 0 N G# e. M8 u0 n- e- ]
- public class LineRender{# l: u9 E& E$ ?6 H. n5 k! X( @
- private final PoseStack pose;
7 H# Z+ r, x, i - private final MultiBufferSource source;$ S1 D. L" G9 H* i
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( } s7 g! z+ T, k: J2 s/ @+ r( B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% T) m& D, K( c) [/ C7 C8 l5 L5 Y# t
6 i9 e- a' F. Q. C3 }7 Q P7 Q6 c- 5 A* p0 h& e4 s* G! J$ v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* [* \" Y, G/ o* Y- H - if(x1 == x2 && y1 == y2 && z1 == z2){! e' y' S7 Q! P# m0 \
- return;3 R4 T* O5 O( p) Z1 w5 A! w- l
- }2 L0 d C# e/ d W" p3 ~1 o+ m
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% j6 z" V/ S6 l: V - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
( l; a1 Y+ P5 h( `8 H* T - }, X" H9 @3 G+ V2 U) U& V+ a
- pose.pushPose();6 l: w" H) B( h2 S6 Y! U
- final int newLight = convertLight(6);! I7 a( q. Q9 y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" b" t- [7 a7 V7 a9 b% j - final float lineHeightSmall = (y2 - y1); d7 J; {8 `" c1 }
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 D1 W! W# E9 v/ K& y' s% h
- pose.popPose();8 m+ H1 ^, G/ s
- }
+ b0 E) n- c7 b
/ Z! U0 y# y5 f) j/ T* h: ?- private RenderType getLayers(String texture, int light) {
4 R) l6 K' N8 F - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; N1 p. N. G) N8 r* x2 P - }$ X8 x; F* }0 S2 \' g# _* @. L
, O, b, x) K' k- private RenderType getLightTexture(ResourceLocation texture) {, ]) J* Q0 s2 }& E. Z; P( ? ~- w+ }
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( C, R b5 c. G$ U
- }
4 X0 q1 k( b' V3 G - 3 G- L% u( h% C8 v
- private RenderType getTexture(ResourceLocation texture) {7 Z3 e) |. L Y& z, y# B0 g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: \9 r K; y0 F. F- R6 O - } u' U, j- h! v' x
, T) Y; A. q6 z2 e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 P* y5 R. E! g u7 W0 Q3 O
- if (cache.containsKey(identifier)) {
# Y* q7 M' @2 T7 i$ T. D: I S7 f - return cache.get(identifier);
' E/ ]! ]1 L4 c) @ - } else {. ~- C7 w6 f& w/ V5 a) h c3 G
- final RenderType renderLayer = supplier.get();2 Q8 b( ^9 {/ K) O, c, G
- cache.put(identifier, renderLayer);
; s2 I- S" a: S4 W( T( p4 l - return renderLayer;! L1 u0 X% ~3 `3 n3 r7 I' r
- }4 ^. j0 n( n8 M% Y- h1 s
- }$ A% V; _& p- |3 L
- }
复制代码 |
|