|
|
, X+ t* K) f) ?" p) y- z7 ?9 ~* ^
行,这个怎么样8 V/ `( w% v P- y$ B
- package com.xhg78999.mtrfac.render;# P# f0 U- U2 Z
- $ e' Y3 g& k7 t3 {( d" e
- import com.mojang.blaze3d.vertex.PoseStack;
' I) w/ W- Q) m; }8 Y) B- c9 @ - import com.mojang.blaze3d.vertex.VertexConsumer;
, r" b! t- a, Q1 E - import net.minecraft.client.renderer.RenderType;$ c6 g1 y, I0 o" {
- import net.minecraft.resources.ResourceLocation;/ K+ P7 E, Q( x
' f6 M+ ^4 y5 R7 n: h2 _- import java.util.*;2 ]; a3 [" _0 F5 y) ]% H
- 4 k) M& @0 m J: |2 M& u6 \. C, a
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& H- u: ]% L% ?8 i
5 H# o; i) h! E/ b0 o- X. B- public class LineRender{
3 _* j$ R9 _! q5 v" C - private final PoseStack pose;5 V" T/ H$ p4 K" `: p% [
- private final MultiBufferSource source;
* }2 R& o+ F" l; z5 m; e* {0 Q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();, p8 W- C0 v& A5 S
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& `6 Y ]9 s9 ]( j! e' V
- + ~, C) a" ^! ?
" w" }$ }' Z9 @+ g: Q- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){+ G& M: w/ l+ R# j
- if(x1 == x2 && y1 == y2 && z1 == z2){- Z( O, ~6 |+ a8 U7 s
- return;
" G) l& V2 ^( [ H - }5 Y: g3 U# A9 R$ \
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 @/ S, D+ `! V' e( Q/ k- @) `0 y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 b; x1 w9 f% F" p - }
9 P/ k$ K0 Z- U* ]; R7 L; K - pose.pushPose();
5 E7 Q- h2 K' T2 N( N ?$ I - final int newLight = convertLight(6);/ t' j2 g; C7 R4 M! p
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; P/ n0 y1 `" G W6 k - final float lineHeightSmall = (y2 - y1);* {" o) ^) ^* G: s; s5 o
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, d8 G c5 M4 B; u - pose.popPose();
: Y5 }9 W0 h9 K' ^; h" i5 ] - }$ O' [3 F6 G- r, j# F
9 f! ~1 P6 v2 O- private RenderType getLayers(String texture, int light) { }8 C; [5 G5 _) w3 L, A+ r; C5 `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ A6 z+ s( K" M9 n* I3 @0 w
- }
& q0 D ^4 V/ u& I0 W) D - 7 ?$ U4 V& Z4 x2 s4 X3 P% F* M
- private RenderType getLightTexture(ResourceLocation texture) {
& N& [1 o4 c h5 [/ E& e) B - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 Y/ \: J0 H* ~- C4 }0 o, J - }$ E+ G5 L6 E: t, ]. _
- 4 G. s# Q2 S8 H0 U" d
- private RenderType getTexture(ResourceLocation texture) {8 j# K7 U; \1 Z/ j8 n9 |" Q; {
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);) u3 \$ p* }/ `' z* ?8 n: x! l0 Q6 {3 R
- }/ l5 e1 t. n$ E6 a7 C8 t% X
i# k9 X* t1 _- U6 W- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* R( }8 O5 S7 i* W. \; X
- if (cache.containsKey(identifier)) {
( M3 X w1 _% _4 } - return cache.get(identifier);
. G+ r- R$ \' k, m4 e3 f. q7 L - } else {
+ d) [2 _( M. d; a* Z" o* J- Z4 p" k - final RenderType renderLayer = supplier.get(); V/ w) e8 f. G" o+ r
- cache.put(identifier, renderLayer);, ?9 i( x/ k$ R) Z+ N- i" i% K
- return renderLayer;
, f- ~" ^# }5 o, A, S - }) M0 G6 |4 E. h6 }1 R8 P/ A& Y
- }
R" g' O& v4 o9 o8 C, Q - }
复制代码 |
|