|
|
; W% A& b# Z& A+ c! H3 m+ d, D5 V2 Y. \行,这个怎么样% A/ c" D1 s$ k) \5 u/ o. U
- package com.xhg78999.mtrfac.render;
# A- W# A, T! C' e
. p, v" D0 A! ~2 w6 A- import com.mojang.blaze3d.vertex.PoseStack;$ l: q' M5 k# l" q5 K6 u3 O2 @
- import com.mojang.blaze3d.vertex.VertexConsumer;
4 Y- z. Y: R, b( U% @) c# F - import net.minecraft.client.renderer.RenderType;7 i7 e: [4 |5 @3 W; P6 i1 M
- import net.minecraft.resources.ResourceLocation;# r" I+ L& `% E6 J8 L
- 2 g e7 O6 x. @; ]
- import java.util.*;$ ]0 t# ~" C% _* H* E
- y% Q) f: m% I6 i' E. _
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
T6 Q5 J, H/ |( C# f' O - 9 |+ h/ o' e4 i" t: E6 M
- public class LineRender{5 n; H4 t( F+ }- Z7 A
- private final PoseStack pose;
* ?) y0 _4 t: N. t7 D' D! R - private final MultiBufferSource source; g' T7 Y9 | z" U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 V, r9 R7 e N& ~8 r - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 s) M+ Y' c# j; k b4 S0 H - ) A' ~- m- X3 O) [
" G7 y) |% B( r% x: ]$ h3 ?- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 C* }3 F9 Z" `+ i' P4 d
- if(x1 == x2 && y1 == y2 && z1 == z2){8 Q, u% F$ w5 G0 j4 m2 G
- return;# b2 _% j3 [4 L& c' A1 g4 `
- }0 k( L' t2 K6 e9 T1 m' q l' g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: F4 o" l0 m v" Q/ [ Q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 D4 g: ?7 n# I0 w
- }
9 @& n8 X6 o" o! e5 m - pose.pushPose();; y" o& J; e$ x, c0 `
- final int newLight = convertLight(6);
7 Z/ I) x& D" H0 J - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# B) r2 }$ |) a- N% \. @
- final float lineHeightSmall = (y2 - y1);0 N7 Z, B* \3 |
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 n2 B, `: @+ z; f4 I, j
- pose.popPose();
* l# N# u# `; u8 ?* C/ N - }
/ t% S- Z/ P8 Y" O$ T
- n6 Y/ d& x. }1 k+ F% x9 S- private RenderType getLayers(String texture, int light) {& o: _" J1 o$ P) i1 N4 Z h7 |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 i' L; T; p+ l8 r0 W - }
( ]+ w! s# H; b0 |1 A' S- @4 I. c
. g5 l7 w$ M8 z' a6 V( A0 \- private RenderType getLightTexture(ResourceLocation texture) {
' C$ D- [4 G) G4 ]7 W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. g5 v6 l& o1 p9 G9 a+ Z. h2 _ - }
# J- c! u0 G( o9 Q
8 E/ z8 T/ F0 f( K- private RenderType getTexture(ResourceLocation texture) {4 G: C; l- U& |- Z7 T x' O9 l9 j) ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ N' u% T3 X, x3 r0 o9 H& w - }
+ V( s$ }& ^3 X& Y* o! D - & \) [' ?1 f6 b j; Q$ V
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ @1 P& l* w5 U# x0 R - if (cache.containsKey(identifier)) {2 h2 z T" _) g$ N* w' V
- return cache.get(identifier);" o. d9 M6 j7 T1 I$ ]: p- x
- } else {* b9 n0 [; v2 Z) R* X+ M: g$ L- V
- final RenderType renderLayer = supplier.get();# s# V# t q7 T! w2 D
- cache.put(identifier, renderLayer);
9 ]! K( y; F; U1 G) H, M! C0 n, D/ U - return renderLayer;
* w! F, ], z8 Y# m- A } - }# E2 W# M$ r9 |7 n/ \4 I" r
- }4 i( N! Y3 p1 N
- }
复制代码 |
|