|
|
0 `3 Q: G7 z8 k5 C! R行,这个怎么样
' G) F. B6 S) u# l- package com.xhg78999.mtrfac.render;
% B+ e x; P+ @ - - } {; s( |7 K) b) }; p" [6 j1 E
- import com.mojang.blaze3d.vertex.PoseStack;0 D2 D* S6 v- B1 E
- import com.mojang.blaze3d.vertex.VertexConsumer;( T4 H# F! U; d( @9 c+ ^: h
- import net.minecraft.client.renderer.RenderType;3 N% p9 h0 E2 g) o! V
- import net.minecraft.resources.ResourceLocation;* H( o0 s. x4 @/ q
- . {, p& Q) R0 u, J
- import java.util.*;
1 z2 P% q+ M) M- H
6 x, u k% S6 @- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% T6 G9 X$ P" q |1 S, H2 D* M - + O, x: J$ U: p* M; E2 n
- public class LineRender{: k9 V; t3 h/ T* C7 W
- private final PoseStack pose;! C6 v( m0 V1 p5 _" t
- private final MultiBufferSource source;
2 J$ b8 x& f9 G: I' Z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 }% N+ w' F* J) C - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ ?0 O' y. Y6 B: I
; r3 F* U4 C. |, U6 u3 E% j* y* E- 7 m+ E6 V* a9 X8 q0 d# Q
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
M$ X& ^. z$ J6 R) L( y - if(x1 == x2 && y1 == y2 && z1 == z2){: n, c8 ]& j/ e& s3 U
- return;* C1 l" f) e7 D# @
- }
7 w' c* [4 @" l - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; ~" S0 Q! m( f% I1 H* H$ P8 Y. x" s8 m
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 k- S2 W2 S+ h& M2 ^2 ~9 h" ]- T- j
- }
+ D6 D' E6 Z k" q - pose.pushPose();9 C$ _$ S" j9 {/ h0 ^2 U) v
- final int newLight = convertLight(6);4 U1 U: @9 B l- {# r
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) F" U3 {% I9 w9 Y3 W
- final float lineHeightSmall = (y2 - y1);
- i4 t/ Q0 p9 M7 o - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; C8 _4 Q0 @ S v3 u6 ]5 B( Q
- pose.popPose();
& S% P; O0 B7 h3 v9 q/ g - }4 ~5 f$ V$ w6 J4 G* d
- 6 Y$ X/ Q$ _0 }" _
- private RenderType getLayers(String texture, int light) {
4 l# f' c8 B3 Y* ?+ t3 u - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# e8 A' P4 X+ D# _: g - }
0 W8 e; m7 ~7 V( {
2 [2 e7 [/ K, s( I! T$ `- private RenderType getLightTexture(ResourceLocation texture) { r9 {# M/ x- O& K& \/ J
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);% }$ T W: s" W0 P. ~5 }
- }
9 X2 I3 E: m! |) m$ Y. w! i - 9 ~/ s6 V$ m K5 M
- private RenderType getTexture(ResourceLocation texture) {
: `" s; y5 e# A; q4 h4 @" v - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: B' F! i- _* I/ ^8 D/ p7 p - }
5 q: v+ z3 R) x4 R9 ^" I& Q3 A& | - ( d( a& t. |+ a5 {; w) V6 m- g
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 L1 A# C( Y! a3 X( r! Q" ?7 W* H" g - if (cache.containsKey(identifier)) {, l: k) m4 X' F; a( L2 g4 e
- return cache.get(identifier);
8 i$ \" e7 f& z5 ` - } else {% N7 S" @2 z) c! W8 r1 |
- final RenderType renderLayer = supplier.get();
6 T6 K ` ^6 h' r0 d - cache.put(identifier, renderLayer);) ~! m5 o% a4 m' j1 \; w9 T
- return renderLayer;+ }; v' H+ Q# C; w# o
- }
- }: [# r- y+ ~" | - }2 Q# F3 x6 h* C; t& \, O
- }
复制代码 |
|