|
|
9 b9 [1 k2 @( ]2 n7 ^
行,这个怎么样& X2 g" |. Y. U3 {; p9 B
- package com.xhg78999.mtrfac.render;
p. Y/ d/ D& |) F( J
- w) j- s0 B; ~- T: B- import com.mojang.blaze3d.vertex.PoseStack;: y; ?6 ] U/ K8 P) M& t% d
- import com.mojang.blaze3d.vertex.VertexConsumer;
6 d* [5 V% w; [ - import net.minecraft.client.renderer.RenderType;$ }% R' `( Y+ D- u* X) L* a
- import net.minecraft.resources.ResourceLocation;, ^/ _; x6 Y9 f" |1 ^, c2 _9 f0 P
* G5 K& i- F/ x- import java.util.*;! ], y+ z! P( ~
- 6 e' [$ e( b; Y& V
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 ^. T" U0 j6 x( T# E - 5 c8 {! }/ C& ]' K
- public class LineRender{' ^7 L2 G5 v1 s" D; L9 E! P0 ?
- private final PoseStack pose;
5 U$ u+ D: g# [! P5 T; w5 \5 H2 | - private final MultiBufferSource source;
, E% t1 Q: J+ @+ ^6 t. g - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 |8 p- w; D) Q/ p9 a: h& j8 c - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' O& D5 }% ^+ d2 f( Z- J7 c% }( y
5 M" g7 }+ m6 [' x" {+ Z
7 Z% `% t9 v4 q7 T& n, e# z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# `: a! w# U8 \+ W# t8 p4 I9 B/ J0 A- _ - if(x1 == x2 && y1 == y2 && z1 == z2){ _) b! ~' D) t
- return;
2 H# G' N5 @2 u1 H w5 L - }
' h% H* j6 ]3 L5 v l9 j) i% v# a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% j! E+ R: z0 Y7 j; o$ M
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
}5 a2 l1 h, u; h - }
' s8 Q6 U* R, ]' X0 V - pose.pushPose();- O2 Z( e% n+ E% B8 f) M% j1 S6 L
- final int newLight = convertLight(6);
V; _+ R1 J* K* M - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* X$ ]+ t! o1 o2 B - final float lineHeightSmall = (y2 - y1);
, Q. n4 E$ g6 ^ i5 p- H& t - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 u5 t1 E6 H4 @# u9 u O6 b
- pose.popPose();/ _# j* I4 y( x( \. |) } u
- }
) I1 y4 T+ ?& @% Q2 P/ T( x - z7 y1 g2 _/ P6 s0 r0 y
- private RenderType getLayers(String texture, int light) {
3 [2 f; R. } r6 K8 k" r: T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));1 [ h1 _, J Y. @% p- C4 l
- }
4 y; j: e; e0 }4 L6 p, D; m+ ^7 r. }* e5 a
& n7 Z6 d8 s8 [9 p8 \ Y0 x M- private RenderType getLightTexture(ResourceLocation texture) {
8 k! e* c8 B% y( k# i! D4 y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# {3 O8 `7 ]5 X1 j0 q3 W" q% m8 T - }; A% V. Z+ i* y" p/ h
- ; j g! {5 w. u1 x5 L
- private RenderType getTexture(ResourceLocation texture) {
; g$ c8 S' ~* j( g - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 S/ ]- K: G0 K. P+ l4 T" Q - }
( U0 U, s: L \$ r; i* h - ~. R. S) @! g* \. n: {) h
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" i% [% o. Y: r% N- k3 z
- if (cache.containsKey(identifier)) {* O( ]2 l9 i+ O; a5 O9 A
- return cache.get(identifier);
- @+ p' i: q) z - } else {2 w* B% ~% q9 I. `5 Z; j+ X7 J! q
- final RenderType renderLayer = supplier.get();
% w& c8 v& S* b$ Q1 h - cache.put(identifier, renderLayer);- C# c- t1 ]" ^0 V3 _
- return renderLayer;
( r3 i" Y0 h3 X0 A# [% l$ J" R - }
$ k L0 Z, V3 ] i4 f$ K9 B. ~ - }% K6 X) v) ]2 t; [+ U4 C
- }
复制代码 |
|