|
|
4 F/ L; l; y1 r7 k1 B: ^行,这个怎么样
! C. I7 b9 x6 V1 V$ k% D/ h7 N- package com.xhg78999.mtrfac.render;
6 |1 J& h" t; ^, D
: K, [: D+ A3 e2 A) U1 B- import com.mojang.blaze3d.vertex.PoseStack;4 Q. w: U" N( @( f; S) t
- import com.mojang.blaze3d.vertex.VertexConsumer;
1 J. ~* ~6 ^ W( V2 h* e! L8 i - import net.minecraft.client.renderer.RenderType;
/ D; Y$ N6 _# \( r - import net.minecraft.resources.ResourceLocation;
' j* I2 u/ g' j |1 u9 q# Z. m - 5 t+ k* V& _3 ~3 F
- import java.util.*;
6 w* U( e( T* s1 k& J; [ - 7 l9 I' M0 w7 ]# J `; A
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( m8 ]+ x5 A n
- + O9 p1 L4 l; h9 o6 a9 T+ e- u
- public class LineRender{. k. W1 S- f+ J
- private final PoseStack pose;
% z! ~/ P% c' b5 Y" A/ m5 K$ B# P - private final MultiBufferSource source;8 |4 L7 I) G' {6 u# I
- private static final Map<String, RenderType> CACHE_A = new HashMap<>(); t8 P+ t8 ~8 q! z, h# u3 P$ R5 ~
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
Q, G+ n. t/ X; i# ~
! G) F6 o) t/ t$ f! O4 [- 9 c4 `( T/ X" V4 E& q8 h* ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# w! Y# z: W Z) _, T - if(x1 == x2 && y1 == y2 && z1 == z2){
: s: |; l8 Q. f# _9 N - return;' M/ J# m1 D0 X$ \, ]5 h. ?
- }, [1 b% p0 R' b9 C1 C! X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 d- K. {1 q" ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% S1 x' V3 Z- m0 o7 U9 V& g" ? - }+ S/ ]% J! i4 d/ B. \0 u% Z T
- pose.pushPose();! B5 T2 b0 B- I+ u
- final int newLight = convertLight(6);, x; s+ l& s; H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 r, r; E* X0 Z8 L - final float lineHeightSmall = (y2 - y1);
0 c( S/ A# C4 P7 _ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 I# S' d% M5 s$ J1 ^8 N) c - pose.popPose();' ]/ R0 i6 Y1 _: J d' e
- }6 G# o0 K, j4 T. a8 ^' W$ ]) ]$ p
- + |) t: `& ?9 F& W# u4 x$ p
- private RenderType getLayers(String texture, int light) {4 _4 I- W' [ d1 ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 `2 {6 {# Y0 K. e - }
, d% f) W0 c9 W: N `
' H' m0 { _& t# }7 ^. q! k$ F- private RenderType getLightTexture(ResourceLocation texture) {. ~7 \6 h7 M" R: d0 {! l* R& y4 B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' ^: G- O: |' d3 c; T. p/ J - }7 I- H2 @- D# t v
- c, e& K, a) Z
- private RenderType getTexture(ResourceLocation texture) {
' v. G# a3 o5 W: c" w) m - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 R2 P2 j) w" k2 w" M: d7 Q9 Q
- }: B- O$ q8 k7 i% `' t
- 9 m. d9 ^& c H
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) D# @; \& h4 E A' { Q
- if (cache.containsKey(identifier)) {
. {2 l" l3 A2 c. U, z; a3 R - return cache.get(identifier);7 l3 V# ~3 a9 x6 o5 X
- } else {
! S: ] d% ^" W2 F, v7 } U1 V - final RenderType renderLayer = supplier.get();
# C, H2 {% D/ d( i) ]" R - cache.put(identifier, renderLayer);
# s4 ?+ l3 i; n6 y - return renderLayer;
' |5 b$ Q6 o$ t c; h' V, p& G! R - }
6 h$ ~ P1 a3 a* c' T6 x, r3 D - }
! e& F4 m1 t% [9 N, T( b - }
复制代码 |
|