|
|
0 m8 J% C4 ?7 f2 a* b
行,这个怎么样1 ?* i F% y# T4 c2 L* X; x
- package com.xhg78999.mtrfac.render; }+ _- `# h r1 G9 ?
: v8 W. l1 S; N- u/ r* ^1 n* z' {; I4 L- import com.mojang.blaze3d.vertex.PoseStack;
7 E' }4 L% {/ Y, E% Y - import com.mojang.blaze3d.vertex.VertexConsumer;
) P+ q' d8 }) ~5 P! ]6 t - import net.minecraft.client.renderer.RenderType;3 G+ I! F) b) l0 [" @# v
- import net.minecraft.resources.ResourceLocation;: u) g! I- S7 }6 O6 b
$ `0 B: {4 Q3 P7 t* r; f8 u- import java.util.*;
9 J; r% Q o! H& h8 P7 O6 y
: T# X4 Z7 {4 r7 L- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ s8 `+ c( l! \: x4 c9 P - 1 V$ p0 A3 P+ |/ Y
- public class LineRender{
( R! r6 y- f% [" b `2 w - private final PoseStack pose;, E" C& f, r6 |3 v! h( Q' C; u
- private final MultiBufferSource source;
( [7 L/ X6 v) h; k5 e2 m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, L1 i' u, C& t3 ~; h; j - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 Z1 i3 W2 g+ E5 ?* ^7 |
- " S* I5 p8 q! T" X5 J/ ~
- & h" b: h: y3 h/ R
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( d% h4 s8 a! j& }
- if(x1 == x2 && y1 == y2 && z1 == z2){
! ~: Y7 C- Y5 Y; e+ P# O! L - return;! B3 F I) j' [( H
- }# m0 M! f. \4 o" Q9 r
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 E' R ?. z( s$ w; I/ n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 @* i, l$ c9 \ t
- }
/ Z/ N+ E, W8 ? - pose.pushPose();
/ s( q; s1 l7 J4 C; S - final int newLight = convertLight(6);
( L. c% ?. Y8 Z5 R' ?$ A+ g - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( K1 K: x7 T2 R/ I. q - final float lineHeightSmall = (y2 - y1);
8 m7 u+ D( K, Z4 E) c4 J ~/ v$ j - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ L, f% b' _; b8 R0 D - pose.popPose();
/ b4 m0 E% W6 X- i/ B- b+ W9 } - }
1 u: p! o* @8 ]2 A4 }5 k6 m
, \; C3 R/ l% o7 C! p: @( k, [5 }- private RenderType getLayers(String texture, int light) {# ?9 c' {0 h. [" V0 c0 j1 @( t
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ L7 t* D: o- B8 {1 x S Y# |4 N
- }0 l, x5 S) G* \. M2 y; H1 ^# A( t
- 8 t( m" {9 a6 a8 n
- private RenderType getLightTexture(ResourceLocation texture) {, c0 B) E" Y Z( ?2 t# F* D
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; S6 A0 @% O- @( V
- } o" t% T2 |8 ~1 h
- ) q, B) C4 l1 ?5 g% W5 }
- private RenderType getTexture(ResourceLocation texture) {
# X6 J8 J0 h1 L) g - return this.cache(texture, () -> entityCutout(texture), CACHE_B);& G& j$ r% ^4 e( a- R
- }' `( G* C% E7 L. K* ~: P( [; A
' a O: j! L/ z8 t$ }0 } T$ a% G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, R3 }* X& d* v# a - if (cache.containsKey(identifier)) {# e! d9 r7 B+ g0 b# e% e' J+ j
- return cache.get(identifier);5 Y$ z' h! V! W9 r% u( V
- } else {
1 } |; w8 d1 v! p5 Y. b4 k( c( A - final RenderType renderLayer = supplier.get();$ T8 d! A9 X9 b% j
- cache.put(identifier, renderLayer);
, v. O( Q U, B% h3 X - return renderLayer;+ J1 p8 x3 `" R4 o+ `
- }
. |5 J, F' n! H& d, e. i - }3 B: W4 F% e# x) C' X
- }
复制代码 |
|