|
|
; K+ E+ U- J9 ]# D7 P
行,这个怎么样7 z# A: U9 n/ t; \
- package com.xhg78999.mtrfac.render;0 n3 m& @8 c/ c& T
6 ?& z# W2 ]" \9 ^1 l1 B- import com.mojang.blaze3d.vertex.PoseStack;
/ Q' X' {7 ~; q" s7 k - import com.mojang.blaze3d.vertex.VertexConsumer;
, Y ^+ j- Q' D: y$ R - import net.minecraft.client.renderer.RenderType;
% s" v7 Y) [/ O7 h" B8 @4 I! L - import net.minecraft.resources.ResourceLocation;- ^9 b7 @& p: e( J' j; ^
6 I- J' o0 P. X# e- W- import java.util.*;; [7 f9 \4 a7 W- i. ]* A1 p
- 0 v* n; |0 H0 i4 t9 i* T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 l M$ A @; V% H9 E' [
: V3 h2 P/ d2 P2 c4 d M( A/ }- public class LineRender{
9 |( ~% ~& ?7 \* P: ~8 n - private final PoseStack pose;
( }$ R, Z& {: a4 G3 }, A0 Y S, N - private final MultiBufferSource source;
# p. [. ]* A9 j4 h6 r4 X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 M+ W, Z" _" ~( ?( D7 O, } - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" W9 E- b' l8 r* @! r - 7 {$ P5 f7 F! k4 V, m; w0 w
' o9 x) d& P" t- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ d- q! D6 W' _, L - if(x1 == x2 && y1 == y2 && z1 == z2){
8 \! w! O5 H& j9 C( e3 D) T$ P - return;
, F. e* V1 v* S8 b3 M - }
" H, Z: z! o* G; p) R/ P9 E5 N) @ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! _! I8 D+ }1 _- O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; t6 L. R8 i a+ z$ j) y
- }
) d. @% C I; e Z* p$ Y - pose.pushPose();: e2 E$ X9 J" N# Y) H1 [6 {
- final int newLight = convertLight(6);
. O( F+ x i* c* y$ o* q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 `0 ^$ C2 A" S+ i - final float lineHeightSmall = (y2 - y1);
- B+ @, [1 A6 b2 Z' k: L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! ~2 H% }3 b% J, U/ @" Y5 {9 y - pose.popPose();6 P- {8 r1 [+ P6 f; p: L0 e# H
- }$ ~5 | D5 P& r8 Z) T
% c( T- s) U- D. b% f- private RenderType getLayers(String texture, int light) {
! t! I l5 |( R; r5 f) k! q: G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
2 u$ a* q5 P9 y; }8 x2 w: C0 _ - }* x; H8 o z1 y4 h% k6 ~+ F
- ^/ l; ?8 y9 |) K6 P; B
- private RenderType getLightTexture(ResourceLocation texture) {- \3 {" R; n- f. A0 s
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: R- i6 r" C$ u8 z2 R - }
# T' t0 ~' K R, I ?& z) A - ( ]: c/ I& V1 ]/ ]( a
- private RenderType getTexture(ResourceLocation texture) {
- j' P% W4 R/ C - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& n- V! i8 {4 G1 A% N+ H3 y - }$ ?) K: @% ]3 @, t
8 S" L: a' m( M6 w# X& e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ ]" D3 V. x w/ C+ V; I5 S# R3 n
- if (cache.containsKey(identifier)) {9 u( R7 G* t6 ]; e$ g, p! R
- return cache.get(identifier);
; `# q. Q% m0 y+ D - } else {
) g% e/ q" E p; w7 n, k& B. D - final RenderType renderLayer = supplier.get();% D3 r3 d& ?; g( S0 k w
- cache.put(identifier, renderLayer);
5 `) a4 D$ S0 \, d2 j3 V - return renderLayer;
& a/ p% z2 ?8 |7 X" D) J3 k! R - }
* p- C) g" L$ q# X6 k5 k - }+ }$ a. W/ L) Q" x2 S3 D
- }
复制代码 |
|