|
|
/ i& M" n5 Q2 K行,这个怎么样 d+ p0 o! c" j5 m
- package com.xhg78999.mtrfac.render;
" y8 w, x5 j% x6 d% \+ W( l7 Z - ( G& t3 u) `/ l& f0 \. ]3 ^
- import com.mojang.blaze3d.vertex.PoseStack;
9 [% b/ Q6 s3 b3 y5 F5 p$ [ - import com.mojang.blaze3d.vertex.VertexConsumer;
3 S8 K& l( N* r - import net.minecraft.client.renderer.RenderType;
4 |! V2 s! {+ h/ K& w+ p - import net.minecraft.resources.ResourceLocation;7 l9 [) K" e; j/ R
- 8 F* ^8 v; g# u/ t
- import java.util.*;$ V A1 L! D3 i9 w- I0 ]0 [& v* O
* [5 y4 l) R, H- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 y4 Q; H; ] J1 L8 F& }/ i: B; d - 8 F3 x2 u0 G9 I$ u1 a) [7 M
- public class LineRender{
) h1 g2 i6 I1 X7 R - private final PoseStack pose;
+ Q. r6 n1 U. {( ? - private final MultiBufferSource source;
2 o- z8 B6 ]7 c" A; r* R E2 }" s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();: t" Q' J, o. n2 m: G
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 j l, q4 j1 H M% E
- d6 N' C# l3 X9 N
7 |: B: ~! d% K1 y; |- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){) U# a: r3 L% g' W" l: o5 W
- if(x1 == x2 && y1 == y2 && z1 == z2){1 | r: B2 s" P0 ^7 H8 V" o
- return;
$ @ T4 Z2 o% Z3 i: R1 Y - }5 b1 _* i( d" K5 J6 D/ K% m' ]8 ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. B Z$ w# H0 v' ~ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
+ o y/ o) b6 f- i - }
) S+ t* L( y8 U: Y" A8 G - pose.pushPose();
7 l3 w9 l8 I0 \' Y1 l8 i - final int newLight = convertLight(6);% d% q- D& d8 j9 n! @' a
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- ~) _6 y z1 Z- C e! {" @ - final float lineHeightSmall = (y2 - y1);. r+ i. p, {: z) J/ Z' D ^8 x% N" D
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# k: Q0 @) T7 I$ r. | - pose.popPose();! r6 J' }' Y8 w
- }. O4 @5 @5 a N
& w, d1 ?5 M: ?5 {( U- private RenderType getLayers(String texture, int light) {
, p2 R2 c% M6 p& J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 O5 ]9 E6 V% r1 Q0 t* l - }
. V- \/ u9 G s$ k4 U. Q% v - , d9 C, ~. [; C$ z9 }; r j
- private RenderType getLightTexture(ResourceLocation texture) {" S- b5 \7 A/ H
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 n. S2 f+ S! E0 c - }
/ }6 v8 b$ ~9 ~- r |5 ^8 U: [ - - B4 |- X; W5 ]5 L/ j
- private RenderType getTexture(ResourceLocation texture) {
0 l9 E0 b- a, K2 w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);9 p4 n( @$ n- a) s5 B+ U
- }
$ I3 M2 A. h, d: c7 ^; Q - 8 X- r( _1 |) z& e$ _# i. s
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 [- x4 }$ ^1 t# l y. D - if (cache.containsKey(identifier)) {
+ E) f9 l& \) e: V) B3 V - return cache.get(identifier);/ K; A% f+ c) n. u/ A7 b
- } else {
0 x( P6 l. Z/ r3 B8 j - final RenderType renderLayer = supplier.get(); K8 k4 q" a2 R
- cache.put(identifier, renderLayer);
- C! ]+ U7 p* j; {. k2 S) P0 ~- Y) V - return renderLayer;
/ m: @4 m! E8 G4 R& U$ k - }% o5 D8 @4 }' a) h' x$ k2 n
- }% o8 p& O2 G, x' ^4 \$ d5 P
- }
复制代码 |
|