|
|
# h0 |# v# n3 s$ [. J5 m- U
行,这个怎么样
5 N5 P7 e( x$ k4 T7 c* a5 S9 V- package com.xhg78999.mtrfac.render;' m2 C8 ^' O6 I0 B& b' I; h4 ?) l9 j
- 4 [; G# m; V: D* A) W% P
- import com.mojang.blaze3d.vertex.PoseStack;
' T* Q9 P0 n6 @+ ] - import com.mojang.blaze3d.vertex.VertexConsumer; p4 Q- j1 B p! E5 _3 Y
- import net.minecraft.client.renderer.RenderType;. ?0 a4 m s' f, o( e6 m- F
- import net.minecraft.resources.ResourceLocation;0 w2 G' P( B; t# f7 Z5 Y" i S
- ' T$ ]' ~4 X# V
- import java.util.*;
1 @( C1 M D/ P6 |0 w. P2 r
$ [( b% E: b! H" s% g* C7 O6 s2 t) b- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 C# U# o$ Y- R4 t1 Y
- 6 v; s3 g; o8 B: R
- public class LineRender{
8 B Y8 l/ H" x# Y0 @, O - private final PoseStack pose;
9 w3 j V0 v5 t% r - private final MultiBufferSource source;* w8 P4 p( X7 R8 V9 n" U" U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();, S- \7 I4 ^2 O5 S
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- U5 N4 g! V" G) M4 Z - . M, k1 j9 \% S- N+ X" O; J- s
9 i7 A) i* n* W. C, ?0 [- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 O2 {# \# n& i" _5 L3 ^. a
- if(x1 == x2 && y1 == y2 && z1 == z2){$ b. B) U* X( {' m0 h1 C
- return;
7 d; ?- j6 B6 w4 N0 g5 I! o - }
6 O% q* A, n$ q! X+ C9 F - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; r6 o3 [7 C& ?3 R - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% ]" G$ |8 o# N9 Y3 Q* q - }2 g3 q5 M/ R, Y1 ^
- pose.pushPose();
8 P$ ^5 {& `- c, Q; p8 M - final int newLight = convertLight(6);
! S9 H- w' X$ b" d: G1 Y - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% l( P$ P" w2 w M, o/ l* M8 Z0 Q
- final float lineHeightSmall = (y2 - y1);$ [7 t) K" P0 [' v& u# j+ l7 _
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 @7 \6 {0 y: g5 P( t/ z; a - pose.popPose();+ @ p" e; o, _
- }: h& I+ n! u' ]4 {% y9 I
5 {! v5 r) w7 H$ t- private RenderType getLayers(String texture, int light) {
$ p8 d9 F* o+ ?: `' Q - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" r& Z. n E3 q5 } t% s, D3 S - }
8 p" R1 X2 l! E4 r- D% j
" p3 y4 o+ v9 Q3 U# ~- private RenderType getLightTexture(ResourceLocation texture) {9 D2 X9 q5 }( I( ]; v
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ G7 q" g3 j+ M, g& T2 t6 o) {
- }; x. y8 f+ g0 b# X) ?2 q+ D
- % Y. U; {8 f$ W1 a- g4 z3 J& A
- private RenderType getTexture(ResourceLocation texture) {3 ^3 E' p! j/ ?& o9 B7 u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; n3 w% n# h& y
- }$ j3 a/ T5 d2 ~2 p4 S
- / X3 O' K: A4 ^; O3 L/ C( S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 A7 u5 v7 [% v0 P" K - if (cache.containsKey(identifier)) {
; s* h# i R1 a! D - return cache.get(identifier);$ S5 d: q" B% d1 T* J* P
- } else {: x; O5 J& F7 w; L. N2 L$ P( A: t9 |
- final RenderType renderLayer = supplier.get();
8 A$ A, b& d% Y7 H8 Q - cache.put(identifier, renderLayer);
r/ T& _: @' J - return renderLayer;
6 e: d4 K# a* \4 S3 } - }
- G8 u" [% t3 J - }* x3 r+ a% N! n# O$ q4 U
- }
复制代码 |
|