|
|
( D+ Z5 x$ Y! X; |) S- I7 n. E N& m
行,这个怎么样
4 u l) W& W0 @7 X9 Q. ]: l- package com.xhg78999.mtrfac.render;
% e/ J4 p+ K2 a; z) g - $ g5 h+ h; ]4 U( S; V5 Z& A
- import com.mojang.blaze3d.vertex.PoseStack;
* I( t7 L1 F! }2 T$ |/ [5 _ - import com.mojang.blaze3d.vertex.VertexConsumer;
/ m% ^; O8 }! t+ U4 _; j1 }. P' }" d0 f - import net.minecraft.client.renderer.RenderType;, w2 l4 ?' H# l- N
- import net.minecraft.resources.ResourceLocation;
9 l6 y6 G% ?* ^9 p& W a - 2 K$ ^) U& B8 S$ ], @- @
- import java.util.*;0 Y0 b# B. E& V+ v& B5 D H" S
- 5 C" Q6 ]6 a$ t5 `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, h% b% M3 B, ^- W! l# ~ - 2 o- `, {/ u |; h2 g9 B/ M- r `) k2 H, ~
- public class LineRender{
+ L7 C- i: ?1 M - private final PoseStack pose;: N. [! b9 f1 @2 X& j
- private final MultiBufferSource source;9 N3 O% X4 B; j: ?" z& L
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- {8 U7 d/ Y3 I* X; E - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 d. U3 L* m& O% L- ]- }& Y- t ~
- . \7 ~. x S5 j- `( T9 O
5 e. `1 l; a, Y, ?1 m) V9 g8 K- Q- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 ~! t* |3 | v
- if(x1 == x2 && y1 == y2 && z1 == z2){* L2 X4 G* L8 f, p
- return;
1 d! y# n/ t* z8 J y/ [$ D) ] - }" k/ H) N* ~3 |3 ~) {' t0 ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. }; y3 P* _ T2 o
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
G- ^) Y7 C' `% R0 a/ Y! _% o& A - }* C6 S) O" C1 W5 `& s+ D; S
- pose.pushPose();. {3 X n7 h* i w8 }2 C# ^
- final int newLight = convertLight(6);
) C# ~* A( J& S0 v* S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 ^& R: R* y' y% {; i9 M0 S - final float lineHeightSmall = (y2 - y1);
8 B6 F& q7 l. u& K6 k - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 z7 \' |& o7 B# t - pose.popPose();8 B2 Y' H* u# ]* a9 n7 Y0 w
- }
$ S% J# e+ K6 E/ E# N% u" c; | R T
2 q, i. e- o# B5 R- private RenderType getLayers(String texture, int light) {
) z) f4 L( A9 j* A- W! f- E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ L- P. K, d4 |# p9 ?' g" G! n - }, b5 `4 L; v3 ~# M7 m
2 m, b) J5 U) P# \1 y$ ~: X- private RenderType getLightTexture(ResourceLocation texture) {
8 K5 b7 `5 P: H/ H - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); D6 E% k$ L w: A& Y% T/ I, X. r
- }4 I1 K* y! N8 d0 M. i2 X
- . ~5 o/ K+ W2 V- j
- private RenderType getTexture(ResourceLocation texture) {
; ^# V$ i* w3 r2 c - return this.cache(texture, () -> entityCutout(texture), CACHE_B);% Q ]( P' p5 h' R2 u
- }. `5 o" `* X) U( A3 i+ M
- $ }; P. ^9 [7 H* y) D- ?
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 I, a$ K" J) A, v - if (cache.containsKey(identifier)) {
# M- e, ]0 `- E" f& @1 L- s - return cache.get(identifier);
$ i y$ Z+ _# L# C - } else {* \( n! W0 {: G3 ? w
- final RenderType renderLayer = supplier.get();
4 d8 M/ U4 Z9 f! K- w9 ] - cache.put(identifier, renderLayer);) N n1 L0 [# Y5 W% q* P; E$ ~
- return renderLayer;* y! b7 d8 w4 i* Y- \- B0 Q
- }
4 ?$ {9 {2 }1 E6 f - }
2 d6 o+ U Y. _; e - }
复制代码 |
|