|
|
" s% {9 C7 v% |; k2 g; g6 C. p1 _/ Z行,这个怎么样
6 @) |4 W, Z: Y8 z+ Y- package com.xhg78999.mtrfac.render;
5 L+ H5 i+ |7 ? - - F) |0 c4 n' j) _" ~9 Z$ @
- import com.mojang.blaze3d.vertex.PoseStack;8 V# E7 {, \: q3 ?: j1 S. q
- import com.mojang.blaze3d.vertex.VertexConsumer;/ v+ {" t. r M% ~
- import net.minecraft.client.renderer.RenderType;
, I. X, C9 M" M$ o5 e - import net.minecraft.resources.ResourceLocation;
7 H7 D6 [6 @% B
* G; T( K- x- q5 |6 `" b- import java.util.*;
; ^1 o+ h$ s7 a7 N! G - - t" S% \2 l) t4 T" I. d
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* o- k; y. x4 E3 Q K; v
- + M6 v- P1 r+ P( e L4 ?
- public class LineRender{
6 e5 K2 l/ w( ~- ^+ W9 r, u1 L - private final PoseStack pose;9 f1 g5 @6 L& V& w. V3 ]
- private final MultiBufferSource source;
9 D$ E4 T4 _2 a: j( L* L - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
B7 F; W9 b1 f+ K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) A* | C9 [" B7 ^5 Q( c - 7 e8 j6 E' R7 G& a! D. \6 c
- , F3 \8 v4 O" F8 T* E% A
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ V% S8 M; r4 I* z( t: l- I
- if(x1 == x2 && y1 == y2 && z1 == z2){- k6 B% }! Z/ Z, I( I4 q
- return;& D4 p7 n- e/ w( u
- }
% f0 |; N" o* l - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 s3 E0 ~$ A. a) R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ p: A& r+ N& O1 M+ P L% R* o: A - }
: _$ l# g3 a; E3 n: ~) ~ - pose.pushPose();- k* ?$ v3 y* e4 z+ O+ @7 i
- final int newLight = convertLight(6);4 ?( O r+ \' E w: Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ f5 L; V. Q$ g) W - final float lineHeightSmall = (y2 - y1);
& H' z) v0 u0 l3 C! ?7 q; A - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 A+ O7 V% C0 l ] P - pose.popPose();3 z8 i% O# T" o( A/ t
- }8 Z" C/ X2 R3 r+ X; h9 M
; ?' m3 U' e9 j0 b* m. H- K: b- private RenderType getLayers(String texture, int light) {
' _. O5 s6 b% ?+ A( f - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- ]! E; p1 |& \- x5 l {! F+ { J5 ?
- }
6 f6 ~! E& Z8 t, M; s4 `0 Q8 ~" m( @; X
6 Q& \; i, Z0 b5 |* j' \- private RenderType getLightTexture(ResourceLocation texture) { {! T! z% X* @, e2 o5 h
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 r6 M+ j: p; p# g5 z - }
3 w* {2 E( C2 |4 a6 q - 9 K o4 j4 `7 p+ Z/ T9 X' p! x
- private RenderType getTexture(ResourceLocation texture) {
' E m" J- u* i# ~+ E3 \ v7 u - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! J# l( o& H) c+ X - }& j$ A7 B+ l$ z- _
2 N' O3 J4 q$ W# E6 f% R& Z( J& b4 O; x- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 o# `' z" [0 ^
- if (cache.containsKey(identifier)) {
E$ ?' t1 `, a - return cache.get(identifier);+ y L" a- I/ R S
- } else {: d& t* y5 G! w4 S
- final RenderType renderLayer = supplier.get();
0 s( N/ a9 } D2 r$ _ - cache.put(identifier, renderLayer);; D( p5 m+ n+ \ R) d
- return renderLayer;0 Q) \& d% R! E @4 w
- }0 ]* A2 P6 _" c* F
- }
2 U! V, p, M4 J4 |( H t2 s - }
复制代码 |
|