|
|
& H7 b( _9 O) i" H* P
行,这个怎么样
, g3 q7 t$ A! D# G- package com.xhg78999.mtrfac.render;
9 \: `2 {8 e B' P9 v" W$ ^ - ) U& E+ J& ?% B s& J1 x
- import com.mojang.blaze3d.vertex.PoseStack;
& T+ R8 ^+ b; ?) [, k - import com.mojang.blaze3d.vertex.VertexConsumer;8 ]4 \9 Q2 y. Z3 D: U4 n0 q$ k
- import net.minecraft.client.renderer.RenderType;
& B5 S+ h1 D2 I8 U - import net.minecraft.resources.ResourceLocation;
7 x0 H" L- q% B
9 o5 r! k' s/ A) [3 N" g- import java.util.*;7 S: r3 E: p1 W: L/ f3 L
- . O9 l. `$ F, \) c: p2 e: U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( \8 `/ k7 S: @+ S$ K# D
- # U# n& W6 J3 p* n% `
- public class LineRender{
* Q6 V- ^3 Q: W% z( m+ |. ^/ T - private final PoseStack pose;3 b5 T" V; d1 c$ b& S2 k
- private final MultiBufferSource source;4 ]! X: K# Z' ?5 z. v. U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 G0 l; G0 _$ p- Y+ } - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( D0 {* \2 K- r/ a - # [$ K8 B7 Q* p6 ~/ ~. j
- # L7 e' z8 N5 u F& ^
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# \1 ?3 x' w; J0 Q
- if(x1 == x2 && y1 == y2 && z1 == z2){8 K7 V6 c/ q/ |8 O4 F. Y
- return;
/ M C& P! R& u* } T; v - }
* G8 P( E T5 ]+ S1 K( ^6 l - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){+ [9 g: P* `7 {2 R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 D1 {: k* s; [5 }+ T
- }
$ _; x- u% `4 c: B" p7 l - pose.pushPose();
9 @( k+ {! H- Q4 l4 x: j2 r - final int newLight = convertLight(6);% Z+ J1 P) F: q4 M1 W0 T
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 c* g$ V. s7 W* x& L - final float lineHeightSmall = (y2 - y1);0 A( R. f+ _( A: M
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) n% {3 x5 ~2 y) t8 ^- k - pose.popPose();
- l" q0 i: f2 J$ Z - }
/ F' c# c* o7 y( c
/ L1 D x& E+ }" ]/ H- private RenderType getLayers(String texture, int light) { l0 `6 q7 a4 |5 ] g0 h( J7 P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ I' f: k' U8 m - }
0 l6 `/ }; t I% o+ j - r4 z5 w! a( Q
- private RenderType getLightTexture(ResourceLocation texture) {; X( }% ` P6 V+ J$ }! Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, S3 N5 |1 D7 b& L - }
& l }# P7 y# m: e - c% \' I6 X; i6 r2 s( e
- private RenderType getTexture(ResourceLocation texture) {7 M& ]$ d g" R3 @) S! X
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
1 x5 Z5 ?) h( e; e - }, N9 ~3 C5 Y% |1 ^2 F4 K
6 Z+ i1 z5 V" S- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, p& {. _( X/ S1 s7 A - if (cache.containsKey(identifier)) {
0 H6 z0 ^, x; z! ?! j1 r" @ - return cache.get(identifier);! v" c: E8 t: ]% Y$ W1 T; L6 }1 q
- } else {
, a3 x! Z% j) ~2 Z% K& E- N. x - final RenderType renderLayer = supplier.get();0 e$ [* Z4 o8 t% k7 ]; x2 x$ @& q6 B6 x
- cache.put(identifier, renderLayer);
1 g' j F# F- l t% h - return renderLayer;
, V( L$ [+ y0 V, x R! C - }% ]4 ]5 Y( o) g
- }
6 {5 t; U3 Y9 N) b, W# v - }
复制代码 |
|