|
|
' a: t3 d8 ~, N: K! o1 R行,这个怎么样
/ M: T6 f; p* x( d }- package com.xhg78999.mtrfac.render;0 p3 M( Z) {( _; q9 g; E L
) f+ M1 f$ _+ k0 v, H, m- import com.mojang.blaze3d.vertex.PoseStack;( L, [( Q; _ \) s3 ^
- import com.mojang.blaze3d.vertex.VertexConsumer;; h9 o/ O. H4 J8 K# K4 s4 I
- import net.minecraft.client.renderer.RenderType;
! I/ S! R7 O0 l/ E" } - import net.minecraft.resources.ResourceLocation;
$ K6 r; F7 M9 D! o. o - * a }& P3 S/ B6 g+ e& j
- import java.util.*;+ e0 h/ F2 E! W. h# j
- 6 k; ~7 M+ G' O( q: m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* o5 ?% \1 k: n) `, S( F - 6 s) L; }" S& c. c3 @5 I3 |
- public class LineRender{
5 a2 m3 N3 O" z6 z F- K' N - private final PoseStack pose; v. v* o2 @% d/ L: ?) S+ I
- private final MultiBufferSource source;+ [* f$ ~/ t* I+ ?* l( @
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 g: |' \0 I6 T$ l/ u% W9 z7 M - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# V+ L6 M1 s* P D, o" l5 W0 e
# S6 o) T2 [6 }0 D* x2 z- 5 q$ V3 S( ?, A7 N) n7 w% E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 {0 l v. G. I. f - if(x1 == x2 && y1 == y2 && z1 == z2){5 @0 G# ]+ |, ^, f( j; E
- return;
n% K/ `% T; B3 S - }; |% Y [/ T5 u6 A" N/ U1 b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; [1 j4 s% b7 b$ k( p/ g& t
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 i5 a- @: j' i. ?, e
- }
2 e: q: v& R ^ - pose.pushPose();
# l v; Z4 D- S4 ^( a- z% ~ - final int newLight = convertLight(6);
) n3 H6 E+ z V- S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 ~+ ^; y' f6 w5 n' d$ R7 d9 @; F - final float lineHeightSmall = (y2 - y1);3 _$ }2 }0 Z% h; j7 |3 r
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( ~0 ^. _, ]2 m4 {7 ` i
- pose.popPose();
+ E4 T* H) s, b5 f5 M - }
' q5 M1 `4 Z+ f" }3 D$ E0 M
1 I L' t2 m% W# }: B& H5 w- private RenderType getLayers(String texture, int light) {
1 N: b' ^+ q! g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" l9 m) S4 x" X1 t1 a( Y - }3 e1 ~, _) G2 m g3 l
" a& d% \3 e; d% c! O- private RenderType getLightTexture(ResourceLocation texture) {! ~5 w7 F% a. T0 Y! i# A
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: L) N6 x( f0 d9 R* r# G1 Q& U5 Z _3 d - }! A8 G1 I. }0 o% F
" b$ I+ K$ @! M- private RenderType getTexture(ResourceLocation texture) {# v4 q, I' b/ e4 @4 Q- R& ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 b. E5 N z! W* _
- }" k9 P# A& J N+ ]% u
' |: L, u" X1 y# G% y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( F8 X% z% v5 F; ^$ R* s
- if (cache.containsKey(identifier)) {
4 p( s j9 I8 O6 M - return cache.get(identifier);7 _, ^5 J3 T* `
- } else {$ W& i [: z9 V. x3 u
- final RenderType renderLayer = supplier.get();
0 g+ y! K* }) M3 l - cache.put(identifier, renderLayer);$ ?" W; E7 \9 R% ]. j2 N
- return renderLayer;0 Q9 q) f2 p' w, U+ G( J
- }9 j& f0 o- S! Y Y% w: l9 l# [
- }
& W. n( D# _$ b1 P3 y - }
复制代码 |
|