|
|
) o! }3 F* D. R, |) y; Q行,这个怎么样) f0 N' s$ K+ Y
- package com.xhg78999.mtrfac.render;5 R2 f% l( r% H: ~+ o
- # ~. q3 `& l# I
- import com.mojang.blaze3d.vertex.PoseStack;
9 E" Q6 p0 B4 M - import com.mojang.blaze3d.vertex.VertexConsumer;# g0 U' Q: p5 H7 o Q" @$ b( M: o1 _
- import net.minecraft.client.renderer.RenderType;- N, r+ i2 ]1 S8 B+ A/ ~
- import net.minecraft.resources.ResourceLocation;. G* J$ ]5 z: d
- ; a* d4 f+ G+ ~3 T' N0 G( _7 E" n
- import java.util.*;
3 P1 ^1 H( X) a' i, a( O0 g$ w
4 b) B0 r+ l5 q5 D+ i' ~) y% @- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 M! U" E. w# I1 M9 t' I! F - / }" V* E. h# v4 @: R
- public class LineRender{
0 a& e" W& O7 H: A! d2 `! ~ - private final PoseStack pose;( V; n# G1 F' `
- private final MultiBufferSource source;
8 {, }. T1 B, E( ]; B$ h - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* R$ v9 \! j" X& w% e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 X1 B; U& R* ~( G, A! V" s
" [# b" g, O# i) W3 e7 v V; ~" W2 M
, f! @2 U* M4 c& a5 D3 F- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' Z Y" \' U, @( N7 _! C) E - if(x1 == x2 && y1 == y2 && z1 == z2){
2 e% X. H0 H" `% W - return;" y9 z& f% k$ v* B. T: q* z* }
- }
m: x8 O5 u* h - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 G7 g9 c* x0 x+ r# w: c
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" ]! u6 J& x- S$ S! \. ]
- }, ~7 C0 c* f, r! j
- pose.pushPose();9 N$ Q- Q8 I; _' B$ @1 X ^4 z
- final int newLight = convertLight(6);
8 V2 P4 y, E) {: R4 F- v - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. S1 l1 Y2 }0 s [ @% n
- final float lineHeightSmall = (y2 - y1);1 b; q7 m, T) I- }9 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 g/ s5 c; ]: q8 I) D7 ~ - pose.popPose();1 J4 y$ K) ~: d6 l) U
- }
, V6 R8 b6 m1 f$ z& V
& A/ s+ O/ _$ `. T5 u- private RenderType getLayers(String texture, int light) {
: J4 e% ?8 T/ Z4 w/ e8 k( e - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
R4 Y/ P& S2 c0 Q2 k; _ - }
$ z7 C: ?2 \, |5 u: I9 R' u- |, i - 3 ~1 V) l3 |" j$ n( K
- private RenderType getLightTexture(ResourceLocation texture) {& t \- W& ^8 L% X! e2 L9 |& I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 G a" e4 s# f- |+ ?, p - }
" `( V3 S" ^! h) c+ u+ R
# j6 A" k# Q" J1 |- B- private RenderType getTexture(ResourceLocation texture) {
' s3 B# d! K' {- ]6 Y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 f8 e* u; B3 x8 e
- }8 W0 Q3 b$ U0 a% {
* S% p) T: _9 M- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# c) T4 s: \, G+ V3 x1 m - if (cache.containsKey(identifier)) {* l. o4 j8 V( n' z* E q& i2 D
- return cache.get(identifier);) [, p; k7 ^" [0 Z
- } else {
" [& ~, O, Q+ R: [ - final RenderType renderLayer = supplier.get();
) [9 @4 ~2 n" L% g5 j9 a+ ? - cache.put(identifier, renderLayer);
9 [' s: T* f7 V0 u) S3 o - return renderLayer;4 q* A+ E& p4 B! ]$ g
- }) ]8 |6 x, R( q6 Y, ?- c
- }
+ t% O7 ]- O/ u- f - }
复制代码 |
|