|
|
# U+ w* P. ]" G5 L# F' ~3 L" y4 Z行,这个怎么样. U$ F: F- X! d p( e, u
- package com.xhg78999.mtrfac.render;2 W/ ?, j9 }8 j# H0 Y3 _3 R
- 5 o8 Q3 Z4 ], A
- import com.mojang.blaze3d.vertex.PoseStack;
/ O( r5 @! J* p - import com.mojang.blaze3d.vertex.VertexConsumer;7 _3 s" k( ?& G( x( M2 z
- import net.minecraft.client.renderer.RenderType;# o0 R1 |+ J, L
- import net.minecraft.resources.ResourceLocation;
( e. q* `- w8 @/ r7 D% u - / D8 R2 W! J' Y* \' O2 `; W' X0 r
- import java.util.*;
( i4 |; ]0 K7 S: g! F) T% z* \# W
( _/ J, W! J# f4 b/ B4 R+ }- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# R& ~# B7 L5 M1 P
- 9 c2 A2 t T3 i6 E# ?4 k: R/ j$ W
- public class LineRender{
" |) Q* w8 [; |4 C0 g - private final PoseStack pose;3 `( \& D7 o- G& G3 V8 ~
- private final MultiBufferSource source;
- [ f8 A$ x; u - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 {* K4 F' a W. H/ `* ]' f, p& ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); |8 W3 E# h) c( x( d
1 g+ g) _/ ~7 @0 ~, I- 0 {6 p8 D" z& J% b* k* n8 r
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 S! L5 k4 o R4 ] - if(x1 == x2 && y1 == y2 && z1 == z2){& {' k' i: w8 _& ?: k" e! a0 [( s
- return;
2 d; j# \8 @+ G7 x1 p9 C" G, A - }
% f2 k) X7 z7 B- y1 M# I - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, ]+ r0 W6 a6 E; Q6 f$ R) w3 T2 c3 b3 A
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' i" s% B& ^7 r7 U4 u# s
- }
; O5 @& l( G1 N. h) n - pose.pushPose();
% P/ f2 B& t& g7 l ^, P - final int newLight = convertLight(6);0 p8 p, T' N. ~6 \( e) d
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));3 K% k2 O0 Y9 P9 o- T
- final float lineHeightSmall = (y2 - y1);
) T, [) K7 x, g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ P/ P; o+ l. y: A
- pose.popPose();
" [3 M3 z! ^% Q! q: D - }
5 B$ z% u; O K/ Z - 8 H* J$ l# u. H4 V8 c
- private RenderType getLayers(String texture, int light) {
c3 h& } X( {0 P1 ~7 r$ } - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
X- W- R% a% I) S D/ w - }
5 E* `1 B! r* s3 y4 h - - X+ a) I+ S& Z" |; a( W, l+ Y
- private RenderType getLightTexture(ResourceLocation texture) {# x9 D2 r( o6 }7 q1 e
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* R% U W2 m+ A9 s - }
* U9 e; d5 Q3 y5 Q3 f4 M2 w2 S. m; r - ( e h1 Y$ ]- B# c* t9 T' k# _; k
- private RenderType getTexture(ResourceLocation texture) {$ q: K: h' b. L5 l' O
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. i L J s% n/ n& j - }
- m# U+ v- u: a0 l3 n$ j& q* e; T( p
" h3 R( |& H! k- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' T- w5 X( n& \$ {- h1 l
- if (cache.containsKey(identifier)) {
# B; m8 x x% k9 r% ?- _+ @ - return cache.get(identifier);
! X! d1 O: d& M& }9 O5 I* i - } else {+ S) E& o1 y, c; i0 {) v% N Y$ O$ Y
- final RenderType renderLayer = supplier.get();4 N W% i- p% v; d4 d) W0 b
- cache.put(identifier, renderLayer);
8 Q. K6 H8 ?3 G - return renderLayer;& B! r9 S. W' J4 O S9 q; b
- }
, N' e, Q5 m" w$ q* k4 }* H - }6 T3 L( V# ~. L6 `
- }
复制代码 |
|