|
|
7 ?7 }7 o8 R: ?7 A! @ z# P行,这个怎么样$ A; [( X1 I4 q! ~
- package com.xhg78999.mtrfac.render;. r1 B8 k% ?2 I/ ~3 D
7 E' C* \. g6 {. p; m; R5 a- import com.mojang.blaze3d.vertex.PoseStack;
) R/ H2 n4 b5 }- C( L - import com.mojang.blaze3d.vertex.VertexConsumer;
4 U3 I- C6 E9 h: d' y& \. L - import net.minecraft.client.renderer.RenderType;
% W2 I g" I+ A! X5 k - import net.minecraft.resources.ResourceLocation;/ Y9 v9 i2 S. B9 t! `9 ~+ Q
- 6 f' o! p0 W& v5 D' o0 B
- import java.util.*;
0 f' |7 O5 q8 Y6 C/ G9 s- n. r - 0 [5 C3 p. c# y: F/ l% V6 J
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; Z! o5 \4 J" x$ s
- & a* l; H# _6 X" t
- public class LineRender{
$ n4 I' F, ~0 V$ w C2 i. _* h - private final PoseStack pose;# G+ B( J0 K M( g
- private final MultiBufferSource source;/ e% K( O7 g9 c8 B% h+ G4 C
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ g/ g3 Y' M9 c% J* l; k
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! o* M. l2 R0 s9 ~
4 k3 G% Z3 |+ K1 w8 V0 s: H- - w( o) t0 k8 I" a7 g2 ]+ Y& N0 H5 u9 J
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 o* I! I$ |1 u a: t, m
- if(x1 == x2 && y1 == y2 && z1 == z2){6 P. |# D* s6 ]. q; v% |
- return;
: X; o6 A: Q' B' f$ _+ [: F - }
7 N( `9 `0 a* ]+ p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: ]: W! C- T7 k4 F7 T - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, l W* b8 d# ?5 p$ R* } - }: h# o) r* }$ i8 @& w2 p. M4 ]! I
- pose.pushPose();* i. d* L) \# G5 k3 e7 v; ~6 V6 J- D
- final int newLight = convertLight(6);% m7 h" D; [) U. i$ K1 Z; P, a
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 W$ W! c$ p4 \) w& D p, a8 k - final float lineHeightSmall = (y2 - y1);
2 K0 d7 {" _ k- f - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 q1 ^- I0 ]5 l3 E* w8 W% v
- pose.popPose();: d/ n0 d: ?6 V* e+ u
- }$ C- ^- U( H8 v) |
% L6 v* J, b% z$ y: R- private RenderType getLayers(String texture, int light) {
- p+ w% Z) b# [9 s5 C9 t7 l& T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( G; ^+ ]$ a# u% ~4 r - }3 n, p, l+ ~# C& ]
; a# v) S+ E4 v- private RenderType getLightTexture(ResourceLocation texture) {+ {/ \: J: s3 B: i. n6 p" K# m
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* _6 o4 i9 V* X c
- }6 k: x$ p& Q+ f" t0 K/ r" Q. Z# D( B
- 0 i2 d2 \4 K7 F1 h7 s; O% ~% y
- private RenderType getTexture(ResourceLocation texture) {
, b# ^) K$ a2 z+ j! t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* w" d( c7 g+ f* ~1 J8 R/ D9 q - }. b7 g: i0 g: O9 G3 J! L
- 0 N& t/ o+ c# k
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 ^1 ]. @+ \# i% N. u
- if (cache.containsKey(identifier)) {
7 `7 M/ S) }# O; @3 f( S - return cache.get(identifier);5 B) N& f; k) {$ i( E' ~' y
- } else {& |6 |3 F* N# V4 C8 d1 e/ N
- final RenderType renderLayer = supplier.get();; |: x3 O3 Z5 Z: c
- cache.put(identifier, renderLayer);
. `: I0 U7 z+ d7 f. \6 f - return renderLayer;
4 z6 O% A Z; w" C5 Y1 w - }+ j$ |# {( L8 V6 D
- }0 f2 h. ] |7 U) `
- }
复制代码 |
|