|
|
! |( v1 ~; d' F& Q' ~9 w8 N1 B- Y( q行,这个怎么样
v. z7 ^3 m8 M8 x) q- package com.xhg78999.mtrfac.render;
6 ^' ~. Y, d4 B: M* f# x - " ]1 e" B4 }" ~! ^
- import com.mojang.blaze3d.vertex.PoseStack;
% v6 R$ \- \' K, u5 M, [ - import com.mojang.blaze3d.vertex.VertexConsumer;1 i9 f1 }4 h1 l0 J+ o
- import net.minecraft.client.renderer.RenderType;
' ~. U; R4 e4 a5 A( f/ { - import net.minecraft.resources.ResourceLocation;
/ p, ?, B; x7 y1 Y+ G
3 u& u+ E6 s& K% C- import java.util.*;1 q" b( D6 k, S3 w2 N
- * a/ C4 j2 T# A, D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ O; W1 W6 Q" a U2 ^
- / O7 }* [4 m; N5 n" a7 f5 f
- public class LineRender{4 Y" `( j# \* R% Y' h& E: v# E- a
- private final PoseStack pose;
( f p) o/ B; g* k! s0 A - private final MultiBufferSource source;7 _* h* l$ u1 I/ H. x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- G1 J7 o6 q* N- Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# l- ]7 f5 ?7 ~6 A1 I% @5 S
6 K: ?* l- i) m9 q& a8 ^+ K5 L- - j# N$ C; ~9 |; ^+ e! G. L% }7 _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 E0 s) b! t. B8 K
- if(x1 == x2 && y1 == y2 && z1 == z2){/ @+ `! U$ C K, b: \2 T) E) u
- return;
( q: d( J+ Z0 e8 x+ \ - }# l; s& O& B7 J' j
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 M4 ~7 _+ n' L6 T - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- A3 `2 E& @* ]: G - }
2 d7 d5 D2 d; K* _" i - pose.pushPose();0 L: K9 U4 Z1 b- t- w3 C' g
- final int newLight = convertLight(6);
$ s* h6 J( @3 s) q3 C( z - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ y" f* c- b, D. p) s
- final float lineHeightSmall = (y2 - y1);$ @8 s) Y( s# p
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( d! k3 ]" V6 B( s1 {% A
- pose.popPose();
- j2 x( e6 `/ d0 y - }
) r# W+ S$ v; g9 c0 i - 5 B8 _# B2 O0 f/ e0 C# X9 d0 r
- private RenderType getLayers(String texture, int light) {
9 H3 c( y$ ~) P! B z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; |- x/ U) s5 o( g
- }
$ P1 P% \6 k7 x- r3 G. L1 y# e
7 @* ?: m- {, u; ^- private RenderType getLightTexture(ResourceLocation texture) {% K3 N9 S+ N/ t) P- p1 r, p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; a9 C$ H1 U. u% E7 k - }
% e, S* |3 y* q' k3 X4 U0 @" y3 u - : _8 v8 @$ T. J; Z
- private RenderType getTexture(ResourceLocation texture) {- \8 i4 t& T% b2 _7 X5 l) [
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);/ v& O7 P) H; Y, h( z
- }# q# B) K% p* x$ P6 \& t
- ' H5 o1 }3 l$ C7 V y% B9 r J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 H# d+ K1 W6 s3 ?, _3 C: W7 N# R" Y - if (cache.containsKey(identifier)) {
5 u3 n- @; h+ _ - return cache.get(identifier);
9 J; z6 O2 M8 ~4 Z `& { - } else {
- Z: ?* h) A V+ p' _9 N/ R# T - final RenderType renderLayer = supplier.get();9 V; t8 o/ Z2 W* j
- cache.put(identifier, renderLayer);
3 W2 d; w* P- H% ~: g8 B+ W - return renderLayer;
" Z; L5 w, h% f% k - }$ U" x& b/ N& M( G/ s, r% G# ^
- }3 l, X0 o$ `# M1 C; k! c5 l
- }
复制代码 |
|