|
|
8 L! S' p- p2 v( B' x行,这个怎么样( \! [% ^7 V A# y. m
- package com.xhg78999.mtrfac.render;3 _/ j( j5 W, w( T7 ]- N8 F3 D
- & o% P' ^4 ?" T4 u. u7 Q
- import com.mojang.blaze3d.vertex.PoseStack;
3 D$ c- I ?8 W+ k1 _8 e4 @ - import com.mojang.blaze3d.vertex.VertexConsumer;
, z! N( ]0 [# }, t - import net.minecraft.client.renderer.RenderType;
1 E X3 {; a A- Z w - import net.minecraft.resources.ResourceLocation;
" o) F( e3 ~9 [, H. r0 t. t: ^ - $ B( ^: I6 E9 @5 U- V1 M' a7 b
- import java.util.*;! u( b3 o/ H. o! Q3 e
- ( w' K8 o, [% ~
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% y% A0 L; a$ t' C% F
- . [( o1 g+ k/ r# X- m j
- public class LineRender{
: V+ _5 T/ e1 W - private final PoseStack pose;* Z V( X i5 J6 ]" n+ ?1 R$ o
- private final MultiBufferSource source;* G2 v# \% u5 l! v% _3 E9 W" S( z, a
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 m5 L7 U# C6 D7 L( ]2 [ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 a+ }6 b' G' v
- " z1 L- E7 y+ P5 M
- * z7 k3 d/ C; P
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 ^+ ]$ s+ r5 @6 |$ c% H6 ^8 Z: e
- if(x1 == x2 && y1 == y2 && z1 == z2){+ T2 Y Z/ K- P; E
- return;0 Z! X6 F1 e6 s! L+ {
- }) ?# U# H1 V3 Z2 B( o+ M* V9 \
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" n& Q/ A/ C4 K3 [! P( o4 I" t
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! l% D% m0 ^- O- j- @ - }+ x) S( H7 [- h$ U; w& f
- pose.pushPose();
7 c$ l2 v" W, t" ? - final int newLight = convertLight(6);6 q4 H" W( T2 F( n6 p
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" J. B! h: [' K4 E9 j, l: i. }4 l, `
- final float lineHeightSmall = (y2 - y1);) f- N# }5 j' G, u$ {$ ?' J- s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
n5 Z2 l( G% c - pose.popPose();% f+ M) P |# }" _) n8 S, y. G
- }
! _9 t6 t2 W, a! R - 8 E& Q: y! t, y, g
- private RenderType getLayers(String texture, int light) {
3 Z# C+ W$ J% T# E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( T- W$ R' p' Z2 g9 O" n8 ~ - }
8 P' A1 ^ X( I4 M6 G' k - : ]- M# ~+ _. c" ]5 C/ x: ~
- private RenderType getLightTexture(ResourceLocation texture) {
) s/ ~4 d$ L5 i - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 d5 b' x5 t* f$ e7 E0 b
- }
. @) w) c% r) d2 W - 0 h: y9 {% g) z! s
- private RenderType getTexture(ResourceLocation texture) {
; K9 w5 S$ G. e# O3 Z! g2 n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 }1 @! o, u7 ~6 d5 G& Y. s! m4 B7 k
- }' w% ]- z2 {/ {4 k) b/ s5 [4 ~1 S1 ^
6 r7 J0 M) Z3 E* T! L8 T- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; W; N- J) `- O1 }
- if (cache.containsKey(identifier)) {
7 @$ L. g: K! `3 L - return cache.get(identifier);
5 Z$ k* R; H: M. } - } else {
: a S$ S! R O - final RenderType renderLayer = supplier.get();$ q2 T% i1 s+ V* Z
- cache.put(identifier, renderLayer);
+ z1 N, k P) S. ]% a - return renderLayer;
: G) G( Q9 q- t' |! @: S. g - }
- `3 P9 }7 t/ a - }& L; T# N3 y, V4 k
- }
复制代码 |
|