|
|
; e t Z1 L" I, q/ {) h
行,这个怎么样# l- p3 g/ G! l3 K
- package com.xhg78999.mtrfac.render;$ e z s' ^( g( L& ~
- . r" P5 F- L, U- E& u, ]
- import com.mojang.blaze3d.vertex.PoseStack;3 M# {! t( s0 q, ], e1 x- c- U
- import com.mojang.blaze3d.vertex.VertexConsumer;* y" G* E6 M/ x# y" T% S
- import net.minecraft.client.renderer.RenderType;
3 H4 G: _: O; J - import net.minecraft.resources.ResourceLocation;
5 X9 M3 V& S. {+ ^' |$ H1 }5 R - $ O8 \& `) o- Y8 J' L- t: \
- import java.util.*;6 n) L9 j1 _8 v1 }" L
- 0 o+ W- i9 R! |# d
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) G" G, f8 t, n T
7 \* q& v) \2 W- public class LineRender{
; }% ? s: F5 } e! |$ l3 S - private final PoseStack pose;. L) j, [0 X* q# n8 ?
- private final MultiBufferSource source;8 s/ i5 n3 S( z" Y; P- Y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, B8 F' \' P: I1 w' G6 j' s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. R: c" o: Y" A2 T7 j6 ^% v
- . |6 E4 s" C, @2 m& A
- 1 r- \' { O% q7 u
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- h$ F1 ?' j. }7 x
- if(x1 == x2 && y1 == y2 && z1 == z2){% v5 g: e3 N( H" Q" T, C' S7 D
- return;1 p. S" n1 ]3 ~3 a: F Y
- }1 N2 a' g$ {; u
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 J5 x* ]0 [4 {6 h) m) F( M - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- d. X% }9 n2 e+ D! \ - }
& N3 h+ j, }( c' I+ k. s# E - pose.pushPose();; J* E# H$ S/ X. S5 h% i$ e- D$ S
- final int newLight = convertLight(6);9 b- k0 v% }% m$ H+ ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' i* H$ z. h; V; r P
- final float lineHeightSmall = (y2 - y1);% f+ W/ b2 I$ @' N
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 t6 ^2 w, M. T/ P" ?7 [$ _9 J
- pose.popPose();
4 `$ s. v3 x/ E) @ - }
! n4 R, W3 `1 h _+ [' i6 U8 y
* a" Z3 l( R) F! f% ~& m- private RenderType getLayers(String texture, int light) {
1 P# A9 A; g2 A+ _2 Z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! M; R; r# K5 Z5 r- |3 J - }/ s2 M' i0 S+ y' i3 v: m9 F
5 u) E. A2 r# _ Y$ y( x( H- private RenderType getLightTexture(ResourceLocation texture) {
6 W) n" y0 p# ^8 w9 N/ l4 V6 U# D - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 S% G2 |* t! }" B
- }
( D/ K9 t( _. a* e( b6 ]9 g
# q( m& ?- b+ F- private RenderType getTexture(ResourceLocation texture) {0 j3 L$ I3 |$ E7 i4 `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ {' _* }: \! z9 J; O - }
( p# [4 w' J0 q6 y
5 A9 U! H( {0 t! L9 `- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) O' _7 x# f2 l9 Q% }* j
- if (cache.containsKey(identifier)) {
7 }& V3 j/ D0 a! } - return cache.get(identifier);
: p) d6 I1 A K3 W1 W! u/ ^* [ - } else {9 v5 D; h/ ~4 h: Y, d% H, y
- final RenderType renderLayer = supplier.get();
' a6 Y7 [' Z: T2 j- j4 m3 k - cache.put(identifier, renderLayer);& p7 c' ~1 |" t) U6 {1 b9 O
- return renderLayer;
$ d, \( D6 R2 X - }
( W/ G% z+ [- T8 m; L8 E- r7 Y - }
, n ?) f- E4 V# v; R - }
复制代码 |
|