|
|
7 S( }. R! a0 C8 G. e
行,这个怎么样0 Y( y/ X: D: I1 u
- package com.xhg78999.mtrfac.render;
1 O( h) b$ k: @( u4 u - & \; B. g+ K3 G* [% z
- import com.mojang.blaze3d.vertex.PoseStack;$ M3 X6 G. i% H- q+ j. r. c
- import com.mojang.blaze3d.vertex.VertexConsumer;
- I, U9 D8 q9 G( j. R9 A: ` - import net.minecraft.client.renderer.RenderType;
% _3 T- u. v: V$ N - import net.minecraft.resources.ResourceLocation;" X3 `" P" F. O3 Z% `7 g; `
- 8 G& {6 x! T$ a* t
- import java.util.*;, |* d& K7 f1 Q; p9 a* ?* T
+ [% q( c3 u3 S! |/ G, s- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 n, [# }* S: |2 h0 a$ _ - $ d1 S. v/ j' h! |# n8 N
- public class LineRender{$ M" @: [0 m7 S" x7 }& H
- private final PoseStack pose;
" g) v1 V9 }3 x# c* ^) u0 b9 { - private final MultiBufferSource source;
5 L1 D/ ], L" o. T - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 G0 C) m3 k- A
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) l% Y* P$ u- ^9 M
- 6 r! y8 b0 D5 B, F8 ~9 Q
% R4 f2 L, w1 i+ s- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 e( |& x& B" D) q w9 h - if(x1 == x2 && y1 == y2 && z1 == z2){8 g6 F5 D4 T, u e2 y {; D' m
- return;
/ @7 G A. N, x - }
- D& n% y( [/ `/ ]- K - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* E: L* |4 _1 j. N4 a) b v# Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
' t) ~, E! x) Z! M: z- A - }3 J. d" J" C) q6 \# H6 q" u3 a
- pose.pushPose();9 a& c8 b5 v, w8 E4 {0 L8 _
- final int newLight = convertLight(6);
- w, J, N2 q# _% T( {8 I/ v9 I - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' r1 w; e+ W' Y# V n) z, y( [! e D - final float lineHeightSmall = (y2 - y1);
5 }+ T9 ?2 f& D - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* ~) \& A3 K0 @! v0 n - pose.popPose();, V0 e1 ]" U2 s6 E5 W/ a3 [
- }+ z/ u4 U# s- l
- 8 m7 E; y, g+ l) C; m; H
- private RenderType getLayers(String texture, int light) {5 j. P6 f) C- S' o
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ O+ `. z! T- ]# h. [, o+ v7 |
- }+ b& ^8 }$ A+ w6 e9 d2 o4 \
- ! }% x/ _4 r2 [! F
- private RenderType getLightTexture(ResourceLocation texture) {! f% m$ Q+ A; V. A) h2 W* K4 W
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' {) r3 h7 \# w! ~& `% ^
- }+ {' X0 l4 v6 R7 M* I; u; N: D
- 4 L8 M3 a% A* @0 ~8 y
- private RenderType getTexture(ResourceLocation texture) {
0 e$ i1 L B1 E! V% P - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- P" n( F/ Q6 q& M* j - }! ~( s( P% w! _+ i
7 @0 }; [$ @4 o" J8 I* P4 t0 l( j8 N- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' F; {) K2 a5 }) f0 t! G7 p2 j6 i
- if (cache.containsKey(identifier)) {
, k3 _( [3 ~; x: r - return cache.get(identifier);% q* ^% R% Z' c7 W
- } else {+ g$ b2 _( C; @* c" d9 g+ a6 t
- final RenderType renderLayer = supplier.get();2 v/ x4 _6 s8 b( P n( V- y
- cache.put(identifier, renderLayer);& ], }$ x1 ^2 x8 R
- return renderLayer;
8 i3 A& o& @1 u3 a - }
( ^% m& X- Z* d+ t) r - }& [$ E W# ^% U& h) F. C5 i" Q
- }
复制代码 |
|