|
|
. s4 G7 @" ]! u$ _! e' |& j2 X- A
行,这个怎么样1 Q' V! ~2 B( ^
- package com.xhg78999.mtrfac.render;$ j7 `+ o* t8 y L
- 6 @7 P$ R. X$ C/ h1 _! r
- import com.mojang.blaze3d.vertex.PoseStack;
5 N# N+ H8 k+ }3 ^& Y - import com.mojang.blaze3d.vertex.VertexConsumer;
6 J9 e6 t9 v, S! |% c0 d/ P - import net.minecraft.client.renderer.RenderType;5 u# F* u/ ?. P8 K& l( e [7 z
- import net.minecraft.resources.ResourceLocation;- D6 H2 D4 v% Z! f* h
- : W- H, m; d! m. a0 v. `
- import java.util.*;: X$ h$ k; b) z' G
- - {8 Z/ c* V* z1 H6 F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 ]; V8 m% x4 Z }1 l5 T1 ^8 V
- |0 o: ^ J. N- public class LineRender{0 h9 h6 Y! `! ]9 P
- private final PoseStack pose;3 R& R. l% O" X/ _
- private final MultiBufferSource source;
) d/ h/ j2 U* x5 _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ S T# m. B& D, c" S* Y; c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' I: k2 P- Q! T* Z
- " U& Y- j4 U+ Z2 `
- / Z' y4 S( q3 [" J+ f
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){7 f! W0 `4 [! a. b5 V/ Z
- if(x1 == x2 && y1 == y2 && z1 == z2){) i- V x+ b; }/ M3 L
- return;" r2 |- k3 I! v# r0 B
- }
( I7 V1 L" D5 D" j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 [8 q* |) O! ]7 m8 c3 L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- z2 D* y# i. i% C& [; I. u$ H; F7 g - }& R' j9 e k4 Z* R
- pose.pushPose();
6 K h* S( \: M, ^ - final int newLight = convertLight(6);3 v5 ?, D6 @2 W& w: v5 c" m# ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 z' G- M4 q2 Q6 a9 g - final float lineHeightSmall = (y2 - y1);
* j- n+ X" N& g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, f r/ q ]; `# E
- pose.popPose();
* o$ Y" `* g; p+ b* Y+ R0 K - }7 B u0 U* u/ }1 P
- " e: y5 V9 b& g8 F8 ]% Q$ t! @
- private RenderType getLayers(String texture, int light) {. h( ^: {2 }' ^6 k) _( n
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 f' b# z# X6 N3 m, y - }
, K! P# `, ]' m/ d% P) s$ i
# U6 h/ e, x- J" L9 s" ]3 ^( b- private RenderType getLightTexture(ResourceLocation texture) {
9 W) R" y$ M9 F7 l& {. i% W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ ?- g8 p# M, p- _# j2 t$ L: x' u - }2 R0 w0 c: z$ M( Q) n* D: \! s4 ~2 l
5 u# g" [0 M/ T- private RenderType getTexture(ResourceLocation texture) {, d# K7 V7 j9 p8 D5 k: i
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; W( m: }5 A5 V. S- V8 Z( o
- }
( s+ D D; O9 ]. L0 M
6 H( Z- v# [ T0 {' A- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; O4 [8 g1 Y0 l- v m* S: t - if (cache.containsKey(identifier)) {$ g0 O/ |7 ^7 W. Q! n6 T
- return cache.get(identifier);
1 w: Z' @* S" L& Y% Y) w& o - } else {& w+ j5 L* X2 j3 P
- final RenderType renderLayer = supplier.get();
$ t8 _; U# w; ^/ f3 w - cache.put(identifier, renderLayer);
1 N3 y' W2 x5 ]5 S1 Z6 N7 \ - return renderLayer;
L9 l& m% G9 u% ?& [' A7 t% M - }
" n1 i) S& Z0 x: C8 o [' M - }
3 R/ B$ L( _% G. v# X- l8 ?1 { - }
复制代码 |
|