|
|
' ?) [; w, s* I; @, p9 m行,这个怎么样* a, E* g) y" K% k- t1 v e6 u
- package com.xhg78999.mtrfac.render;
# K( @8 ^- s; q/ L& Y/ s. J4 B - / y" C5 P. W9 X2 [, r
- import com.mojang.blaze3d.vertex.PoseStack;
$ P) D Y1 G8 J$ M - import com.mojang.blaze3d.vertex.VertexConsumer;
9 _, I9 u' T* I+ O' w - import net.minecraft.client.renderer.RenderType;7 E/ @. v* J6 V; Z+ S
- import net.minecraft.resources.ResourceLocation;6 w g: q( _( A7 S' v
& p; E. \4 |; x `5 t8 m- import java.util.*;9 H+ O% M$ a, ?) g- v, x. E
- $ w" A$ [$ `, Y" ~
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( k$ }) G) i; ~
$ M g. H2 }( f5 w/ M- public class LineRender{0 t5 R# @1 G! q' m( b- L; b
- private final PoseStack pose;
9 W( h. b) N0 F1 I; j8 A# Z - private final MultiBufferSource source;/ e0 Q% D1 X( c( b8 y, C0 O
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! I7 t" G2 W. \. h/ S" v - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 `5 J/ l- w+ f/ U5 W
! l' `! G3 h* `5 i; Y# R- S
?+ P/ [# z; h$ n" s- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 W. N8 g; S2 i+ x
- if(x1 == x2 && y1 == y2 && z1 == z2){. D8 H' ^0 v/ i, c; h& [
- return;' |/ m9 c* Z2 w- i/ M0 Y2 Q8 q) a9 }7 g
- }' @# ^/ ?0 d: Q2 N- [
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 q5 O0 N9 j2 P# d. Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 F) J/ r }8 X2 i0 x' n - }
3 q2 C7 S: {& [ - pose.pushPose();
! z3 P9 q6 k; V* {6 u0 y - final int newLight = convertLight(6);
' M) ]3 j1 `1 q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 s; m( f# C1 W, T8 w' P - final float lineHeightSmall = (y2 - y1);
. X/ d$ o* ]2 b! @, o1 e - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 c- U6 n7 q' T' {, a6 J0 S - pose.popPose();
2 s1 u! @2 N, ]7 A) Z: W3 ^) l* F, A - }7 O' H& ]/ |1 R8 |/ n% h3 f
. O8 y7 j. B3 s- private RenderType getLayers(String texture, int light) {# @) e. f; T1 W [
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 k9 ~& m2 |- O) y7 K6 x9 u
- }
4 ^# E8 J) v* H - 5 P0 F, E/ P( |" u! t" M+ O
- private RenderType getLightTexture(ResourceLocation texture) {
" ], i" N, D8 S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* f. z3 B8 r# ?; E/ v" { - }
3 u4 i: `, F+ d! N
$ P' _# ^2 E: ]1 Z& l* X- private RenderType getTexture(ResourceLocation texture) {& F9 l. V6 t0 `! e( x. i- X, }
- return this.cache(texture, () -> entityCutout(texture), CACHE_B); P, c9 a3 I8 y1 E% | J
- }( ]5 [1 i. e. v) X$ T
* \" a3 r- q6 q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ I p, u0 t3 y
- if (cache.containsKey(identifier)) {
# h% B7 s( h3 ?& I - return cache.get(identifier);
; n$ f* U0 L5 L: P) y6 N) K9 Y - } else {
d @/ l" w5 u+ S0 M3 g' O - final RenderType renderLayer = supplier.get();5 o" j1 ~+ Y, Y; `6 l W
- cache.put(identifier, renderLayer);
' w ^) w; @* E5 F+ b+ D+ H - return renderLayer;* S# k o2 o7 T! C; N4 F
- }
+ `6 k! C0 H" r& z1 V; | - }7 c2 ^0 r' A4 L$ N r9 V3 W/ v8 |
- }
复制代码 |
|