|
|
& A+ S. v1 X& {+ \5 [5 ]
行,这个怎么样
. I4 O% x' K& u7 [# ^- e3 A- package com.xhg78999.mtrfac.render;
/ I6 J- g/ M: i3 C. V0 s& G - # _' U0 K |3 m! p5 J. K
- import com.mojang.blaze3d.vertex.PoseStack;
, T# T4 i" V V: I% L - import com.mojang.blaze3d.vertex.VertexConsumer;
/ l' L* j% c, A( K - import net.minecraft.client.renderer.RenderType;4 i9 y! D6 T g: F7 S" f
- import net.minecraft.resources.ResourceLocation;! A" s9 _. m8 N1 J% S/ G
M) T5 W7 E" q/ {9 q" K( A8 r- import java.util.*;
/ z4 S' n8 E; J% Q - 3 `7 {5 v, M, G! h1 g9 ~6 R
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 U1 p/ p- E8 q9 r% g- l
! Q m; e2 r. o: [& P4 h9 m- public class LineRender{# @0 ^& r4 a1 S8 P1 o; P* x- ]: Q
- private final PoseStack pose;
: d/ [$ J( Z. u& Z& { - private final MultiBufferSource source; c0 X: q- |6 U$ H" S2 A9 Z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 ^& m2 z2 ?% ~/ d' ^) l
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ u/ k7 {! z1 F: X; e, Q) h( ^
, L9 n7 f9 [. O; }3 m+ e
6 g6 d- g! X, C: Q( K: V% i5 a( w4 @- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( ?$ |3 G) [2 r
- if(x1 == x2 && y1 == y2 && z1 == z2){0 l" V+ n# ?) P& m* c5 k; q6 s
- return;
! r3 ~1 `" M* m3 K; s% t - }
5 |- C" u! n( \ j4 B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. W+ j/ o6 d; B" b8 n4 s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* R$ |2 ?; |; f; E5 f - }
/ h/ f% H) T4 T2 [% E5 d' i - pose.pushPose();6 _8 ^8 P/ \) p: X4 y
- final int newLight = convertLight(6);6 A; o+ T2 J2 t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
M7 n" p7 J c3 [) }1 D& o - final float lineHeightSmall = (y2 - y1);
6 J9 h; M: N. h% `) T - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ u9 v1 U. C) R, i - pose.popPose();( s, ^& o" H8 t) h, C
- }. T' ]3 Y3 P9 {3 Y1 b; H' H# ~
- ( c7 F ?7 n/ v. d2 V1 N( d/ ?
- private RenderType getLayers(String texture, int light) {
R# G+ p+ @9 s) `, Z: u - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, J) W3 t3 ^( v
- }1 x+ D, x/ u( q& U8 x2 f* `& r
- C x {' v2 \! P- private RenderType getLightTexture(ResourceLocation texture) {
" C: X5 C2 r: \: ?1 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 \$ a# M, Z; \2 l5 t& J! P
- }
2 S5 K0 ]$ c# H8 D, h
& v1 m1 V1 A9 q/ P' [0 ]7 y- i- private RenderType getTexture(ResourceLocation texture) {" S+ u- ?' u( h
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 R _* d3 b+ l' {) @
- }
& W& _! b' W( t, @8 B
& r7 [# w3 Z0 o- L. i- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ i @. D! r2 A7 T$ C - if (cache.containsKey(identifier)) {3 t0 V l! s+ P8 z! e
- return cache.get(identifier);$ f+ O s- U4 N) E, j1 B
- } else {; x+ J5 U0 v# C2 N0 h8 D9 s
- final RenderType renderLayer = supplier.get();# T* a* c' t% Z p7 j7 m2 o: H( H
- cache.put(identifier, renderLayer);* u/ n1 O9 A# P+ f/ K2 U. v
- return renderLayer;
2 t* T; e4 p; l2 L" T: C- u - }
, v' n0 l4 ] |! C, w - }! J5 t/ T& C7 j1 B: F3 I( o2 q1 N) A
- }
复制代码 |
|