|
|
( y1 ?) y( _2 P% q, B) v* J行,这个怎么样
1 y' ]' B( P/ p: f1 U/ f- package com.xhg78999.mtrfac.render;
$ \% S$ l& }( u* Z8 }. c - 4 g# W+ H' K' A5 r( N
- import com.mojang.blaze3d.vertex.PoseStack;$ ^+ l- f" K# Y4 {! S+ a9 g9 d
- import com.mojang.blaze3d.vertex.VertexConsumer;
! x1 x, o/ N4 L0 L: R - import net.minecraft.client.renderer.RenderType;$ D# f% u6 i0 T) F
- import net.minecraft.resources.ResourceLocation;
c0 L( _* T9 t" {% U - * m2 _4 m( Z j) s" `: o' B% [# g
- import java.util.*;
) l8 Z! a) r; c - 2 |4 p4 d$ K8 l) j- H4 S5 C
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ b. |) I2 H$ K7 ^
- h* f2 C* X; B7 u: v; D3 C+ w7 C- public class LineRender{; R: ?4 K- G2 O9 I" I3 Z
- private final PoseStack pose;2 x0 \) `8 G5 Z+ {4 S* `
- private final MultiBufferSource source;: w' D6 m0 O* _; A; B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();# ~$ _/ s# q% t6 K) b7 H; }
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! i$ S& R/ Q1 X+ C% u3 k3 f, W - ) x) D# k* D' R9 C( e" [% N' t( ?( k
- ( E* w: r2 d8 M
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" P8 i$ o# ?# \4 p& I2 u) V9 ] - if(x1 == x2 && y1 == y2 && z1 == z2){( n5 a! x6 R! Q
- return;
: N9 N7 N9 v# K! l% g T% r - }1 S' o1 p9 {- I
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, s% h% N3 f/ j, ~1 }
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); a- d% a7 p5 c4 T
- }
* b. n0 S- X, n( H9 P - pose.pushPose();: X) x$ N) d( X& ~' d D' L
- final int newLight = convertLight(6);
" X+ ^% {5 S T! b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 |8 r/ ~1 D! ?4 h - final float lineHeightSmall = (y2 - y1);( y7 g0 ^, R. F/ F; s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 r4 P# K: H9 Y
- pose.popPose();2 K; s: S' P' H5 }# ~4 |
- }
. ~, a I8 B" ~* S/ V4 @
$ @5 I6 N# N8 J- private RenderType getLayers(String texture, int light) {5 Z4 @2 }5 v1 Z! @; [8 X
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; O) V$ F, U1 S+ _6 |
- }* d$ Z4 U/ ? _# ?
- 0 T/ _! D) Y: ~1 O) _4 e- o
- private RenderType getLightTexture(ResourceLocation texture) {
. l# }. k s4 M8 O - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 w6 M8 X, S6 C) M& j - }
, q; h6 t, D# S1 f! v: z& ^- e# | - 4 I9 H* f& a/ q8 `7 w, e
- private RenderType getTexture(ResourceLocation texture) {
/ L' Z3 ~7 I: ^% l* n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. S3 Y4 v* G, n7 g - }- P: N# C1 U, \5 N
- 4 n" C: ^1 Q0 n7 H$ X: O
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
b: G7 N5 ~( k) u! S! g5 W - if (cache.containsKey(identifier)) {4 v/ F! r- t1 S& Y
- return cache.get(identifier);
/ h$ E/ B) ]" K1 \) K1 w8 M( l - } else {- s) o H- A/ k; i( {% q9 p
- final RenderType renderLayer = supplier.get();/ ~6 v+ F4 h6 j9 O: P" z: C0 A
- cache.put(identifier, renderLayer);
0 s( \6 J% h \& K) [1 D" Y X" N - return renderLayer;
7 K2 M2 n% C+ T" v' I R - }* v- m+ i$ K7 s) f/ a1 `" }3 ?+ j
- }
: r' m( X, O M4 ^! f& A- g& _ - }
复制代码 |
|