|
|
8 j- M. J/ u7 D) S
行,这个怎么样
; ^9 r: M* N: ]( y& s8 K S5 ^- package com.xhg78999.mtrfac.render;
4 E+ J, o% f( D# E
# `( ~* U- F! U& G! X- import com.mojang.blaze3d.vertex.PoseStack;3 [) w1 Q- q; H& w9 K
- import com.mojang.blaze3d.vertex.VertexConsumer;
. I: e& i ?* B" f - import net.minecraft.client.renderer.RenderType;
?7 b$ q6 P# i& h9 [+ T - import net.minecraft.resources.ResourceLocation;
& \6 {3 T- y& R8 C/ Q2 w
& B7 q$ C; g" U' d" P g0 ?: q* t- import java.util.*;! \5 F1 X @1 K3 O0 Q- Q. ~
- * J F' A* f1 c' K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. z6 R2 x) v | K$ T2 y
D' U4 D% m' b- public class LineRender{& |' @+ W0 N( {! J2 p; m7 g" g
- private final PoseStack pose;# ?5 G) u ^( j) B% k
- private final MultiBufferSource source;2 ^4 }( j* K3 D( I
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 t5 E4 \5 L- M3 r - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();0 Q7 ?0 [5 C0 }1 G7 W7 i
) `+ O* K+ p8 l x) A/ \- i- - W' o- ]8 R: t2 h1 O/ A3 w [
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 W7 `5 r0 X( X a - if(x1 == x2 && y1 == y2 && z1 == z2){' _5 k) f M0 M9 k* f9 t9 }- w& H
- return;
! g* ~: B$ r0 J* X - }* @# F# L+ g0 L+ p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, w, f7 y7 E6 b; u4 J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 }: t6 H9 y7 C4 I, t+ L2 |/ e; N
- }( x: f5 f9 j7 g3 Q# m1 R
- pose.pushPose();6 k! |, G0 N6 z( h% G5 T
- final int newLight = convertLight(6);
7 [$ ~ ]; g8 E3 @$ } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: D& I: i7 U! U/ n4 t - final float lineHeightSmall = (y2 - y1);, C7 q, k" _9 g a8 ]& w0 g
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) {( K! G' ~- t( w2 X" q. d5 t
- pose.popPose();. O3 [& t( g/ N' ~1 y+ z
- }& \3 R* p- N1 v7 @9 i! \! z
( E) |; l3 @2 e6 |2 _2 g9 L- private RenderType getLayers(String texture, int light) {
! c% G8 M5 |/ G. X - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ L3 r$ I, `4 A- x( P6 U' d - }7 p: Q* B' L) J, ~& B
; t# F1 A* r, T! ^4 v1 T) n- private RenderType getLightTexture(ResourceLocation texture) {
) P( R6 ?( H# l0 R0 ] - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 f* i" @3 u; e2 u# p: h - }
3 ?8 w/ H0 b( ^" w6 Y0 ~% ?
$ n, B4 _! C$ }1 O1 @- private RenderType getTexture(ResourceLocation texture) {* I. I/ t( L, z/ o3 D' F- N4 E1 T
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ j* P H8 e* K6 ~' [
- }% s/ _& c* Z J2 c2 h! I6 ?1 F
- : g ?8 C; }+ m7 `% @$ `
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 T- W' m7 H V! E' E
- if (cache.containsKey(identifier)) {
& |" ~) Z7 F+ ]/ m; \# ] - return cache.get(identifier);
* p/ K: x3 D- ?& X$ {* e8 Z0 w - } else {
3 L2 Z n+ w6 }9 [ - final RenderType renderLayer = supplier.get();( u; B% [# R5 u2 [
- cache.put(identifier, renderLayer);( g0 {1 ~/ i5 U/ q2 v
- return renderLayer;
: V: y" ?7 ?: _; y4 l+ Q$ d+ r - }
/ C4 d t1 R* K" d( @ Z - }8 L* V( m: G# _( B
- }
复制代码 |
|