|
|
! A; D# U/ G3 M; l% }0 b2 \行,这个怎么样2 j5 {) g* x/ u! K$ a ? m
- package com.xhg78999.mtrfac.render;" l# g, @- h7 n3 ?
- ; v1 x7 B S1 o4 k% c1 N6 L2 x& v7 M
- import com.mojang.blaze3d.vertex.PoseStack;
5 |7 _5 \4 h% J0 L4 i( w2 O - import com.mojang.blaze3d.vertex.VertexConsumer;
4 W9 y1 h, G7 a - import net.minecraft.client.renderer.RenderType;+ D! f# O; x% C3 ?
- import net.minecraft.resources.ResourceLocation;
$ R; |. Q0 b. E* r. r - 3 k. E- P z4 X1 o( A7 s
- import java.util.*;
4 [) @. s" m6 K
+ P, Q' T+ w! C8 u- S! u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ P) u0 T. y& X* m. Y+ s
! d, w* @" z: z* |- public class LineRender{
! @4 m0 C, m; \# X8 d& @: J! }* | - private final PoseStack pose;
: Y% |* K3 ~& c/ E4 M! ~; u - private final MultiBufferSource source;2 s" J. g8 X" c+ [) d" l; O3 G
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 v/ R8 ]: g8 u5 f' t2 _3 R, ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ E& b% [7 E% x8 ?+ p# p0 i
7 Q6 c! y- E. y, p& V5 u% N- " R7 t6 r8 X( F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 _7 _7 C8 g: {/ n0 M7 V9 z5 W
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 x. F3 c9 z% ~ - return;
& V; N/ j3 t, W W ^3 q - }
% W0 A! Q0 j1 p! j9 x; N6 c% L s& s - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 J! z4 p4 u. Z/ N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 ^$ q5 ` p( L0 O - }
# i; j9 G& @2 P - pose.pushPose();1 |$ K/ N3 E* A8 c$ _9 n% t
- final int newLight = convertLight(6);) k, q6 N+ ?1 c# n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ S% f9 J- S. y h1 n, k - final float lineHeightSmall = (y2 - y1);
; G; Z; ]3 z1 F - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 v9 b* d( C X4 e% B - pose.popPose();0 d$ g* j$ o9 k- g
- }; R# l3 G6 ^, a3 t4 b8 E% H
- : v7 H" ]- c3 ~9 {
- private RenderType getLayers(String texture, int light) {7 A- U" R6 E8 z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& O& a- Y1 E! h; M
- }
1 R" I1 B; `, p; R9 u: x( y8 `
* E# N; O( ]4 `; O- private RenderType getLightTexture(ResourceLocation texture) {
" d" c9 A: s" C/ ~. n; x7 [' Q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ p' {; {! r; A1 E - }
5 ]% }0 m8 M L9 ^# e( Z - 8 k- _) z' f. l) a
- private RenderType getTexture(ResourceLocation texture) {0 c, m- t" l. Z: C8 E
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);( b/ Y( \. z8 j- V
- }
5 h9 `. Q! Z0 M" {! n {# Y X- V, W - 1 b' y& E; C8 o: I5 S/ L' k
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 b! S% A/ Z! v6 Q$ G - if (cache.containsKey(identifier)) {4 e5 e! o/ ]3 a; l2 b2 ^
- return cache.get(identifier);
, f; g- q. T; ], d3 W! f - } else {
& A: N. |& v, K( {- | - final RenderType renderLayer = supplier.get();5 P/ t* }2 p5 p: {
- cache.put(identifier, renderLayer);/ i& [/ P a" {
- return renderLayer;
" ?/ b- ?3 L( i7 B$ z& b - }
) R1 B5 A; E+ `( Y. y" R - }# ^+ r4 H' S& }
- }
复制代码 |
|