|
|
2 W$ @+ J7 Y( I4 P2 p- f
行,这个怎么样( v, ], R3 f: M& j1 }/ \
- package com.xhg78999.mtrfac.render;
. ?9 x4 @' h0 C% q) j$ ~5 r' G - 7 F4 a- A8 b$ C9 Q
- import com.mojang.blaze3d.vertex.PoseStack;) N$ J9 v+ l0 A5 w
- import com.mojang.blaze3d.vertex.VertexConsumer;
6 j& z- k8 ?. H* L. e - import net.minecraft.client.renderer.RenderType;% Q( A8 ~( }! J& o4 y
- import net.minecraft.resources.ResourceLocation;
7 C. P/ ^, P1 i J" o
1 ^& v# I3 K( b5 O4 p* e- import java.util.*;- \1 l) V/ Y w
- + z+ N/ X8 J K% k; ]
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& q# _1 J9 Z; ~- ?+ D% E) n; d, L G
o( P( D) B) D- v- public class LineRender{4 O7 O5 [% v, ^! Y& Y
- private final PoseStack pose;
0 H* e9 ~7 b! n$ {, m1 x9 I - private final MultiBufferSource source;
) O0 z9 t' e9 `) B. d - private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ ?5 ?% G% b3 l* s& d$ t3 M
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" i: g, \/ f7 E) T( X4 r4 l/ l
- . l A& g, b3 t4 O
- ( @0 _; E7 @/ p: `% N
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& b S8 w2 t9 T. q, Z' D- W - if(x1 == x2 && y1 == y2 && z1 == z2){: g/ G+ E) r. N
- return;
& z% E# N/ u. k9 D1 j6 ~ - }
- `5 L* S7 g) Y8 L1 S; M R% E# U - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 C) z; X* U3 ^; V7 q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 W& c$ i/ z: P4 E - }
% l9 K2 Z# U& m# h8 F9 i - pose.pushPose();
! M) V7 x. e1 ^5 F0 B - final int newLight = convertLight(6);$ m o' N. N: r; t. g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 ?% h% ?+ N3 ^0 Y; @2 ^
- final float lineHeightSmall = (y2 - y1);. D# z) T/ [4 ]0 x' ^( c
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* m/ E1 ^6 `- e3 T* i+ D1 Z - pose.popPose();3 B. {, ^1 q/ |8 }
- }
. X- f! }2 e4 v" ]. @" g, x. V2 a - # i3 F% S. i* e. x! o: t9 v! k3 Y
- private RenderType getLayers(String texture, int light) {
B' I3 m( o" [/ s - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 E. C& S6 Q) t& U) m& f - }! V6 q9 `+ C% |& _6 r
- 7 P* V; l/ t, v% X+ T$ D# R, \
- private RenderType getLightTexture(ResourceLocation texture) {0 [, \8 T" k% Z& B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# {( O' _0 B+ Z1 P( i - }
, l! \, c5 j+ T9 _5 w# ~0 @- D - 9 s, b: o: J! {4 x0 a9 ^
- private RenderType getTexture(ResourceLocation texture) {9 E- \* Z- H% u7 h# _$ M% s8 Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B); h9 F0 u/ q7 L! s4 O
- }
+ i7 ?3 c" Y$ k6 D1 [+ c
; u7 Q5 G% z. k- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 d" C# |# t, Z% Q% M - if (cache.containsKey(identifier)) { m9 f6 [7 [$ Q! h3 T" I( J
- return cache.get(identifier);9 J6 F& l! K" M
- } else {1 n$ |/ o. s! o9 z/ P: L
- final RenderType renderLayer = supplier.get();
* X) h8 ]1 `+ f2 U3 |- A - cache.put(identifier, renderLayer);
* c+ k9 w; @$ R; { h - return renderLayer;
( f5 f- u6 b. @( { ^4 O) g9 e - }6 g2 [" f9 s4 U ~
- }% y4 i/ `: g1 M* K8 X) @
- }
复制代码 |
|