|
|
1 [8 W. {3 w3 p" s0 d+ Z
行,这个怎么样
4 @+ I, n" o" M9 o0 ~- package com.xhg78999.mtrfac.render;
% M+ A& _" Y2 q& |/ s7 T- A% o1 ? - 3 Y+ P) h4 J" d0 q
- import com.mojang.blaze3d.vertex.PoseStack;& R- Q3 t( l G8 r
- import com.mojang.blaze3d.vertex.VertexConsumer;
9 G! t* y0 K' {1 A3 K1 g - import net.minecraft.client.renderer.RenderType;
& q5 J: i8 l& K& S9 I6 V3 C. j% i0 p - import net.minecraft.resources.ResourceLocation;) i9 M! L0 J) _1 C
7 P( `: P8 i6 {" W, E- import java.util.*;4 E0 I% o$ m( x8 Q0 b
) \0 x, W2 F# g) c' B- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( b- [5 S s( `: V# V& \
4 X7 X* h$ m* V& ~2 |- public class LineRender{
: m8 D' m& w( Y - private final PoseStack pose;+ G3 P1 {$ M0 w2 ?( i7 o
- private final MultiBufferSource source;
+ R8 N4 X' o) |% R& H( I) N - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ H2 l6 C; r% d7 K) x( t - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( m1 Q! l- A" g" Y - # N3 [/ H- }( I+ H+ K
, Y6 j3 b' \' ]1 r8 f- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 v5 P# U0 H0 a- `
- if(x1 == x2 && y1 == y2 && z1 == z2){2 t. R" G+ B. e
- return;
& m E( [/ n5 Y5 A7 Z& j5 ~% L; p4 u - }
7 |' @1 Z, W6 d1 x! X. M) z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" \. A7 ?: h* X8 k5 m" W3 r - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 G( @6 K) }$ W1 \, [ - }1 O$ P0 L* Z/ o
- pose.pushPose();
j- d2 w- y" [7 d! S - final int newLight = convertLight(6);8 }% Z# G. Z! q% n4 D2 D
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 A" T& E$ d4 K+ v% [: M - final float lineHeightSmall = (y2 - y1);
' p6 [ ~, K/ Y" j8 I2 D! W - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, h6 P* y# w9 v
- pose.popPose();9 J) W" t8 m# y7 F7 |
- }
- I2 m S$ e- U. F N) R, p
" ? }& _4 d% t K7 [' a* y- private RenderType getLayers(String texture, int light) {
+ u+ n. B! ?6 e, V8 y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& C) X8 N7 @; X+ U# L @% F$ v
- }
: t4 T1 `: h# }) V9 R3 S* ?
% h3 i/ S8 V& x9 q b! V) U- private RenderType getLightTexture(ResourceLocation texture) {1 l$ G! e9 q+ O
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& Y0 k& Q( O! ~" @0 s - }
3 J/ F$ Z' ? D% t) W4 ` c5 X* J - 5 A" c# J) n: L5 y/ I. a
- private RenderType getTexture(ResourceLocation texture) {
8 `. x$ K1 T6 j& j3 a' o7 O - return this.cache(texture, () -> entityCutout(texture), CACHE_B);' b, G% E6 c+ T7 Z* i
- }5 p, N Z8 I+ O- b/ P( j/ k
; J; k6 E# N" b3 v- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! H2 O. G5 m* ^. k- {
- if (cache.containsKey(identifier)) {. P' l# c: c( d* J; ?. `
- return cache.get(identifier);
9 o* c* N7 u6 ?1 r# g - } else {% ^6 w! C7 ^ E
- final RenderType renderLayer = supplier.get();
9 N1 s, X7 L1 `$ R* {! U5 _; H$ S% I - cache.put(identifier, renderLayer);' z" { {* }2 y: o; { U
- return renderLayer;) e" @3 f, J, C! w( E; B1 B) A
- }- j o' P6 z$ f3 h8 G
- }
5 `$ A+ b3 d: i& E - }
复制代码 |
|