|
|
! a! E, }0 N) c2 q行,这个怎么样
3 c% h3 q; A1 m( R0 p0 l% h; L' D- package com.xhg78999.mtrfac.render;8 C/ W& E1 k8 ]( Y5 L; |3 j
5 z3 Y) N+ s; D" t# V# O- import com.mojang.blaze3d.vertex.PoseStack;
& M4 `( E' ]' a' m - import com.mojang.blaze3d.vertex.VertexConsumer;' ]2 N2 N' v" r& @
- import net.minecraft.client.renderer.RenderType;
4 a2 o+ O/ {4 o - import net.minecraft.resources.ResourceLocation;
, c; L$ `( a$ Y' f/ _, E
1 F- ]9 d' j- S0 {- import java.util.*;
6 |( c7 i0 @0 J* A/ x" n# Z
" f" c+ N; m& A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. W; o3 |: q, V5 a, r2 T
% ^7 t3 M' e S7 k/ L4 V/ T1 v- public class LineRender{1 Z2 Q) F" [1 f# b! B
- private final PoseStack pose;4 J, `# u0 o4 g
- private final MultiBufferSource source; c) t Q, H4 X% i1 x8 I# g1 d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();! }; j) ]3 y; R9 B* K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();7 X |* y u# r* x
: s- {, K9 |' X- m- % K" C- Q+ m9 C) }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ e' T5 g: J* S0 I - if(x1 == x2 && y1 == y2 && z1 == z2){( B& F, U' E/ }) r4 \2 i$ D
- return;
4 o1 I0 \ E6 P2 ~1 ?6 b, V - }* Y0 e! J+ U7 b3 {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){4 S3 N; x0 s9 _ w& v
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, z) I+ S8 N: @% t3 b - }
z2 l( {9 W: ]3 [8 S7 N - pose.pushPose();. z9 V. T: v% e3 P; @5 G, U
- final int newLight = convertLight(6);
4 ^! ~+ I$ n/ K+ t0 T. Q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ |; ?( p, }: X$ x$ d) z
- final float lineHeightSmall = (y2 - y1);: w* P, m5 A1 {4 o6 w/ O$ M
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
6 }: O2 j; e5 K3 h4 l: y- q - pose.popPose();" c2 t, f1 A. i, ^" x
- }
) `( u& \ z" c# |1 y4 C* a( P - : _9 k$ ]9 ?; X) v: I, j( @! a
- private RenderType getLayers(String texture, int light) {
* _8 s; ^7 k& C7 _2 y7 c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 B) D. Z; f7 ]7 h6 A3 x' H4 W - }
1 Y! e& J1 G* ~) H. |' @' N+ h! o - . Z0 l- z1 M5 K! y3 Z
- private RenderType getLightTexture(ResourceLocation texture) {
+ b: P$ m. S' m" _: j7 x - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 m8 a7 i! r% v `1 f. ] - }3 a3 C. x9 y- e- y
( R/ X- \' `/ b8 B- {$ N- private RenderType getTexture(ResourceLocation texture) {- P, |: M7 f$ r7 t
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; H; A. i' r( F* \9 s5 ]
- }
' x \8 U3 V% u" b, x: H$ ] - 9 _- ~0 V/ z( w* i6 }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 \( o' i; `; h9 O
- if (cache.containsKey(identifier)) {
: b' M* h" L4 o% `6 z5 ^. N# f s - return cache.get(identifier);+ N# e/ k* i! ]* B1 w; V! ]! M
- } else {
) l7 d$ c, L; [" X" m' r - final RenderType renderLayer = supplier.get();$ \* {$ o. v: c6 U: i& W) K' }9 A
- cache.put(identifier, renderLayer);( J; [, P# @2 Y5 a. M$ X7 w4 K2 X
- return renderLayer;( a4 v/ I+ \- c; V# n) a
- }
% h) r$ x9 D5 X [" ~/ Z+ a - }& o, d: J) X% Z0 e
- }
复制代码 |
|