|
|
" C3 G2 Y5 _$ R行,这个怎么样
/ M5 @7 s' X5 ]: s" `( d: V- package com.xhg78999.mtrfac.render;1 u8 y' b$ c# E, M/ b) |
# t& ?" l# n4 P; g- import com.mojang.blaze3d.vertex.PoseStack;
1 {& _' Q: j1 t( ^ - import com.mojang.blaze3d.vertex.VertexConsumer;
; C$ ~9 \- Q7 P: A - import net.minecraft.client.renderer.RenderType;: q3 R- s9 _; Z) F
- import net.minecraft.resources.ResourceLocation;
; a" P3 Z9 q( b5 @/ [8 O - ) S; g e$ j( a0 B2 o; P
- import java.util.*;6 l) r0 F3 D2 e3 v" o
& ^: h7 r4 J/ v* e$ `- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& S s. p# I( R
, E2 [$ O8 s3 y& ~6 h ?0 V; F- public class LineRender{
7 q% _. c! S8 r: M0 z! O/ z% n - private final PoseStack pose;& `3 |, Y% d% C
- private final MultiBufferSource source;' {- e" s+ e; V6 G' o: u7 V! e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( n! \3 O6 ]; @$ D9 _% }% E
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ D8 x' u3 c! f
: ^5 }' v, m; `, s- R# H* H2 ~6 n: t E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 I; I. A1 i) V1 L& M- P0 U
- if(x1 == x2 && y1 == y2 && z1 == z2){7 ?) l2 y7 N0 {/ _; }. ^
- return;) ]% d* j# } `4 u- J& {5 i
- }: g/ M, G O h
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; q6 f" E. q9 C% B; n3 ~
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 ~. G5 @( @$ `5 W* v - }
9 b/ r4 u9 S0 [, O. Q+ H" v8 Z - pose.pushPose(); I' `! f, J( c8 A, j( m
- final int newLight = convertLight(6);3 R1 J$ e! a! \2 h/ S+ f4 N
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% I" }% I6 H3 W! I
- final float lineHeightSmall = (y2 - y1);0 _; z9 {: F7 {. _) V' _2 d+ Z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 U2 d% ^# n/ Q* A1 q& S
- pose.popPose();6 m) ~. g5 ~# i# k
- }
6 P9 X2 \5 c6 z6 k+ B( h& k - 0 ?7 q! m3 M2 |( q$ t3 P, {* ?1 j
- private RenderType getLayers(String texture, int light) {
$ o& A1 c% H" S! A" Z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ X: O& c5 X3 T9 F - }( V3 s% l; ~. z. O
- * I% T6 ~4 M5 K
- private RenderType getLightTexture(ResourceLocation texture) {& ^. K: }* ]1 f) R
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); w. l* M; c4 d' L) h1 d+ [6 W7 I4 j
- }
& ^, ?& I& J& i- B: s1 K: J; X - " m8 S B3 k/ U) B P* u
- private RenderType getTexture(ResourceLocation texture) {5 K% n, e# a( X2 M" k$ f* C4 D
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 [* p# h, U# P4 _" N' E - }
8 \5 w7 ?( S) I; @: C, n: e9 S1 L - 2 w! }& d X2 P+ ~* f
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 J) ~4 _7 K- w4 _2 U! h( A - if (cache.containsKey(identifier)) {
) P5 G3 u! }& d+ O" ~8 o1 _7 m - return cache.get(identifier);
3 R" H7 ], y* ` - } else {
& X: F0 i# S) I* k8 F - final RenderType renderLayer = supplier.get();
6 d. r2 e4 I9 ^% W+ C - cache.put(identifier, renderLayer);
% `, N- x& p* ~! o" c+ j n1 g - return renderLayer;
6 x. A# k5 A+ o3 D' v - }
6 G7 j/ C0 D6 \' B - }
5 j# m$ Z% a9 {; D - }
复制代码 |
|