|
|
- B6 L! P: H8 F5 ~/ y5 w8 v行,这个怎么样
+ B0 c" D# {. }3 Q9 m- package com.xhg78999.mtrfac.render;
. Y. E4 ?/ |0 p/ R1 [5 H; ?) f - 7 e7 [- L9 f3 m6 c( n) `/ A0 M
- import com.mojang.blaze3d.vertex.PoseStack;' \2 ]# x- x: [; p7 {
- import com.mojang.blaze3d.vertex.VertexConsumer;" P% _" Q5 \/ @8 m* p% M- u9 ^8 U* y
- import net.minecraft.client.renderer.RenderType;( v. P7 I5 G# s
- import net.minecraft.resources.ResourceLocation;
* O$ C, X: p+ \. K* _ - : g2 q+ H- z/ @6 L, F6 p3 W
- import java.util.*;* ?! }; [3 w2 y8 g, T9 X+ p, B
- + ?# Y( Q, K0 H+ T c, O4 v
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" v6 ]3 T! X) I' R# }8 \4 f - 3 `& n Y& r, D3 K/ \$ g. E
- public class LineRender{
' \0 F, z' a9 B( w e6 ], N+ n - private final PoseStack pose;' `0 e% q }" q4 f! n* k9 h* P# O
- private final MultiBufferSource source;
4 G4 o# S, x3 U3 W - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 w' i) h# Y. {' D r; Y - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: z; e$ g9 n( x. e - 9 n- Y4 E$ f4 v5 D
* ]* \9 J/ _$ l- r$ [- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% y' Q( `2 m9 [. W5 R! A- M! a
- if(x1 == x2 && y1 == y2 && z1 == z2){! T' h/ Y7 d5 Z& j5 N4 {7 ]
- return;% B0 l, k. D, t. _, F2 I
- }2 V; N" k5 f* A3 P# f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" \1 ]( l5 ]: p; D" Z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% N8 F7 E# d8 K - }: N/ u$ A. H2 Y T# J, l/ X; O
- pose.pushPose();
, _: ?" J3 Z6 c A: B6 x" | ? - final int newLight = convertLight(6);: B1 M1 [: n5 A) p* c' m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 R6 s! r# N4 f& {3 T- S: ~, P: w - final float lineHeightSmall = (y2 - y1);
0 W! u6 S0 {; k7 J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# e3 `( J7 `' T
- pose.popPose();& k( s8 A5 l" @% p7 \+ Q
- }( I4 C% f5 \( Q% c5 ^0 u0 x
4 K' Z0 C, ~$ C* l- private RenderType getLayers(String texture, int light) {
+ m3 N# o2 B) ]3 T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 X/ u# p' d2 W3 E& W# N3 Y - }/ C4 x t- X! X; Y6 U, \
- 4 r" {9 Q# Q, @) d+ f
- private RenderType getLightTexture(ResourceLocation texture) {4 x$ r: N9 I. C# J; F/ X* j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: ^! m4 w9 J% U. n
- }
: i* t$ b9 n; e- F, k- P5 Q - * b# _$ L9 @7 N8 ?$ }
- private RenderType getTexture(ResourceLocation texture) {& c* Q2 f& K% W2 J
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! ?2 I3 ]( v+ W% m0 s! m - }: N/ |2 D6 m3 R
- 5 J$ u0 [9 t0 K2 S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% v9 a# {! O8 X b- H* d$ M - if (cache.containsKey(identifier)) {2 ?9 ]6 G0 g5 w1 l+ `
- return cache.get(identifier);, E& t. c2 `5 Y2 ^* @9 j8 |: m
- } else {
2 U. w% k/ r0 v) n; k2 @ - final RenderType renderLayer = supplier.get();/ S7 l) g9 p0 a9 D- }/ z; f
- cache.put(identifier, renderLayer);
: W. N9 j/ @$ `0 H - return renderLayer;
0 m3 T6 n6 R! W# Q4 S( ], Q - }
8 R4 n( a: j5 ` X# k - } G! n$ U7 B {$ U( H+ J& J3 \
- }
复制代码 |
|