|
|
! a: s P& x u2 v" H行,这个怎么样% B% Z- R. d; [1 o
- package com.xhg78999.mtrfac.render;* }: r, F" O$ @* v0 v% r. a! F
: L0 L u* k& }. {* b- import com.mojang.blaze3d.vertex.PoseStack;
' v6 }: r9 D/ w% F6 b+ Y - import com.mojang.blaze3d.vertex.VertexConsumer;4 a, ]9 v5 ]( L2 F) s) D0 g5 \6 G1 Y
- import net.minecraft.client.renderer.RenderType;- p/ E( Z T% V. s+ U8 y
- import net.minecraft.resources.ResourceLocation;9 @8 X% E0 @' a5 F! ~3 U( Y
- , p( N; U3 m4 `' D( `; L6 z$ w2 m
- import java.util.*;
4 b8 f5 \5 `# }& k - # ?* T7 a1 O0 S
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 a# C! k' J9 s6 b' p) R
6 u+ {- n3 g$ q9 L& W8 z6 j0 ^, \- public class LineRender{: H, D8 D1 t0 w7 v0 m( x
- private final PoseStack pose;( q3 g9 D* J0 \' e0 r8 J5 J
- private final MultiBufferSource source;
% D# w: C, w' r+ T/ c - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 Y+ `5 ~* g) V5 j2 B6 h
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 g. H$ m/ Y! d/ o, F2 ]
4 ~1 b: x. i. d/ }9 u ^3 U
# B1 ~- M H: [) R- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- B; o+ i% I0 p& @# ?+ f - if(x1 == x2 && y1 == y2 && z1 == z2){
/ O) C1 y1 l0 U+ p4 \; F2 v - return;: M& X5 P; s6 v/ G7 t" X5 B; a
- }* V3 @" I; Y. T O% P' c2 \9 ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( {' Z6 L( _& n2 T
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 ~5 Z$ N* g! z; v2 t3 \7 f) d - }
/ n, `) s7 O1 P, F# @ - pose.pushPose();: |! e# [7 O- A
- final int newLight = convertLight(6);* e! L. L4 B7 a8 g! v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ J0 S# l x7 y - final float lineHeightSmall = (y2 - y1);
# R( q# R" M& t7 _( U - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);' \. f$ I- [+ z6 i4 E5 P* N0 R; E% U
- pose.popPose();
. @5 R, t( f# v - }
' Z6 Q# i; w3 [/ \) f( l- K - : o: @0 p0 K) k+ I/ x, z' ^
- private RenderType getLayers(String texture, int light) {: w0 [% {/ w0 Q* p3 `6 h% H- T7 p' N( U
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
2 e/ q1 a& _: @. L - }7 B+ H% S' o! E% }! ]' ]
- ' Q3 b/ V z& v1 F; L# T4 X0 P, z
- private RenderType getLightTexture(ResourceLocation texture) {6 T- Q# n" J; K
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! f: ^9 l) m$ J7 W/ H6 `: a3 P
- }
3 f/ e$ r1 s( ]9 h# L) P - 9 w, C9 \" \1 k# P) O4 K: Q# `
- private RenderType getTexture(ResourceLocation texture) {4 Y0 w2 x* U' ]! R
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 K# ]" c2 d6 u! [6 `9 j t( ^% E3 b
- }. e E) m1 p1 H' d2 ^9 ]( K4 K& j
7 t8 W* @2 Y( `" _# v$ H% `- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {. O8 d2 Z, a$ P' v [# B/ m! U
- if (cache.containsKey(identifier)) {
6 T: Y4 W0 f0 M& n! d: \8 Z - return cache.get(identifier);
! M5 X1 j; {( R - } else {
0 L. y3 x' C) o' A9 Q* D3 y - final RenderType renderLayer = supplier.get();7 P" n. Y( M. R) `
- cache.put(identifier, renderLayer);
6 ?1 i. ?1 R( q$ b" c - return renderLayer;0 R3 y3 p# V- Q+ h; I
- }: W: i" F$ m8 d5 k/ ~$ ^* p" P$ `( W. m) k
- }
) Q5 M- V: Y+ H: Z* V; R9 { - }
复制代码 |
|