|
|
: `. N+ z+ d9 Z, Z( h4 a8 W
行,这个怎么样* M4 p" H4 v2 [& E
- package com.xhg78999.mtrfac.render;
0 _/ i( [8 c4 T% x! M
! {7 u: _% N/ @( E) T, }- import com.mojang.blaze3d.vertex.PoseStack;
: K) R- P+ \7 u- u - import com.mojang.blaze3d.vertex.VertexConsumer;0 V' m" P1 p t; A9 k% w# C/ F
- import net.minecraft.client.renderer.RenderType;
2 b7 S; s+ r. D+ H - import net.minecraft.resources.ResourceLocation;
/ Y& ]( O, M2 r* e3 i
5 u% k7 a$ ]6 T: z" S; K9 G Y; _- import java.util.*;
`) N0 |8 n1 L. ?
9 @, P, p3 W" C2 x9 I) x- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# ~" A# b9 }; |# K, w' N; ~, b - " _% X/ k; {# h0 `: r# D3 n
- public class LineRender{5 `# l% l5 M7 q) u$ ~+ r! @. Y
- private final PoseStack pose;
1 K5 H2 E6 M. `3 `- c9 @: {' H - private final MultiBufferSource source;7 l% L5 L L% m
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# x0 I: o2 }5 Z' O - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. |: X' z- X& F* G
, o& N4 L; j2 p7 j0 _; Q1 A
; B$ i3 v. n5 Y. G" D8 E7 s% {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){" o! F! O+ B+ h8 R4 F* o
- if(x1 == x2 && y1 == y2 && z1 == z2){
+ p3 c+ u3 y% ]/ ?, e) \2 v; G3 X/ u - return;
. j- ~8 c+ }2 R - }
; ]2 [3 j5 Q" \+ }5 W0 _( J - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( m& z, y Q) P: ^1 y$ }* U. b- n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: n, V1 g5 \4 O: ~ - }( Z6 Y1 |- r+ U
- pose.pushPose();; _ _; b9 f* }$ d
- final int newLight = convertLight(6);# F* a2 [( [* L; G8 U; }
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));- r# p, G3 t, H$ s
- final float lineHeightSmall = (y2 - y1);
1 }9 I& I8 e# `$ Z. S- ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; F9 J& r, e( g, k, g) I
- pose.popPose();7 R6 N; e& X4 k/ Y4 b3 i* @: W- q
- }$ w, Z9 V( s& X/ I6 l" q
+ F$ Q b$ G) Y; c1 c D- private RenderType getLayers(String texture, int light) {1 n1 @ K# M- i% t. s. j
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' h0 l' q1 [" r - }
+ O Q) Q% d. j6 Q( V% J+ o - D5 e3 F% V* g
- private RenderType getLightTexture(ResourceLocation texture) {
: i* y- [( E& ^ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* o7 P- |) K6 \$ [. y - }0 e5 F h) ^1 m8 z
0 X9 R6 u3 _3 f" o j( d- private RenderType getTexture(ResourceLocation texture) {
* n' D: g% W. s, O7 p* Y8 N& D - return this.cache(texture, () -> entityCutout(texture), CACHE_B); Q+ {3 N0 B/ Q e4 A; B
- }# U1 A6 @/ V( l2 V: t
- 2 `! i$ g: N( `0 b' M, c6 b
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* L, [" b* R6 I. l" H! Z
- if (cache.containsKey(identifier)) {( y: u- X0 J; B' U& a" i
- return cache.get(identifier);
$ c1 n1 a6 P, |9 C+ t5 n2 Z7 c. [ - } else {4 y8 q8 b$ Y1 y8 \' g2 c
- final RenderType renderLayer = supplier.get();$ _% q1 N4 u: {$ |' K8 Y
- cache.put(identifier, renderLayer);; R* H4 k5 B8 N9 c+ r; T
- return renderLayer;' K$ n4 |8 i6 b: n* P
- }
4 c$ ^! B# ^$ c" l8 A3 p - }
! k7 m6 X/ q# c6 j& e0 c" | - }
复制代码 |
|