|
|
7 L& O. g. h( U) r$ f- I! }
行,这个怎么样5 j0 H6 B, U- M
- package com.xhg78999.mtrfac.render;
, t6 q1 U \$ i6 d Q1 M$ P8 j5 J - - z7 K2 ]: k y4 i9 S6 A
- import com.mojang.blaze3d.vertex.PoseStack; a* G& [5 {! Y5 S
- import com.mojang.blaze3d.vertex.VertexConsumer;4 k* ], g( u3 d2 @3 `) R9 ~' q
- import net.minecraft.client.renderer.RenderType;# |4 C) ]* x" r$ z
- import net.minecraft.resources.ResourceLocation;4 K. Q0 k, W) A0 P' i$ R0 U- a5 E
- T2 ~$ s8 t. Y1 ]; }# y5 @' ~+ x- import java.util.*;" ?' g' M: G' q9 O; I3 P2 i
- . v% E& a& _3 R* l/ u/ L# v
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 _* M$ c" v/ }8 M2 z - : D' R- J' C% V5 ]
- public class LineRender{
6 P" ?8 S# ~. s* o/ L3 E - private final PoseStack pose;
( x. }" _ \- J8 e0 V) v - private final MultiBufferSource source;: l. O" T3 j" w$ f
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 T) [5 E! @0 z& V1 j- j9 g
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" f9 r3 z1 i/ Z" c( y: I
, E3 `& ^ Y5 D; v8 S* b3 N3 k- ]
+ v; `& E9 }( D" a- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# l/ {; P1 R- Z3 h - if(x1 == x2 && y1 == y2 && z1 == z2){
6 U3 z6 T3 s: Y/ ?: { - return;
+ D5 E( d Q6 T& ^( c* V - }: S2 ~9 l, o* W( H- W) b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# f' L9 E) l [& R - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" ^! A# F& t& T: ?, A. ~0 a+ u, z
- }
4 g% b# s: ~, A - pose.pushPose();" S: |) i/ Z" y: Z4 M5 @3 P
- final int newLight = convertLight(6); L7 P1 f4 |; B% c( T' r
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: y+ b( R/ @* O) p' i - final float lineHeightSmall = (y2 - y1);
" q+ n( }& ^ M: |! A/ x - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 O r; X4 L9 [& F' j - pose.popPose();
7 v4 ^7 Y: r, [% Q8 z% b3 R+ G$ [ - }6 N# `6 J0 A0 a0 r+ F x
! }* c! S: o, e' z3 ^- private RenderType getLayers(String texture, int light) {
0 |; N$ n8 @- M3 l! b9 @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! d' \8 i! H' M( B - }
! B4 A. t# z3 s* A o# U$ y4 B - * x5 _) O7 w& H/ j" v- u
- private RenderType getLightTexture(ResourceLocation texture) {$ y9 v& m6 s# P. \; O8 E! z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ J& H$ f S* N5 ~3 ^6 O7 I8 A - }0 L6 o- W% g* B. @! ^- e; ?
; d4 Z( A& @2 ?# V- private RenderType getTexture(ResourceLocation texture) {6 z/ t5 T, [9 g& e2 C! X v
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 s1 N5 M+ m7 M8 n' P - }
8 V4 h, Q$ ^5 S - 5 E- E& v2 w) k, Y8 }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: d$ y* \( t# t - if (cache.containsKey(identifier)) {3 Q: v- H; P, ^4 J9 x1 _
- return cache.get(identifier);
' Y9 O# v- u: F( }( K0 z - } else {
0 U0 k7 X1 Z1 y* } - final RenderType renderLayer = supplier.get();
0 w q) L' I1 k' w( W. S$ M* I - cache.put(identifier, renderLayer);! j5 \3 K, ], }; d X* I
- return renderLayer;
' n* a9 C0 ]9 q) S - }
0 _0 U) ?4 Q0 Y! e+ s& }% t% y - }
! X' G+ c0 H5 J. k3 E% T - }
复制代码 |
|