|
|
8 y& U$ q: B$ i; N# V, Y( J8 y; z行,这个怎么样
* _- F3 M7 t. z8 E, q4 \( t0 ~/ ]- package com.xhg78999.mtrfac.render;
( @ k' E. R9 U6 b+ t1 ^6 M
C% h- H+ W3 u- import com.mojang.blaze3d.vertex.PoseStack;) u; e/ U& Q0 \% P. Z6 X
- import com.mojang.blaze3d.vertex.VertexConsumer;7 R! S O9 @: D# m5 ]7 h# ^
- import net.minecraft.client.renderer.RenderType;% [0 ^+ P5 A) i7 J" g
- import net.minecraft.resources.ResourceLocation;/ ]% y; X* d3 E' o
- # J3 h {% n" t4 G' _/ e
- import java.util.*;0 \+ T1 w, |( i
* f( h+ O( H4 i. S- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 [& o) m0 q4 s
: }& P' ]4 y) y: M- e% t& n2 s- public class LineRender{
6 n$ e2 A, I; Z4 }' D" I8 L - private final PoseStack pose;
! n: w1 r2 x2 z* {5 D6 v - private final MultiBufferSource source;' X( x A* B- B1 v. T3 ^, R
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 n& a# j/ N$ c& h) W2 a& K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' I, Z7 {7 `" t( d2 B- _4 j# g
* ]# W' R0 m% m2 Q$ x- " `2 l" X' u% a# Y, V a) Z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- B n; U. i" q/ ` m - if(x1 == x2 && y1 == y2 && z1 == z2){
' J) l, y0 p& Q8 P. H+ d - return;
4 ^1 G/ m4 R$ ^( x" M9 a - }
Q2 q3 F, N& u+ Q3 p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* I0 p: y$ w4 I6 n7 x# @ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) j8 x" |% o6 @+ r8 k - }$ J% f4 C# r4 c
- pose.pushPose();
' ^/ [9 B. z5 z1 O" y; C3 _ - final int newLight = convertLight(6);
$ @" Y% A% v6 W* l - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 w1 \7 L1 S9 W5 M! T7 ?. H
- final float lineHeightSmall = (y2 - y1);1 L) [* |8 R9 J; f/ V
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( d8 c3 o/ O% }- y8 j- z, I, B, l1 [ - pose.popPose();
- } k8 r8 N3 D3 e2 Z3 A' S* A - }0 J: D( J- `, L$ f
- + C/ V1 `2 R a" q3 T6 V
- private RenderType getLayers(String texture, int light) {6 G$ S# {0 |4 o' S( j5 o4 L* U0 Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ t/ ^9 K# M1 M L! O$ w) s: f - }; s, c9 x K' \( b0 j
- % e( q" L) V$ y0 b6 e M
- private RenderType getLightTexture(ResourceLocation texture) {5 u( ^) n6 n+ s+ I# ^9 s1 S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); b. z( O* E/ H1 h0 p5 J. k- w
- }
# i5 L. O8 e4 H9 j/ w% L - & p' f* M; I% s+ X7 I& ~
- private RenderType getTexture(ResourceLocation texture) { ~8 r% Q7 r' ^% A( L! Q9 N; O
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 J+ i3 Y' N* y5 ?* M D; i - }
! X6 x1 G4 ?8 b/ f8 r6 X0 i
5 J4 M* G: a5 Q* L7 n6 Y& c- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 J/ p9 g+ D2 g: S3 q6 G
- if (cache.containsKey(identifier)) {. @/ S* ^' o a7 D! J5 o4 |
- return cache.get(identifier);
; V6 f8 _* H% w6 D% u' B - } else {
F7 r4 C1 {! {2 V - final RenderType renderLayer = supplier.get();- y# B6 m% M" a. x% t/ G% D) u# o
- cache.put(identifier, renderLayer);
9 q& d0 L& C9 \8 p! V - return renderLayer;: P7 ^) r' k9 g2 Y& U
- }* O5 I1 p( b9 f. x
- }. N2 \ [, q0 [
- }
复制代码 |
|