|
|
4 c* {9 U: M; E6 L r% M b行,这个怎么样
7 }$ _$ V$ ^) z' v" z0 S- package com.xhg78999.mtrfac.render;
. n. j7 x1 g0 b& Z! m" A8 y/ Y - . _- y6 o" a8 s
- import com.mojang.blaze3d.vertex.PoseStack;
, ^" l5 }5 U2 ~* u: | - import com.mojang.blaze3d.vertex.VertexConsumer;" M) P) `4 m& D/ x$ r
- import net.minecraft.client.renderer.RenderType;. C: ]' `5 P+ ]( u7 n2 j
- import net.minecraft.resources.ResourceLocation;
U4 j" f5 k" Y, n W/ }6 Y2 F+ G
w/ |/ X& s' u; m- import java.util.*;; D# o+ U" r; X/ f+ p) t# n$ d1 C
- F# ]& {% K' M& c1 V4 H: O7 F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 r' q2 z0 C) z5 H" B; I% M3 m - ; ?, M* U: {0 g; W
- public class LineRender{1 u' `9 N5 u3 ` j( M% I$ S
- private final PoseStack pose;5 p. r0 g8 w9 X% \9 t, _" }$ V5 i
- private final MultiBufferSource source;
. z6 o% k' \8 r8 G - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
( t# _( [+ z' {# T/ e8 s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- p' B' E) x9 [2 U0 t+ I/ r, D7 p
; G* M3 J3 r! ~7 k5 v- 5 ]7 ^3 M h, f. E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! z( l2 B t& T0 z5 [
- if(x1 == x2 && y1 == y2 && z1 == z2){
4 U; d: w1 B# ?# P - return;6 E- o8 J6 G. g: d
- }
/ H& L3 t$ o1 g: |7 k - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% l5 O9 Y# R# E( ~7 \6 L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: d% k' z$ T7 w3 U/ h8 e - }
% m9 E: `. K; V9 ]) @ - pose.pushPose();
; M2 L6 K- b3 l) @* z3 z2 P - final int newLight = convertLight(6);
, i4 U- f' V! m- P. Q/ y9 | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" }6 i+ F C' H: a1 P! | - final float lineHeightSmall = (y2 - y1);0 t# M0 g$ G3 S0 t
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 G; e2 P1 o2 H) ]
- pose.popPose();" {& p. z4 _( [, G5 ]- N' g% \
- } `$ A) p; S w. J: h% E2 S% c0 E
8 m7 o5 ~' _7 O$ ?! D6 W- private RenderType getLayers(String texture, int light) {
3 P! T9 g+ B" q& o. Z( v1 u: g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& J; g6 h2 X9 {0 y# U# Y( o6 | - }' q ]- M: `* P# F: c) ?7 N5 U
8 O, S4 S8 T; G$ N0 ]- private RenderType getLightTexture(ResourceLocation texture) {
. r, }5 L" ]- Z$ E2 _, Y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& s5 Y J$ r$ X# a9 \
- }
% V! q( U( E* ?, X" X1 M5 q
! O! H- W9 _; {/ s. |: V9 f! D9 p- private RenderType getTexture(ResourceLocation texture) {
5 m3 |1 n* m7 s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);( o. B( J x7 i9 b8 I4 W
- }
. h; d* X5 T1 X$ x5 L7 t- y E - 2 L" q7 O/ e& e# M
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 L S, H! M0 I) e
- if (cache.containsKey(identifier)) {/ j3 u' R( c8 n3 ?2 `8 Z& j
- return cache.get(identifier);
1 I* h0 c3 J6 Q( @2 N7 t - } else {( a8 [5 V& ~; d" [
- final RenderType renderLayer = supplier.get();
& M5 \0 X7 m1 Q* D8 X8 i - cache.put(identifier, renderLayer);4 F) j$ N. [. @) O
- return renderLayer;( o! ?8 g+ `" [- U( z( {
- }8 r. v; V6 T3 [- V1 a
- }9 ?+ b! v1 A6 ]6 f
- }
复制代码 |
|