|
|
" z5 U" O% M2 Q7 [/ M9 f$ ~0 X行,这个怎么样6 x6 [+ r l: ^4 o
- package com.xhg78999.mtrfac.render;
( W% C% m8 P' I. O" z
; g% C' D* Q+ i1 i: J8 \- import com.mojang.blaze3d.vertex.PoseStack;; k( s5 Q0 A8 H; M% n9 z
- import com.mojang.blaze3d.vertex.VertexConsumer;6 R% C2 a. d. P: p
- import net.minecraft.client.renderer.RenderType;
$ y6 ]4 i0 j: Z1 u B; H2 d) W - import net.minecraft.resources.ResourceLocation;
) @" Q2 `. J3 v) ^
# Z# O8 Q: W W2 G- import java.util.*;
K/ v9 K+ v$ \! D. M
' ~- ~' b- `4 a- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 j7 z. H) q: z- M0 g7 |2 ]+ U
8 y9 J% n1 |, R2 K- H0 }- public class LineRender{4 A2 I' `% _( p; J
- private final PoseStack pose;
+ u t+ \3 u8 `# E" F - private final MultiBufferSource source;
2 n6 g$ J6 j7 u9 z0 ~. R9 Z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) J3 E5 J. Y ^1 { - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 \: v5 D" h8 T2 ?% Y9 ~; O
- : t, p3 ? u% B+ Z7 Y: h9 I
- - P* f1 V' \8 l8 @; b) g3 i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) {3 t5 Y& f" N1 [5 q# X- Q7 \' | - if(x1 == x2 && y1 == y2 && z1 == z2){
7 ~% a/ i* C& ~, A - return;
( P$ e9 E4 o; t; z: y4 S - }( N. ` y9 x I' R' ?9 D9 O+ u; @
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){3 q; i4 F. C2 G C, @
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 J! z" S4 P" e# B& f - }
8 Q: G- r& ]$ X3 U/ a7 @ - pose.pushPose();5 z) A# C) B u/ J; T8 F) }; F& a7 K
- final int newLight = convertLight(6);
9 E/ f( h% t0 B t. H# m4 i - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 W! x4 _+ L& B) [9 e
- final float lineHeightSmall = (y2 - y1);
! O( B8 x+ |0 } - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: r7 ~( M9 Z) n7 ~. h) K6 i - pose.popPose();
8 C1 X* O! t4 t( W4 i( X) e - }* a ?" b$ g! e+ `4 q8 d4 u
- % x- V4 h5 l9 X" G7 _
- private RenderType getLayers(String texture, int light) {
, `3 l4 w# n0 h; p# O - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 Q, W/ z7 J0 l
- }
: B: ^2 l2 y' y - $ d H. [4 t2 K3 I
- private RenderType getLightTexture(ResourceLocation texture) {7 G6 z7 {# v( h7 v" ^6 b3 Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 o9 S# A$ q- R! n+ ]/ [
- }1 w I L) I8 j! A/ |0 u$ ]" {1 v
j$ P2 r# I4 |4 T; F- private RenderType getTexture(ResourceLocation texture) {
+ L- A% y7 {3 h) k- q) B - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 Q8 f8 S7 I3 A! e, r7 l; s, S: S - }
# Y3 G% S7 u* g$ I+ B5 ]
; y5 `8 a0 c1 m ^2 P; [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 H; w. D$ p' z6 O$ z0 T9 k- \
- if (cache.containsKey(identifier)) {
$ h0 X1 z1 y! ` - return cache.get(identifier);/ P' {8 m8 k6 q4 h% J# p0 Q( X
- } else {
' ?1 J0 l% ~# f! r - final RenderType renderLayer = supplier.get();2 j0 c4 M, u; J! |9 {0 B
- cache.put(identifier, renderLayer);
- W; V( ^% _% t' w3 P5 a - return renderLayer;
1 x! _$ s0 k; N, N5 _ s0 S+ D0 `6 Q - }7 s# k6 B2 Z1 v- v
- }
2 g& d7 B8 ]. t8 ?1 n$ X! N7 ~ - }
复制代码 |
|