|
|
3 s2 t, L+ Q1 O6 w# g- x
行,这个怎么样
8 _$ W! U9 @# L- package com.xhg78999.mtrfac.render;
+ g5 U3 ]' g8 s! k+ D3 g
* q D( l. E8 e1 J9 Y. m& W5 A- import com.mojang.blaze3d.vertex.PoseStack;# Z4 H9 b/ L2 i' [% Q6 d
- import com.mojang.blaze3d.vertex.VertexConsumer; n0 N; j# [9 M" m6 o& q
- import net.minecraft.client.renderer.RenderType;
, P2 L( a( \! R, @. j0 R) X" O - import net.minecraft.resources.ResourceLocation;
# C1 V$ B: U# e
3 q: {9 C* D& Z( `. K8 G) M- import java.util.*;0 D- y9 A& G" b7 K
- / j& ]+ `! w; z$ v$ \% z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; H4 q3 y( ?( A7 f" Y& e' e$ q
H: G3 F8 D" D2 a7 [- F4 U. m- public class LineRender{
0 u2 j3 B# Z) }, R, M, K* B - private final PoseStack pose;1 A: ^: e; L; W
- private final MultiBufferSource source;
7 ]$ T$ C; f) K9 v. q$ `* C4 R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
. u1 c) F# W( L- T. y$ { - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& }3 }8 [: x* u% B
/ @0 \8 E9 L+ E
" H$ K7 y! C- T' M- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
0 y# T! c1 R- S; u. z - if(x1 == x2 && y1 == y2 && z1 == z2){0 Z$ O7 W" t7 p! P; A
- return;
5 z. r$ ^+ X: ?4 I/ r$ M - }
" b9 A2 T' X/ [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ m. p3 y5 |3 x8 ^/ n6 J - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 h% O; P) I. X1 ]4 r1 S - }5 P# @1 k5 k/ C% L/ ^
- pose.pushPose();
+ d7 [' c- Q6 z3 t& Q- }7 w - final int newLight = convertLight(6);: R: W1 N0 D$ U) U9 ^2 A
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ ^, _+ d' `, ~3 R
- final float lineHeightSmall = (y2 - y1);
1 |+ O! s- S# L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 A. S, Y8 t2 n9 c
- pose.popPose();4 T& H( R$ [1 y5 J
- }# ]+ H" W) G8 T9 ?, q
, v/ h9 N, O) q- private RenderType getLayers(String texture, int light) {
% u# Q4 y+ Z5 g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* Z' c2 q. ~1 v; p: p - }: ]' m0 c' R$ H" F/ k
- 6 \" y( P% w5 L5 d/ X4 X3 a0 ^0 z7 Y
- private RenderType getLightTexture(ResourceLocation texture) {! y8 z( K) y* I4 e! `- t; R
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! |' j. T2 A# o' V4 N5 p9 h1 k - }
2 I5 Q; P! {# O5 {7 P
5 i0 Q1 L% P- g" I- private RenderType getTexture(ResourceLocation texture) {6 r/ W" x0 J4 p A. e. ]3 @9 h: g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" [& ~& F3 e; ?, x6 H2 Q B/ u - }+ c! w' I: D# h' a& u
1 k! Z8 w _6 x, [* J* R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {. L7 F9 P( @ \" s4 s
- if (cache.containsKey(identifier)) {8 c, f# | X* s+ Y
- return cache.get(identifier);$ B9 l6 e* F% l: A3 U! W( ]
- } else {! x& t! u Z, a% G
- final RenderType renderLayer = supplier.get();
- B; ^1 G! `& Q% R# J. ]) c. I; X - cache.put(identifier, renderLayer);/ N& L U3 C' Q) Y2 `
- return renderLayer;1 Z( ^9 X n u/ U
- }
1 a+ U; H# o$ i) l5 ]! M - }4 k# }$ N1 i- F y; j- d& M
- }
复制代码 |
|