|
|
# W5 S7 O2 @& _' Q `, }行,这个怎么样( g2 h; F8 X+ d8 n+ O* K
- package com.xhg78999.mtrfac.render;
" l4 `& g4 |0 w& ?% L; ~0 f4 [ - , Z) e9 c& i P5 Q8 H# }% e* G
- import com.mojang.blaze3d.vertex.PoseStack;
. I. ^/ Q7 M$ k. g7 ^ - import com.mojang.blaze3d.vertex.VertexConsumer; H# \0 B( r8 Z5 r
- import net.minecraft.client.renderer.RenderType;' _4 E0 S& |, R% s/ k0 ]. @
- import net.minecraft.resources.ResourceLocation;
8 ^% b$ I% w3 I& ]3 G" x7 i
. u8 m- M2 V" l) Z5 @, G- import java.util.*;! u+ }8 m N' W+ `; U% G3 T
- % l3 ^! s; t& k; E$ h* u6 P- R" f y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(9 u3 h1 @2 _" N. _) b0 M6 M
$ T4 W7 ?) ^! n, a$ N- public class LineRender{
7 m$ ~1 B( `$ C8 I J* G - private final PoseStack pose;( s0 f0 |+ |6 ^ K
- private final MultiBufferSource source;, l" S- u! M+ o$ b. l
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 P" P0 b1 _6 V" N7 u. h
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( j/ h4 ?1 w% P9 a; G- @( H
6 ~3 R3 u, R) T( d& T& h. d- 7 ?8 A0 d M) z8 ], o0 | ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; T9 W3 D, Q$ |( E7 ?
- if(x1 == x2 && y1 == y2 && z1 == z2){
: P) E8 r) k g2 a3 R1 c& S - return;4 s7 t5 ~2 r2 u9 W" j0 v
- }
- m, _& c4 @: ]0 Z7 |7 y) A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ X+ m# I7 s$ d# o* ^ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" O- \/ l* X' D2 X$ u- E" d
- }
1 G+ u/ J& H$ w - pose.pushPose();
6 u _9 k d) s' X/ v; O - final int newLight = convertLight(6);, b; X% |! _4 N, @) g( i
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 F4 f% x! v* s# y, o" ^" `. ]" w* a
- final float lineHeightSmall = (y2 - y1);
8 c- p& J. x) t4 ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) [( U7 A5 W. ^ - pose.popPose();
. A9 K# e9 }' i; S9 K5 r - } D9 U0 c, c% d; b4 s9 R0 N0 d* x
( X6 c% |6 Y; M* W' i- private RenderType getLayers(String texture, int light) {
[. L0 ^: N! @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ k L; _4 L, u+ _: A& v2 t
- }
# z: a5 d2 L& P% m4 P
& q5 X% G# B! t( R+ @- private RenderType getLightTexture(ResourceLocation texture) {
# u" N o4 b2 F. L3 t' Y7 J; p - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 r0 i0 `' E/ h; p
- }4 |2 Q2 V8 }, _. z3 D3 \9 c) G
- B/ U( ~9 q# k
- private RenderType getTexture(ResourceLocation texture) {# k8 R. j: Z0 P: k
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' q, ]. s z6 b( ]6 Q, \& | B
- }* W! P6 t; H& \3 F0 g! e1 s: u
- ~* { S' y+ M& k, W- C7 }& r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. U% {( u. g3 S; ~' o% o6 i9 i - if (cache.containsKey(identifier)) {
3 F, F: c) h; T/ K) M: B - return cache.get(identifier);; ~+ `7 S- b, G& L# ~; k% K8 W% t
- } else {1 |7 e/ s8 P) z, v3 W8 S+ i
- final RenderType renderLayer = supplier.get();1 v! D1 [9 G8 Z, m9 Q a3 W G
- cache.put(identifier, renderLayer);
+ s% n- m. G7 L) R. S4 t5 V5 b8 ] - return renderLayer;
1 V( y4 n; g& b - }
8 @( t6 K( P" r. m% j - }
2 i. C; ]2 Y4 V5 |$ V0 H - }
复制代码 |
|