|
|
+ _5 a$ p, I" `$ a$ A4 z行,这个怎么样$ W8 C: m5 c @7 U4 {; L8 z
- package com.xhg78999.mtrfac.render;
3 Q6 n8 M+ i+ b) B" e' ?
' j% z- L8 I7 h/ T+ f- import com.mojang.blaze3d.vertex.PoseStack;7 w8 ~* H- Q9 b7 r
- import com.mojang.blaze3d.vertex.VertexConsumer;
! L* e: [* k) i& e7 U9 O5 L - import net.minecraft.client.renderer.RenderType;8 _. F' v4 C: C# U* n
- import net.minecraft.resources.ResourceLocation;
, o* q3 B0 ~% Y
. i& ~' ?9 ~" K) @- import java.util.*; c \$ s6 |1 M9 o' y4 R
* @* l) ~' K3 x8 |( q7 v1 N- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ G3 J% `! A2 t) h; {
1 U' i# ~; \( G& W* l( p4 [$ Z- public class LineRender{
l/ [; p4 W8 A! U& C - private final PoseStack pose;
& I8 U) I+ W' ^7 O& E g - private final MultiBufferSource source;
( L5 f4 _" f; [0 n3 s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 ~4 ^8 H8 R! ?6 C- }1 w! D - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 n9 Q! z. B% Y0 C# U
4 Z; S% X7 g1 H# n- - n0 {4 A+ S5 K( `" O/ A: V+ Z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* L8 q& T* T0 M - if(x1 == x2 && y1 == y2 && z1 == z2){& X: y+ ?8 ?7 B9 b- ]5 u4 o9 [; I
- return;8 @' N; z+ g7 l% J" ?- [# ?
- }% G0 J: l8 w- r5 s
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# U1 \# Q) W( H( i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( Q8 i" ?/ K% p9 _! Q
- }
: n6 q3 r4 P% w$ H0 `% I( m6 {6 Z - pose.pushPose();
# g: v, `% ^1 b9 J) R - final int newLight = convertLight(6);
4 N8 N& U% b: [, U) J$ V# Q4 l - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 O: L I Y8 G$ P$ D1 G w - final float lineHeightSmall = (y2 - y1);
@- S6 f! N4 \ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* `0 ?7 r/ N( k- a( ~
- pose.popPose();5 j3 J# z6 n/ E. k1 c( _
- }% _# v, V" A8 [; d
n+ a* t; S/ F# x; C4 e! e- private RenderType getLayers(String texture, int light) {, d/ s; P; I* u+ g" D6 J
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! J2 J9 @! G$ Z6 S
- }
- n6 c8 _$ g5 S - `9 W/ J7 T% @! |" H
- private RenderType getLightTexture(ResourceLocation texture) {
' N8 M) Y$ Y$ V2 T& K+ I - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. Z# r# C) w/ L
- }
3 R9 h: a2 s! f0 \
% }# _( b3 {" g6 s9 P( H- private RenderType getTexture(ResourceLocation texture) {4 P D3 M# G4 m/ F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! N4 B& w) H- X! I2 c& M* |
- }' n8 d( f3 [% x' I4 l( G2 C
8 m$ \- A+ r& v5 [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# ~+ ~$ v% Q9 Z; S* k9 \8 r
- if (cache.containsKey(identifier)) {7 D- l8 d. f" P
- return cache.get(identifier);) G% b& @0 R8 X; c% j2 Z" N
- } else {8 s* ?0 @% _3 X% {# t6 E0 t* V/ o6 {
- final RenderType renderLayer = supplier.get();
% g6 \5 U p* y1 N% }9 X# t - cache.put(identifier, renderLayer);
& z, p8 t2 L, k+ L: b - return renderLayer;
! X0 ?7 Q; V- k N! H' F% O - } u8 W, H- o w2 t1 b6 |, h+ d
- }
1 e* j: ^, y6 d3 i7 Z - }
复制代码 |
|