|
|
; N/ U1 [: ?7 X. ?% M+ o. E
行,这个怎么样6 D8 g+ L# x, F2 L* j
- package com.xhg78999.mtrfac.render;
# z3 l: {5 e6 M. J' n- a$ v8 \
/ K$ P+ T1 q7 J% u& z _- import com.mojang.blaze3d.vertex.PoseStack;. L( n% {; F+ n8 l/ d
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 s% ]2 a! A, Q: k% Z - import net.minecraft.client.renderer.RenderType;$ e8 B# Y: _% h7 C2 B% z: v' T
- import net.minecraft.resources.ResourceLocation;
1 C8 x( T+ r1 C" V, d7 \( [' [ - + R$ w, }6 V$ f/ a* n& F0 V. U
- import java.util.*;
, S% u3 `: w0 J B1 ?& `2 B, A3 } - : O! b# W: D8 w' d0 S3 j$ _+ W, J5 q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: Y Q( |5 N/ U! O8 ~* l
7 v. D: L! a- H; U- p) G: o; a- public class LineRender{: b; s' V1 \( [
- private final PoseStack pose;
1 _" H; u$ e5 h& J - private final MultiBufferSource source;# u# `+ c( a) s. I/ H, L
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" ~0 M9 G( r/ @. [4 I8 p8 N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 Q y7 f4 d' A. g) P9 k
- 0 L$ Z, b/ A/ ?/ E# ]/ s) V
- 1 c5 A& M& X, ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. u; i7 s7 M" Z- R# ], |' J - if(x1 == x2 && y1 == y2 && z1 == z2){
8 G8 `& ?3 n7 U# a! g - return; g) r: b/ z$ f$ H9 X
- }
) [1 J4 j8 }8 u$ }5 m; s1 E$ Q( g - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 X/ d% j1 n# H) n% _* o- U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
$ o; j( G8 e! R* A - } n. Z+ J) F% ~4 \3 S7 ^
- pose.pushPose();
7 C$ C' \: n% \8 O; H$ D* U - final int newLight = convertLight(6);1 p/ j) g0 M' n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 B- O( ] {, ~) m: Q- d0 d& P
- final float lineHeightSmall = (y2 - y1);0 R8 G3 a% k0 j/ l J
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ R5 c8 R+ Q+ _+ h' W( c - pose.popPose();
# A7 d" [4 U& T3 ^2 k+ C* x - }
! C0 N* N, z6 ^+ a0 X- j8 E+ A- P) {% \
1 U G( @9 s3 x4 S- private RenderType getLayers(String texture, int light) {* m m' n$ O0 e7 D6 U
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% W/ u' E6 O. A4 S$ H2 v
- }
) w' r0 m% L% T9 S7 d/ q - 5 F9 i# [( s9 Z6 |+ A
- private RenderType getLightTexture(ResourceLocation texture) {1 H% V. L/ U% d/ f
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' J* [# A8 W0 R3 \: { - }5 v. p! t+ N% f% z1 G% L
0 v% ~5 L' z! \" n7 F; l3 d- private RenderType getTexture(ResourceLocation texture) {
. W2 X2 v! E5 g' m6 W5 ~ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; w5 K1 l$ s( V$ Y7 l' d' J& A - }8 @: e6 h+ r& s% C4 X
4 d2 A! ^4 _. I( o. l+ Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 `/ j+ i! A3 C l) {
- if (cache.containsKey(identifier)) {. ^, I; |. D) { K0 C
- return cache.get(identifier);
) c: N' r& S4 J! r - } else {8 J: \+ C4 T8 j; P9 ]! d( H
- final RenderType renderLayer = supplier.get();( J$ d9 l; } ?% _! k
- cache.put(identifier, renderLayer);& v$ H# J& D' \
- return renderLayer;
E" A4 \$ Z3 S h - }
; R0 o/ V5 L' N/ C - }" T8 o) X/ T* ~4 C4 z3 K2 ]
- }
复制代码 |
|