|
|
: V$ @; i/ R4 |2 \1 S4 x' `行,这个怎么样( r" \: Y |% ^ e
- package com.xhg78999.mtrfac.render;
% V5 u% D+ h3 V2 I( v' t# _ - 0 Z& Z3 k2 K, m% g5 Q/ | [
- import com.mojang.blaze3d.vertex.PoseStack;7 Z o. Y8 a4 f' v
- import com.mojang.blaze3d.vertex.VertexConsumer;/ {0 Y' @$ u D& J
- import net.minecraft.client.renderer.RenderType;
5 j, u& q$ ^/ c, N - import net.minecraft.resources.ResourceLocation;
( t- |# p G0 s" K9 D5 ^7 x
* w; [/ s* `4 h4 I" E6 J% [- import java.util.*;- p- e9 ]0 [ Y: D8 O
0 s# `# d& n2 t0 ~/ [- Y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 z6 P8 X) ^9 C9 C* _) ?2 u2 p+ X( f9 S' e
/ e; Y* y0 y4 |7 C' M3 o. h- public class LineRender{9 z' r! I) h" N; ^2 |$ g5 p$ a
- private final PoseStack pose;( q8 Z/ e7 q! c/ C1 T
- private final MultiBufferSource source;, I* l. D [/ k7 h5 c' w2 ~
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 C1 \$ v3 T. |. _8 `+ a9 s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% W6 t, g, t+ @- |
+ d6 J6 n R2 ?/ f
1 f2 R1 E7 t. k* h6 S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: x- w H0 t. c G, w - if(x1 == x2 && y1 == y2 && z1 == z2){
& U* A$ D& Z7 ~; j+ m3 h5 m - return;
e' _$ W. _0 B) ` - }" f' o3 ]1 t+ S* ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ A- {; z' N8 ^- o$ N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ C2 D; b8 |2 z1 ~ S7 U$ H, P
- }9 n2 `, R# W7 O3 q! Y
- pose.pushPose();+ z0 D+ I4 V: k: D% q% @" W
- final int newLight = convertLight(6);
. U! P3 k; E/ _/ u+ } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; b: O1 v+ C3 i - final float lineHeightSmall = (y2 - y1);3 e m! U8 }" }0 h/ V b% w/ x* f8 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# s; ~3 z( |4 f5 X' W+ a; K - pose.popPose();! s v0 {: X9 Q3 L: Y% M
- }+ s, j8 Y, T% m6 U2 u8 l
- N1 y# C$ e+ w) H0 K2 D: z: B- private RenderType getLayers(String texture, int light) {+ }9 S1 s0 p/ r' Z! p0 E! g
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 H! r3 V% [3 n8 B - }
% L. t- p. U S- {! v9 t5 K7 i7 n - 2 M6 D* r5 e" [9 O _
- private RenderType getLightTexture(ResourceLocation texture) {
! s3 R L8 p$ r. n0 I" s. R, p - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' v% F9 ?8 ^; I. B! ~5 Y1 C
- }
5 C+ T; `( x- p; W p: I
8 o7 y9 F& p" m: k- private RenderType getTexture(ResourceLocation texture) {. O' u5 ?, y5 ]. B: Z6 x0 \9 s# U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 `1 q' F C g: _
- }
! ]8 z& V# ?% R7 `/ N8 }8 k+ N
7 H$ x! G1 |! f) [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ r1 {8 d# m2 _* C+ T - if (cache.containsKey(identifier)) {% f; o" c2 ^; C6 F. ]8 f0 ^/ M
- return cache.get(identifier); F5 x3 F8 O, L- j. C# w- g9 q+ I
- } else {: q4 a$ V! K' [/ u! f0 y# s( [: p
- final RenderType renderLayer = supplier.get();
# N, i6 D( |$ } - cache.put(identifier, renderLayer);- `4 Q3 o( x2 W2 G9 ]
- return renderLayer;3 v" x; f* T' x0 R
- }" P, p" q. k) _3 G& _
- }( _& |# r& s' d" n& D
- }
复制代码 |
|