|
|
2 S/ W. J6 W }. K行,这个怎么样
- M; J, v' Q' F. ~( _ f( a- package com.xhg78999.mtrfac.render;
- y+ D; | m3 X: b% b0 X
+ V1 S9 Z- ~; o/ W4 s% o) t" O- import com.mojang.blaze3d.vertex.PoseStack;
" | j* p; o& d, _. ^ s - import com.mojang.blaze3d.vertex.VertexConsumer;! O9 L$ G9 k) R& y# d
- import net.minecraft.client.renderer.RenderType;
- [ D+ ]2 O) {4 r" [) } - import net.minecraft.resources.ResourceLocation;
+ s. u6 H9 [$ n3 |4 r1 {$ S+ l - & c/ r' i% ^5 w, ~ r7 \
- import java.util.*;
& }" G% L/ g1 k& h
5 i, v2 c0 b `; K+ A, o) {! G$ W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( n: p5 g6 i+ @) h
- 8 M; c o! [! O X0 t
- public class LineRender{
" ]- V1 k3 Y# p2 n - private final PoseStack pose;
+ C; n% W; s1 ^' T! }9 I- ? - private final MultiBufferSource source;
+ \' J/ V3 r7 O7 q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();# s( u6 k$ F! e2 p
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 o6 J. z% z1 R; i+ d' Y2 c0 G - . l5 R/ g3 s3 x* J! Y7 q
4 ~# x3 ? k( t9 P' r Y# C1 z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: m, Z+ p7 d9 b2 C* X% A0 f; K - if(x1 == x2 && y1 == y2 && z1 == z2){
, H& r" `5 y5 h - return;
- t! Y% p0 D# A - }
$ S9 H8 A2 l: M8 {. \+ l3 j4 c - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 Y3 I7 i9 j: c8 E
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 [: p; J/ V3 n1 X; h8 y
- }
: ^& A* p5 R- J. @( l - pose.pushPose();( U( y! Q: m9 _" B& a3 y
- final int newLight = convertLight(6);. M& L, R2 I# D% ?- n- B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( i7 q0 l% Q2 P3 @$ K - final float lineHeightSmall = (y2 - y1);4 @. Y) z- d6 ?- B" p% E
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, y! n. J# o# b! M( n( t
- pose.popPose();
5 i& b) U" e& O' Y2 ~- X! L - }6 p% v9 T0 Y5 f4 t% @
- ' L0 W5 A' I- H) o" Y- F% ^8 r0 J
- private RenderType getLayers(String texture, int light) {" i# o& }! k- ?
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ u, _, v. l6 l9 D0 l" V! z3 E - }! Z2 |" C; C2 u% s, D
( B: M5 B' M7 N3 J* G8 D% N* B- }0 _- private RenderType getLightTexture(ResourceLocation texture) {1 L) |; M' b7 C: n' k$ F: w4 S4 h
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! P7 Q1 n: w4 P* Z) _9 @
- }
3 z: { {3 V! N. o# y- }
. w+ u0 i5 n+ j- g8 r* G- private RenderType getTexture(ResourceLocation texture) {$ S. G/ I1 g; d% b' a1 E" D) v. ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 N2 j! W6 x7 V) K0 N
- }3 I4 j8 t& L% Y) \! J. L
* _! W2 O6 N& v) j- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( h0 I' ]/ P/ T X8 L9 F
- if (cache.containsKey(identifier)) {8 _$ H! p ]" X
- return cache.get(identifier);
( [$ o- x3 k9 g" C - } else {
/ S0 g/ I* K8 s3 f5 { n9 A - final RenderType renderLayer = supplier.get();: p% |! F2 o7 U! a2 B
- cache.put(identifier, renderLayer);
, E( X0 h% b1 O4 Q5 ~ - return renderLayer;8 n% f6 C* y6 Z! C
- }+ `# W5 ~6 {! h+ k
- }# |6 ?6 P) D# _
- }
复制代码 |
|