|
|
4 b1 x! Q) }9 C4 W% }5 S行,这个怎么样
9 C! P# D& [: ?( b4 M- package com.xhg78999.mtrfac.render;1 E5 ^+ g6 O) w& Z4 ?& u; o, Q: s
- 3 }8 c3 \4 K8 K! b; r$ G Z
- import com.mojang.blaze3d.vertex.PoseStack;
- B( G, D1 a$ }7 W0 g3 Z7 O- z+ Z+ e - import com.mojang.blaze3d.vertex.VertexConsumer;: ^% ]7 y- Q; P S4 X5 |9 }; k! K& c! O
- import net.minecraft.client.renderer.RenderType;: Z. ?2 y0 v+ i9 D0 `6 @! ~
- import net.minecraft.resources.ResourceLocation;
# @' l) V& h$ B2 | H0 j
+ L+ t! q3 u+ e- Y8 N4 q- import java.util.*;4 H$ X' i+ T/ T' P8 `
- # U) T% o3 U `! q2 D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% j' o$ T! `! o; {! K7 G$ s9 F
- . l! \- q2 H+ d/ t
- public class LineRender{9 t2 M h. K; I9 h$ c
- private final PoseStack pose;. F& A l6 [; M3 |
- private final MultiBufferSource source;
, y& [/ w) U. V8 N" M& m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: k, [& C1 R1 T" \* |0 Z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( J; e2 B ^# Y; |, @1 v( T% p6 e
7 d; h% T, ?- r7 ^/ g6 H
4 N( E8 t6 E/ |! d" _; B: O- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: h! ^# m% a! r" a, g) r - if(x1 == x2 && y1 == y2 && z1 == z2){
7 W# F* k/ G% b# [' U# d9 _ - return;/ N% }' t. z& {6 N* A
- }
. o% Q9 N5 Y5 D( Q% j: w7 U - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ z5 {2 n; m' a' j* s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 V9 |/ Z1 t/ s% ]' l
- }' ?2 Z4 y4 @, Y6 A: u1 R
- pose.pushPose();2 N: n8 [5 p1 [- O( b" H; a7 Y( e
- final int newLight = convertLight(6);! U3 h) S& K. E4 l+ M8 S) g3 e
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% [5 ~+ G# x! v, y7 z - final float lineHeightSmall = (y2 - y1);
0 y4 R$ U# v, b - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
6 ~. h7 H. c8 j - pose.popPose();9 M. g' _( R- n2 L c
- }
$ O9 }& e9 A }0 i
h: y' i0 M, i( U) H( ~- A% s- private RenderType getLayers(String texture, int light) {4 {7 T* ?; }, _- F: m! A4 ~8 X+ L
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' E3 n+ C: O, t0 P - }
1 {) s' ^; [4 V: r# } - : ^6 _5 n) c! u/ T2 M J, c
- private RenderType getLightTexture(ResourceLocation texture) {# @- a, n# [" P: O$ a$ ^1 L8 y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. G# m; t2 E$ Z$ [% o! U - }- p& Z% U1 Q' y9 T
2 r; h- t( ?7 m$ e+ n, N, G1 s- private RenderType getTexture(ResourceLocation texture) {6 s; H1 S8 j8 @9 f$ v) @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 z0 o4 S ?- K$ l) u - }$ D7 Y$ o, M$ M. A
- , l0 `/ l$ h% m/ n8 s
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 H; Z4 r q* f& {5 c* l - if (cache.containsKey(identifier)) {
Y! Q# j) ?: m1 ^! a% K% m7 k - return cache.get(identifier);
0 V$ C! S4 w; m0 D - } else {
, B5 c! ?4 e3 _% O$ } - final RenderType renderLayer = supplier.get();
0 P' c. X$ Y( O6 C, \) Q! @! C B* \ - cache.put(identifier, renderLayer);
% w% Y; M$ e1 j* }; ?* }2 @ - return renderLayer;5 I3 x" ~: i1 M) L
- }
2 c; g/ E. Z* q4 C - }5 r6 a/ }6 \ z; |1 @" P
- }
复制代码 |
|