|
|
! R- ^4 V- c g& Y行,这个怎么样
6 p5 C6 y- ?# _# b0 K) l6 l9 ^, G- package com.xhg78999.mtrfac.render;0 x4 @9 V# k+ B& p* x
- + P; n! x2 ~ ~) S
- import com.mojang.blaze3d.vertex.PoseStack;
1 S3 @5 k! m8 k* T - import com.mojang.blaze3d.vertex.VertexConsumer;% G/ v# u, b9 T2 |9 S
- import net.minecraft.client.renderer.RenderType;
# T2 U/ z1 M8 [( v7 h - import net.minecraft.resources.ResourceLocation;; Z2 x+ x; M; [9 j, g! Q; f" b6 u1 [
- 8 _. C* x. j2 m3 r% q# I& A9 |2 |9 k8 s
- import java.util.*;
) q' K( q$ v+ U$ e - 3 m" ]1 S7 P" q; J5 T$ l0 b6 o+ j4 M
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! R1 y/ T/ y5 i6 v3 x* ]% H
! Z2 F* ^3 Y3 a7 J0 n- public class LineRender{5 `; [: Y4 ]' N6 g( _
- private final PoseStack pose;
& V$ [' c2 ]6 D; L( } - private final MultiBufferSource source;' I/ K/ K3 O; u% x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
6 r' G( l6 ^6 d; x+ }5 @5 u - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; H/ w2 L% k- d8 Y' t2 |# @, E
- ^$ X& U) n2 c! s0 X
8 H$ x, W5 Z g- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( Q% v8 |2 h1 p( c( n* B6 y/ R
- if(x1 == x2 && y1 == y2 && z1 == z2){
& N: o& l. X1 E! S3 Q( \# y - return;7 T$ d/ d3 i" U, ?9 t2 V Y6 b
- }
$ v. h) W) {1 y4 p9 D - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, S; [7 ], l2 h$ W0 L! ~6 _$ g- I - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 M W5 p. Y0 Z; n* c - }; t. \, a' S! S' J' |% x
- pose.pushPose();* @4 W6 k# T( V6 J) u
- final int newLight = convertLight(6);
! q' j4 C; h# F6 l+ L v - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 n2 h; y% y/ F C
- final float lineHeightSmall = (y2 - y1);
O& I' W- u* v( A* f3 C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ _+ X5 F8 o: `# P7 i
- pose.popPose();. v; R. l& n+ }
- }
& f( P+ B/ D: k - + n9 M/ v: r, n8 R9 l4 d# {8 P
- private RenderType getLayers(String texture, int light) {0 i* ^: f4 T8 A
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, _! X: y& y2 {7 P# r5 d6 F& v - }/ C" ^; o6 a4 _& g2 ?
& w. x) F4 j3 m D3 K- z% ?1 g- private RenderType getLightTexture(ResourceLocation texture) {; _5 y B/ p. m, L7 r
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ U5 H ~: J2 C; s0 _! V - }/ m) {8 Z3 N/ A- t" j* q
- ; K' \6 D3 c- @; Q
- private RenderType getTexture(ResourceLocation texture) {
1 k9 s G, V6 i% f - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: [ X' q& C( q% O$ W7 L" f; D
- }& u& w( H# |( M. P
- + I4 S: k3 Q0 C$ O" _0 M* e
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
0 G- v; y1 C4 h - if (cache.containsKey(identifier)) {
* }( G4 ^' r3 D" a) J3 d - return cache.get(identifier);
! a0 B& k4 h% V) u, e6 `! m( X - } else {" |! v$ r3 J/ `2 R0 h$ Q# \; W Q
- final RenderType renderLayer = supplier.get();/ Y X# G" q. B6 e& C
- cache.put(identifier, renderLayer);
: k# N4 N3 h! D" x; R6 ]/ H - return renderLayer;
) D/ M {4 o- P# |& P# Z: d - }
, W8 c/ G5 w7 n. E2 ?* o a - }8 y7 G- F" l! s; |: M$ T
- }
复制代码 |
|