|
|
' w Y! A3 U2 _6 c1 F/ _5 p& v3 G5 }
行,这个怎么样
* \. c7 n$ ]3 X/ ^8 M1 e: V- package com.xhg78999.mtrfac.render;/ W9 {9 A4 n+ |8 _6 z
1 u) X$ ]: ^& }: h& R- import com.mojang.blaze3d.vertex.PoseStack;
+ G; ~: n j" p* X1 c; G1 x0 h - import com.mojang.blaze3d.vertex.VertexConsumer;# _: C; u; b( T
- import net.minecraft.client.renderer.RenderType;
+ v, i0 B* ]1 K1 T - import net.minecraft.resources.ResourceLocation;
: i& w9 x$ ^' W
$ z) |% v0 d1 N- import java.util.*;8 n' Y4 ]4 P O& g! f5 H( g
- 9 [3 [. r; x* {" @% C# ]
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: X6 [6 _$ U; U9 p E" O
. U% B$ ]4 P% W$ [# M- public class LineRender{4 a( Y& K7 N( i' g! M/ o7 j7 D
- private final PoseStack pose;
+ P& ?( a$ c9 q: W O - private final MultiBufferSource source;
- y. u2 }/ L* q2 q& ?& q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
6 ~, ?; l/ `4 C/ `4 D - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( A7 r6 ?4 _" z; }' b+ M! F7 }; w
- 4 @1 R( W- l- _5 o1 ?, |
- , D; N# S. `8 O% w$ }5 J0 }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 f# q& C! T3 C- x! \% X3 R - if(x1 == x2 && y1 == y2 && z1 == z2){3 w+ v9 U& M! U7 A2 |, ^/ o
- return;
8 C$ C- g7 N& U% O# m1 i2 \# Q - }
$ P8 n9 {: e6 u6 K - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){+ W9 H0 y+ B9 m7 b3 |3 E
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");0 ^6 r$ f) ?" g& f
- }2 Z) H, h+ m% c2 E8 ^4 U
- pose.pushPose();
h# ?: I4 V( V/ `) {7 ] - final int newLight = convertLight(6);
) @6 a$ G9 G) k4 ~3 U4 G, P - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ [) \( a7 a# d6 C7 t% e
- final float lineHeightSmall = (y2 - y1);
2 t3 {( N) p% d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; m" c) w$ {( c* i3 D0 E - pose.popPose();2 {* {* q6 W& [+ q+ C
- }
! h' O' A2 e4 M6 T - 1 T1 L6 ~ o. l( t0 c
- private RenderType getLayers(String texture, int light) {
z* x; p+ V; a1 P - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, ? U4 S/ h4 E: \! n
- }' E- `) |( J6 f3 U0 ?5 N
8 L- U" ? ^* w4 ]9 s- private RenderType getLightTexture(ResourceLocation texture) {
3 B/ S1 e9 A6 U4 E' H5 i5 u& t - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 i( m+ @7 H' V - }
$ N, X+ M0 Y7 [+ {# b- r
) D+ K" g; d9 z* { B$ f- private RenderType getTexture(ResourceLocation texture) {
/ |6 E/ Z. q/ R) E& p$ p - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 v2 k- b2 f8 V+ m6 v3 y - }
: w2 L2 N9 k; ?7 U, b - 9 M% N" Z9 l w& E* {
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ l# ]0 |6 _+ m. U - if (cache.containsKey(identifier)) {, m& h. r6 y/ a& }& p
- return cache.get(identifier);
! [$ |' D0 {; l# d - } else {
% T) b( X& Q, G9 ` - final RenderType renderLayer = supplier.get();
/ J% ]+ U7 _5 A0 {. q - cache.put(identifier, renderLayer);
7 N( ?, i2 @* F* a5 d* ` - return renderLayer;. j4 G2 w0 N4 |; D& d
- }( }: R# C/ d9 \
- }
# F- X$ L, D2 M" U0 A - }
复制代码 |
|