|
|
' E# E- H5 L' v, J6 [3 v行,这个怎么样' S. T9 Q; i% ^) F: U* n) F
- package com.xhg78999.mtrfac.render;0 N) w5 ~( X: M" W5 `1 T# t
* ^5 y. ^* n& O) j- import com.mojang.blaze3d.vertex.PoseStack;# B& \6 i* P: ]4 n$ O+ f
- import com.mojang.blaze3d.vertex.VertexConsumer;
* F* O& m6 u" a* ? - import net.minecraft.client.renderer.RenderType;$ |' k# x o) F2 @9 i- o1 @
- import net.minecraft.resources.ResourceLocation;3 f) d- n, b2 F: v
7 Y f3 ?( e" J, Y, B( Z- import java.util.*;
9 r& d- I3 d+ O% h! L - s; ^0 d7 G" I6 D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 v4 C4 ~8 W4 }2 W
3 C) D/ i& y- H) T! E- h- public class LineRender{7 N( _ \. X' g0 r9 H
- private final PoseStack pose;
4 s" p# w$ c* L8 P$ Q9 ] - private final MultiBufferSource source;6 L. n) Q' z! u. }. c8 K
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 z; E8 |3 P/ q+ F* b* X8 c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! R) L5 N0 e- _1 ~; u8 k2 z% t* U8 r0 z* f - f. v) i, y* t% C f6 E
/ q! j$ n7 T) K' F( c0 {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: x! @' p H9 S# } - if(x1 == x2 && y1 == y2 && z1 == z2){' B# f7 Z: | ?: P5 J: f
- return;
. l( T5 P5 q I" o1 [/ g - }
" Y# K* e+ w1 Y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; I" `$ w# Z, r9 V$ r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) u0 z. ?6 P8 u: F8 X2 u+ Z
- }
- u6 g, T+ S" r+ p! A& O" T - pose.pushPose();2 M3 G* t" f" |- K+ P2 ` Y+ [$ p
- final int newLight = convertLight(6);3 Z; i6 G1 n7 w) f/ b6 q$ T9 u
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, _5 F4 `! e, u ? ^- Z7 O
- final float lineHeightSmall = (y2 - y1);
6 |, T4 y1 V+ j2 i1 q6 A1 r" A - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, h, m/ A/ W; E1 W) i! @# G v; q- _
- pose.popPose();
( j7 g' q2 W, @% T2 r: ]) H+ U# ^ - }
6 ^% k5 V1 `7 t/ ?$ h3 o/ x
7 S. B9 ~* E8 Q- private RenderType getLayers(String texture, int light) {$ I1 ^# A2 @, f$ k
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ C! N) F* W# y. D. N d1 D
- }% s2 w! Z! t8 P' d+ H' q
- i" Q+ I; }+ b! ~7 {- private RenderType getLightTexture(ResourceLocation texture) {' M4 Y/ i2 Z! v! J3 S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* z1 R- {- i+ Z: U - }
+ G# @9 x4 |4 H( D- b& M0 ~- |0 Q" U
6 H8 I( o& P) G9 D, J5 I% Q- private RenderType getTexture(ResourceLocation texture) {0 r: o% G* d* e: n, S0 R/ I" l( y' s. P4 x
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: @% v7 r& I- k& E* r2 V6 M - }9 z! w0 v, o4 u8 X: L+ J# x
7 S) J; t# N* o' O$ H8 L) M2 ?- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) Q X0 y8 s' Y# l- t7 q o
- if (cache.containsKey(identifier)) {
; p: Q! y$ e8 e7 e+ T. p - return cache.get(identifier);8 M9 }) j' ?' g
- } else {
O; w& F! F# ^8 G7 S - final RenderType renderLayer = supplier.get();
3 r+ o' u( M; j% I - cache.put(identifier, renderLayer);7 W" q' V. Y9 h' o' v; A# L( X4 y
- return renderLayer;
7 ]* E4 K5 a- e+ a: X6 v9 _0 O& e) ^8 W - }; Y( X1 n8 T) i$ X5 U0 W2 B @# f
- }* K- O) O6 X3 ^
- }
复制代码 |
|