|
|
& t; K$ y$ |% d. ?行,这个怎么样
# f( q# e3 E" W# W% i8 i6 X& Y- package com.xhg78999.mtrfac.render;: F3 X; B6 S' i) c, N: f
, L) V! e- e+ `- import com.mojang.blaze3d.vertex.PoseStack;9 `3 i# n! Y; X/ \
- import com.mojang.blaze3d.vertex.VertexConsumer;
% Y6 N- A, d6 S+ C - import net.minecraft.client.renderer.RenderType;
1 j6 x5 y; L8 o7 b% J; {) @, C - import net.minecraft.resources.ResourceLocation;" O# {, h- J# b5 S
- * y! c; F) S6 L
- import java.util.*;
) ?9 ?4 p2 N" q7 h) L5 \4 E+ s - * X0 M( d3 Z$ H/ n
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 ^; W9 z0 L- j# v
$ }! W# E" i) [+ P$ e, v: l- public class LineRender{
( b4 x9 [/ l9 \5 T - private final PoseStack pose;, V" E+ _* i) Y S
- private final MultiBufferSource source;9 i8 K2 K0 d G& ]% d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ @. {- @; C) H3 ^( q$ ^
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( {6 e+ }& \" g" z3 T# ^. u
- ! q( o" v* F0 @4 k- C( y& p5 ~
- 7 p8 K+ g( v7 z! B! k3 E9 q- X% y7 K
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# L9 M6 x+ v$ c5 o - if(x1 == x2 && y1 == y2 && z1 == z2){0 K! K' ^9 V7 z5 z6 s& D5 s
- return;
' t( u# l' s' k& y: L, y - }
! K' B* W6 }6 I1 _3 p* c. K- F - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){& Q, z9 X v! l& M% p& i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! c2 g6 M) w8 B$ a# p4 @. X
- }) W: i7 r6 x% \ F9 S
- pose.pushPose();3 q# e. A/ I; l2 A/ k" p( }* X
- final int newLight = convertLight(6);; s4 c j# p d E% z" |6 i
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 e7 _& b: I9 | c* \ `( x% B, s: x - final float lineHeightSmall = (y2 - y1);
5 ]. M6 G, M: y/ O, D. g5 b - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" X. l/ t7 S' u& m* K - pose.popPose();5 m, I6 x- @+ s
- }% c- o1 F2 w- f& ~) @, f
" C8 |7 M2 [+ L. `- private RenderType getLayers(String texture, int light) {0 F0 f* V1 ]- H9 A
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) @. v$ W! \6 [% k! ?* i - }
6 v% l4 P; A- K C
; f/ y6 ]9 \/ {- private RenderType getLightTexture(ResourceLocation texture) {
4 a. d& m8 S9 V5 U- Z - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ W; ^0 w. v- G( i7 m
- }
/ }6 H) M) d( A8 ~3 r) S
) M% a7 L7 c" ~0 P& A- private RenderType getTexture(ResourceLocation texture) {
: J/ n4 B2 \" [' |6 R- V% C5 j - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. `2 E* ?6 y! \' S6 z - }
8 P8 ]# L) k1 F o9 q: @0 D - 8 y9 ^3 z+ S2 B8 l+ v8 \
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: F7 @+ B$ I$ N! Z( c$ q4 Q& V - if (cache.containsKey(identifier)) {
& M- s8 n$ |; t% g+ | - return cache.get(identifier);
! v+ U7 e5 `( m4 k - } else {
* G0 u" |1 |8 G8 Q8 `. x* q% Y - final RenderType renderLayer = supplier.get();
4 G5 w* V4 h! |# i# L$ J: I - cache.put(identifier, renderLayer);
, a; a2 m0 W9 c# h% F. Y - return renderLayer;
+ H8 b$ X! @# g5 G1 z6 D - }
( x5 q: F2 t! Z - }! C! m8 n* A2 j6 o! k4 d* j/ A
- }
复制代码 |
|