|
|
0 ^ O6 I- F. Y/ x; ^: @$ Q8 x行,这个怎么样
/ C- u& e' T8 z7 T- package com.xhg78999.mtrfac.render;8 o7 z. K" q* R( k/ A
- 4 ^' t, i- f7 M, v# Q4 T0 e
- import com.mojang.blaze3d.vertex.PoseStack;
6 I6 x" _# c3 i - import com.mojang.blaze3d.vertex.VertexConsumer;
) }9 m2 h9 j8 i* k - import net.minecraft.client.renderer.RenderType;2 M/ A' E2 d6 w4 b1 s* d; Z
- import net.minecraft.resources.ResourceLocation;
5 p) W' }- n5 x
9 U7 X/ e% ^ {. G J/ y8 B% a- import java.util.*;; C% @. m5 C: r" Y
- ; ^5 I! \2 V5 A8 G8 r: o5 Q r z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. V# T5 m x7 H7 z/ Z c - + u1 ~9 d: r2 J7 S J! @
- public class LineRender{
( E0 q8 N- @. k0 ? - private final PoseStack pose;
5 ^8 m5 c4 ?# F8 s( I+ e - private final MultiBufferSource source; f: w# `" a" B @6 [2 G# a
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 w3 L% J& F) O. D6 E* s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); s" P! L! a2 L, c/ c! w
1 n# O! [6 u. W9 v* \2 Q$ X9 F- , P4 F; c7 c! x! K1 X
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 i! u1 ?7 K J
- if(x1 == x2 && y1 == y2 && z1 == z2){' U0 Y5 G) `$ |, M& N; Q
- return;7 h5 O" @( X" N: v: x
- }% ~0 N6 e) _0 I( S, r
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) r2 B4 I% _ q# ?$ C
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 p. r6 k9 F% |' u. k) m - }
% p2 U+ m) R2 R - pose.pushPose();
: K2 i9 g4 n6 z) [3 |# Z - final int newLight = convertLight(6);
8 Y4 b; H9 I7 c% V$ T) C4 G - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 v3 @# H$ ~$ _* C - final float lineHeightSmall = (y2 - y1);, k/ I+ N f8 m A6 H2 h2 a3 Y9 u
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ j% k& G; \' H
- pose.popPose();. C+ |, s: F/ G4 ~ i S& N
- }' F: r2 X2 X) ]8 X3 ]4 m- K
& [, M. e& T c+ N- private RenderType getLayers(String texture, int light) {
9 y2 ^4 p/ ?2 z1 |* o* ]% R - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
|# ]3 \! F8 d0 ?5 M# c9 C. o: l - }
- G% v0 A/ q( E7 g$ ?) P# v8 Q1 D9 ` - 5 U; `0 Z w1 T5 Y
- private RenderType getLightTexture(ResourceLocation texture) {5 F4 {; |0 O+ n
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 |$ ^: y1 B7 B) G - }8 F3 Y% m3 \3 `1 Z: F$ P
6 p& V2 x8 x5 M& D" j) i- private RenderType getTexture(ResourceLocation texture) {0 y# x' F9 \7 T9 P7 f
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);% }: E L. y; F7 u1 _0 G, g
- }
7 J1 V4 w+ W7 C2 U4 y; J - " W5 ^9 m7 m$ n: V* x! e& ]& U
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ D& a$ R& t6 W. i! {2 s4 {
- if (cache.containsKey(identifier)) {6 @6 ]/ S5 U5 V2 K4 T- g) l
- return cache.get(identifier); e3 L, O) Y# |3 D" W- x. Z# v1 U% |9 g
- } else {
5 {5 y$ {5 W1 W6 ] - final RenderType renderLayer = supplier.get();1 u+ ^0 o9 i+ U0 h1 S
- cache.put(identifier, renderLayer);
2 Q% _# D$ D) L1 ~8 N. }' N - return renderLayer;5 C1 r# `- v1 I! ^' n' T2 f
- }9 H( L# x3 X* @, s7 q+ h; h: J
- }1 J3 M# \# R# |2 l- h: O# r% t- G
- }
复制代码 |
|