|
|
u6 i' `+ d/ \8 x% E" G
行,这个怎么样
2 t# M1 K4 r% G- c( ^: q: ]3 ~* n- package com.xhg78999.mtrfac.render;8 I) M& z9 M2 {- m: R
- - r5 E$ d9 o' D: `3 X' c
- import com.mojang.blaze3d.vertex.PoseStack;/ y$ a, i- a( H1 l+ {
- import com.mojang.blaze3d.vertex.VertexConsumer;
- T5 O- V* l8 V- G2 t - import net.minecraft.client.renderer.RenderType;% C8 l- F8 Y* P* {
- import net.minecraft.resources.ResourceLocation;- f* A+ L1 V1 [9 a3 b
- 8 V1 G5 d- X( p* B6 @ Z! v
- import java.util.*;
% T& |- u8 B/ M8 G+ z
% a6 `* x3 T1 T, s3 S. i U. O6 q) m+ X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 D: m$ ~9 [. L+ t7 B5 p6 h
( `4 g( f; H# h% E8 W7 ~- public class LineRender{1 N7 c" c. i6 h- X. K# T' |
- private final PoseStack pose;- d. \0 c! J [% Y1 G
- private final MultiBufferSource source;
, u+ S" R2 e% ~3 ~: U - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 i& {3 E6 a8 n) ?
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 t3 V# h" O4 a" V. N- w
+ s# q+ y6 W) Y- K$ D$ v
" Q& y$ ^/ o! h- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ F% F9 H2 I y# x0 `1 ]8 K, \4 `3 Z
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 z+ m/ e6 o" K( @7 J: J - return;
$ K# v) N/ o0 o, V# c - }
- T5 V6 ~% i& k4 y2 r. ~ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% L3 f- M, C) f5 X5 Z+ I
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- R% M2 I: m( q7 E4 u U; w" I - }
+ l; _ }5 F2 ]7 N0 { - pose.pushPose();
! c- K3 }- @$ u/ Z* O& t1 z% p3 p - final int newLight = convertLight(6);, p# o3 l/ |0 v$ {* O* m% v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 k" y$ N ?: y& v5 `$ I - final float lineHeightSmall = (y2 - y1);
" y/ v# }* D/ [- Y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! H: l* t6 u2 I/ a
- pose.popPose();$ v, l+ d% ]" V& {7 W% s
- }
( |2 e! T; O; r, i) ^9 e1 t
S" B8 v/ N# a: E9 i0 Z( A- private RenderType getLayers(String texture, int light) {
' `: g( E/ D- _9 \# w( W }0 W - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ z ?: j, a6 a2 z4 |+ ~, f2 g - }
$ D; n) [- v4 n$ P: c4 p5 j r5 P
: Y: w# U6 `; V) M$ q2 J5 \# d; Y* M- private RenderType getLightTexture(ResourceLocation texture) {
8 u8 F) V7 a5 G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: f9 {- }/ O$ @# o& i8 D4 `
- }
# C7 m3 p9 l" n/ A
2 M0 m U V+ I5 U- private RenderType getTexture(ResourceLocation texture) {
5 p0 t- _' h0 v/ \7 \2 A - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 |0 M; `* g" N1 r: M. P - }
9 T4 [& m# M r% ? - : U/ A% a& S! N. A
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 J" V% \7 x+ e( {$ [/ c
- if (cache.containsKey(identifier)) {
+ f. s9 V2 s, R8 e! m - return cache.get(identifier);( S4 F @9 o/ Y5 a; ?
- } else {
) j' C; U" \- w0 |+ V% o7 l& \( E - final RenderType renderLayer = supplier.get();
+ j) J. ~# W0 Q3 S& T2 m% \! T; N2 C - cache.put(identifier, renderLayer);
4 v1 T) y1 b2 w8 t2 ^( G8 Z - return renderLayer;7 _8 V' t2 F( T+ O: a. \
- }
# s; E! O" Z9 t% W7 R0 O, F% g - }( Q6 A7 e& ~) j2 V+ }
- }
复制代码 |
|