|
|
2 w+ I( \8 q( W, p
行,这个怎么样
* x0 e# M. u- F8 d, @- package com.xhg78999.mtrfac.render;1 x$ }0 v; J6 J/ P0 z, r. ]
- % m% A$ D" v) p6 K$ b* o3 i
- import com.mojang.blaze3d.vertex.PoseStack;, V! b2 _' H: y7 H0 K* Z2 K
- import com.mojang.blaze3d.vertex.VertexConsumer;
4 F( {3 W$ d4 \. r' R. h - import net.minecraft.client.renderer.RenderType;; O. v! B; q" _6 l, E: ^
- import net.minecraft.resources.ResourceLocation;
. v$ D% I1 b( o! D+ c
! {5 [! L" y/ n- import java.util.*;1 P M( \8 h, N5 e7 B2 V3 M
- # @. n: |+ ^2 i. D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, l7 C5 ~ x! z! V- U% I$ v( E
" }5 U. u) N0 l. L0 g6 a, @ T- ?- public class LineRender{$ ~- w. o% @8 b7 k4 v
- private final PoseStack pose; R1 u- S$ R! d
- private final MultiBufferSource source;
+ b4 P7 k% [0 |3 l5 k0 s, n- }# } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 L# G- o, ?* @. R% o: [ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" g# N) r* g* i) v8 L
1 @4 {! V" M! g) I3 U7 k; b% K- 2 ], _+ a. J; P, g4 {9 _5 n: a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' p9 m- t( u) S; w- R2 J
- if(x1 == x2 && y1 == y2 && z1 == z2){# Z# ?5 l$ b; T( b P8 a
- return;- j( |: r h4 ~' W
- }% z6 J" D' Y9 z9 f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 J! j3 Y) T! }9 Z$ i- m
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; [5 X: y9 a" U% r! f2 N( R/ l
- }
: W2 O0 k1 q5 U4 S; g$ j - pose.pushPose();- T" a5 F$ V2 ^! c1 K
- final int newLight = convertLight(6);
$ T! \5 k* Z" ^4 Z, b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, [9 m. G+ @( ]2 q
- final float lineHeightSmall = (y2 - y1);
- O" @6 X( u) |; ~ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* T# d& M n. x
- pose.popPose();
) L9 I" }" C/ C& Q. K2 v - }$ B, w& b2 |8 Z) L6 T/ H5 }
: ?* O8 H o( @- private RenderType getLayers(String texture, int light) {
z4 b4 r& S E) e6 v; Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 D8 k. B. e/ c6 B) } - }
1 J0 \7 t' r# L, N: z
- g, T" ~1 T2 G3 p$ ^- private RenderType getLightTexture(ResourceLocation texture) {
2 @+ I7 @8 }5 e# \2 K* Y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* e3 \0 H) u' ]3 S - }
" @; E+ f* J8 P. t2 n0 e
1 q3 D0 T) g1 W, e4 F7 b3 g& w- private RenderType getTexture(ResourceLocation texture) {; t& H* T8 p* V: d9 W
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# C6 N) g" r0 A+ t" @
- }' g5 D( x; k+ }; _4 p' w$ ]
- # K; i5 P0 w" i8 C
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 f9 S* M( B/ R$ X9 U+ x- n7 P* m9 d( ]
- if (cache.containsKey(identifier)) {
# Y' I1 J; h' O - return cache.get(identifier);
4 I+ g% m+ }7 Q, I$ L% j# u - } else {2 c0 i" I& D0 M2 S/ Z6 F
- final RenderType renderLayer = supplier.get();
# q0 D# q& e: o2 M) o - cache.put(identifier, renderLayer);
$ W! r) e3 K+ H) T9 C( ~( A9 V - return renderLayer;
# s' ?) {9 S% Q2 d! f - } w6 F0 B' D9 J
- }% s+ j7 V5 `- k0 y3 p
- }
复制代码 |
|