|
|
8 l6 j: F7 O4 f- P/ R! e行,这个怎么样( Z g: N, Y- B/ w" u/ i+ x
- package com.xhg78999.mtrfac.render;+ @, F" Q. X3 S
8 R9 y' k& T2 z7 }- import com.mojang.blaze3d.vertex.PoseStack;' W9 d: U2 b- A; K
- import com.mojang.blaze3d.vertex.VertexConsumer;; E& N$ i! ]8 G. H" d& F0 v
- import net.minecraft.client.renderer.RenderType;
& x& s. t$ u1 h2 j7 d+ s - import net.minecraft.resources.ResourceLocation;% ~ b5 } |! K0 ~% w0 @
- ( K; `) ^# H' X9 Q; i
- import java.util.*;+ c7 d6 _, }' \- a2 n6 G7 v. s
- 3 r& w( Z! c8 K+ z _
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 w! J) Z9 e% s' \6 H7 ~1 i+ ~ - ) s) O5 `# f. O. K' v% Y
- public class LineRender{: m7 F) e* F$ t
- private final PoseStack pose;! y% N1 s+ `9 K$ D9 n
- private final MultiBufferSource source;% g8 L, G o1 e6 ?8 ? R& y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 i8 f @( q; E9 H+ {1 J3 j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();3 \' q+ t& F0 l" n- N9 f
6 t: Y: ~+ D) Z0 O- 3 [4 h/ J' ^% C& Q- Y9 h9 g
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ C4 F+ d1 D% I0 K - if(x1 == x2 && y1 == y2 && z1 == z2){- M; ~8 a6 X. H
- return;
; _7 K9 @2 j) p9 i; \; k - }
6 b! X. R9 w1 H) q) U - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) Z1 h8 T) d5 W- ^) y% m' u s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. r8 T0 b* _0 H! M, M M7 [9 B
- }; p! I! N. W+ c+ y% e
- pose.pushPose();6 L! H- c* a. o. _# L* R1 y1 n
- final int newLight = convertLight(6);1 l( O; g o( H C; z) m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 p/ W5 B( t6 @. H - final float lineHeightSmall = (y2 - y1);: u# C; M( u# p
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% f' Y$ H! Q2 u+ j8 S
- pose.popPose();
) ~, ?9 \8 ^# Y* w6 \+ F - }
3 T9 e4 ~. }' K. ?; ~, z1 t" k
W6 E& z" X+ T u# @- private RenderType getLayers(String texture, int light) {
0 w# x2 X/ X& s9 M4 x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 b7 @; U, h4 x6 ]! Z% S& D1 l - }
4 }' U6 r: c# P7 m5 X - 2 q d& ~0 D: k3 i# R, y; Q
- private RenderType getLightTexture(ResourceLocation texture) {+ | n) V$ C1 A
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; S; Z! q( O8 N" k# r
- }. @* |2 B9 A: j
& g- x2 ?* L$ `- private RenderType getTexture(ResourceLocation texture) {- a/ t0 q! _2 K6 j. K, A' k1 N
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; E; c! U7 c! S4 A+ D: m - }- f: D/ X5 m) C+ m/ v3 J9 {
& Z$ k9 y7 |/ u$ D( X; S& a; O4 F- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 T n. M. k4 z' M3 X7 l, @
- if (cache.containsKey(identifier)) {! W( }0 k, u" |
- return cache.get(identifier);6 ?7 D1 S$ J3 Z0 O& g8 \# r
- } else {2 `6 }( G. b* L+ h3 j1 d7 q w+ i
- final RenderType renderLayer = supplier.get();9 O" s: T7 F- e% k, ^
- cache.put(identifier, renderLayer);
9 T9 U( ]3 A$ O+ `- w - return renderLayer;
4 w2 F9 X- t* e. e* u* E - }
3 b9 Z1 f+ N3 _% I% C. ^ - }5 @$ D0 j5 H- {1 L. n% z O" `
- }
复制代码 |
|