|
|
; P: Z7 j* {; A, }2 `8 l
行,这个怎么样
7 P2 y+ w# \( f6 }- {% t- package com.xhg78999.mtrfac.render;
) A9 I+ K1 A! G; S" | - , Y7 C# }0 R4 e( k; g* X
- import com.mojang.blaze3d.vertex.PoseStack;
! s% Y+ i5 V' s! Q - import com.mojang.blaze3d.vertex.VertexConsumer;+ ~* o/ O! N. d- y! I7 j7 I' ~) E
- import net.minecraft.client.renderer.RenderType;
. K6 ?2 C5 Y# t b# @ - import net.minecraft.resources.ResourceLocation;( U% ~$ o' _( E6 N6 {! o. q
- " [4 i/ b$ t! S2 Z9 G# d
- import java.util.*;! ^$ Q8 E: Q6 Q' U8 w7 _
- ( N' h. N: ~+ i, Z( Q% f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( Y+ `& L% Q, m% Q- \
+ f( B5 w+ X$ |& p% I' l4 n: v# U- public class LineRender{4 p/ s# S* \, G1 y$ m
- private final PoseStack pose;
8 S3 V) J* J7 e% g! m$ C - private final MultiBufferSource source;
: N, F# ]- p1 E) N9 _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 N; ?! x6 s8 l+ t: K' L
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();0 D6 v2 R6 k- m% D, o
9 t) M4 i% J. q% k8 O
" F- a2 w g( I2 X- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! Z2 N9 J6 ^9 p - if(x1 == x2 && y1 == y2 && z1 == z2){
8 @: e' M) v J/ ~ - return;
7 ~0 l% {3 V: E2 `2 |2 t' K - }
0 R! b' r5 ^( a) ]+ @. z% B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, S& A9 x; `$ { A
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' V8 | k4 G ~) d: u
- }
8 G5 W; ?" W2 U; m - pose.pushPose();
: Q) U1 \* R1 O5 F: g [ - final int newLight = convertLight(6);8 b' P6 k- K8 V N. G" w
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));! \/ f' b) V; g3 g# v
- final float lineHeightSmall = (y2 - y1);: G! r6 g v- o2 g+ y5 Z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- O4 m a0 K: h - pose.popPose();5 {7 ~: |# e ]
- }+ o' u) C* ^5 n5 y' E+ G. K
- 7 q) B$ Q+ l% F
- private RenderType getLayers(String texture, int light) {
) Z) `( ^) ~" ?# F* u; y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 o. F' L1 r! K+ W3 c( q# z - }& I( `( a5 R# X4 S3 ^
- 7 s0 a) e; u( U7 k/ ^; q: p
- private RenderType getLightTexture(ResourceLocation texture) {
3 w' Y' M% f6 i# m - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* U7 P. a) W2 ?" ]4 | - }5 t3 ~" w/ x6 D% m, [
- 8 Z" x* c: F9 z$ V/ R' H
- private RenderType getTexture(ResourceLocation texture) {
6 ?* l. R8 m- K+ x) [6 J - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' b5 G6 m5 l' \+ w' D0 [ - }# c, H+ l+ z/ y) H( g
- ' g2 i j1 U9 [: D
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ t4 o7 P' r, S9 ?0 V - if (cache.containsKey(identifier)) {8 s8 u5 N. C* _$ M* ], m
- return cache.get(identifier);( q; w6 Q2 b9 Z7 f/ E
- } else {
) l5 \* r- R3 s2 O; k4 Y4 ` - final RenderType renderLayer = supplier.get();2 A3 v+ I ~( m! s% T7 k7 ?" w
- cache.put(identifier, renderLayer);6 x, D6 K4 ~5 ~
- return renderLayer;
0 h, N+ E2 D+ E# B, P8 p/ | - }/ o+ [2 v; w, S+ R2 n
- }
/ ^1 h! h. l2 T! A( U& G - }
复制代码 |
|