|
|
+ Y. k: B' J% B+ s8 l% \9 p" p& H/ o行,这个怎么样. a) o$ M# T( P- ~/ y3 s
- package com.xhg78999.mtrfac.render;
$ [9 X V% ^; Q5 a - - ^+ [0 t( V+ h+ M
- import com.mojang.blaze3d.vertex.PoseStack;
: p! @& G" z7 ?/ w3 f! F - import com.mojang.blaze3d.vertex.VertexConsumer;5 D+ P5 S8 K0 c+ U
- import net.minecraft.client.renderer.RenderType;7 c5 b# ?# [. E5 N C
- import net.minecraft.resources.ResourceLocation;7 u- R$ q2 F6 z: T3 I: G% w1 m. e
- y1 k) v: y1 N8 T% i- import java.util.*;+ u5 r+ o& b; a4 C2 K
" t; `8 `, w9 E1 B; j4 L- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
4 h) t. @. Q+ k- T8 x
$ A/ \" A& O2 d5 m6 v" @# m- public class LineRender{
2 ]( I7 K+ H" _% y# n% V+ o( @ - private final PoseStack pose;' ~# V$ O& p( @
- private final MultiBufferSource source;
/ `7 g' r' b: } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
S3 ~! |3 a# T4 r8 Y3 k5 M2 X - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' q N0 i3 e( Y) r7 A
/ X- c: B/ H4 O1 v- 7 U: C* k& |( e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 T6 y9 i1 \! H5 G0 s& W3 P& t
- if(x1 == x2 && y1 == y2 && z1 == z2){
_8 @4 s2 C8 k, C- _5 p - return;* F& c; t! f1 H. I t' v
- }
. W: k6 s7 Z$ D ?; | - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- J" }6 U: q* V% ]+ m* {, p
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 T9 H. A" a1 t6 Y6 D, y9 W2 N3 ~
- }
' z/ Q& C- g' a4 g/ a - pose.pushPose();+ s/ i2 u) L& H1 M0 @
- final int newLight = convertLight(6);1 L+ A, P; C: \* ?: I' m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 E1 {; b1 r( G! j
- final float lineHeightSmall = (y2 - y1);
: J: S- n! _4 J& w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; h" O [7 g2 H0 h6 g0 O, @
- pose.popPose();
9 d, e% ]) p( N5 P* F( L; n; G. C7 j - }7 O; L# Z6 c/ n; j
8 Z7 W9 u _$ q# ], [+ i z- private RenderType getLayers(String texture, int light) {( a+ R: N8 O- }
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' D+ ^ ^- u% q0 @: J4 ` - }
: Z6 ~' Q' D8 n1 B - ; A0 N# w- r# ~0 x# l6 m3 Y
- private RenderType getLightTexture(ResourceLocation texture) {4 t' l# \- t' ~" j7 f
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 H v2 ~/ [6 u, W9 l
- }
. `4 g" a! E; @; \3 B, d/ u- P - $ l: X, ]6 z; L7 X7 o2 x- W$ ^) z2 P
- private RenderType getTexture(ResourceLocation texture) {( E m) K' S+ {0 K3 p
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);% K( {" A5 n- ?" N4 G8 c) f+ q
- }7 o) v4 W% e }2 T3 ~
3 j, J# w- ?! F; Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: }. |* l0 M2 M' [ - if (cache.containsKey(identifier)) {7 g: L2 r5 t0 A1 @2 R+ q9 \& v1 g
- return cache.get(identifier);$ n) R+ t, {# j- V' t) I. N
- } else {0 x [) W7 {; e1 m
- final RenderType renderLayer = supplier.get();2 x6 [( X, g1 Q6 R r$ M
- cache.put(identifier, renderLayer);
5 t/ r0 G: u; M' @# P - return renderLayer;& r% o, e8 H+ P/ v
- }
P, y% G* x9 L6 x6 h - }( t3 T/ J7 A" y& w% a
- }
复制代码 |
|