|
|
5 H' Y2 A( h4 w" Z3 F: I行,这个怎么样
k3 ~& m7 ~0 d+ _9 B$ X- package com.xhg78999.mtrfac.render;
7 R5 h+ F- k- ` - ) q7 q: r d+ U% `2 j5 w2 [7 {
- import com.mojang.blaze3d.vertex.PoseStack;4 u* _1 U& Z2 Y# H
- import com.mojang.blaze3d.vertex.VertexConsumer;
) c8 S+ r& p* x( h$ P; D; S1 @4 ^ - import net.minecraft.client.renderer.RenderType;
6 [; w; f _2 J3 e3 A5 a; }2 z3 n6 K - import net.minecraft.resources.ResourceLocation;
/ V: ?# V3 L0 F9 w3 T - / S1 q* k1 K. `+ \$ E2 ?0 z; O
- import java.util.*;# v/ z& a, J& r3 q
- Y2 g3 X5 ]# q0 `- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 s/ s8 ?0 b& p" V8 v. R* v
- ; c2 F. u2 g% u u v, R" e
- public class LineRender{3 l; ~4 b5 N' B% K: p- S. A
- private final PoseStack pose;
: y6 m5 ]! A) o5 W7 j9 z/ a - private final MultiBufferSource source;2 S1 s$ ]" D, U( i% U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
|, I( G! O. P! T d$ L' T- e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( \' E( O0 q% C- V, F/ ^ - 4 B5 Y' L3 i: [& V. y4 L+ W$ @
- / ?$ S* h. `( v1 O; m) K. T- _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! S4 J0 \2 E7 Y, d/ Z - if(x1 == x2 && y1 == y2 && z1 == z2){
2 u5 L& z4 W: Z# \( j2 l- \) f/ a5 f) h - return;
& @9 R* @+ f7 W7 H" j; G - }$ j/ e* h+ T s* `
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 K% X+ U- ]. X: @; k7 U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; M0 r6 n3 w$ \! N. t0 \ - }
& Q) w7 T) z7 t4 ?; G3 x7 _) j' M - pose.pushPose();
+ |7 t: ?3 \: c/ M* s- S - final int newLight = convertLight(6);* d- y& H$ B# R9 w' ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. [: N5 Y, q) @9 Z( o# e
- final float lineHeightSmall = (y2 - y1);& W, M7 |5 j- M2 B" I7 y
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 S! ~/ Q+ w7 L - pose.popPose();7 M U4 T0 e" J; r N) v
- }9 m7 w7 J' ]6 w* P0 K, g |
) B5 m- O4 F, U- private RenderType getLayers(String texture, int light) {" o" j/ L* V. P0 K
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 }1 ^6 b/ |* a( m" u6 J
- } L, F3 h' }6 b7 ?# T$ \
- b+ q8 q' I2 {! F( L* M
- private RenderType getLightTexture(ResourceLocation texture) {- K; L( m. s6 [* @! x. b* s
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
- D" a0 J; n% n! U/ x - }- t, c" [6 w) ]0 R8 f/ P+ _
- 2 W! g# U. ?) Q& w' A
- private RenderType getTexture(ResourceLocation texture) {
. W" B5 h. c2 { ]4 K - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
7 Z7 S2 M7 }) t) T/ S& i - }
5 X" f! v( r) n/ K5 R
. {5 Q& q9 K" f- S- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* g4 E: D- b2 b) Y - if (cache.containsKey(identifier)) {9 _2 z, A5 E4 X Y; P# @3 P- [; ]
- return cache.get(identifier);: B) n! G8 G x" T. }
- } else {, Y/ L4 Q, V) R- r+ G
- final RenderType renderLayer = supplier.get();8 B. s6 o" |$ O6 D0 a0 ^8 T4 S
- cache.put(identifier, renderLayer);
0 B% X9 j4 U& ]! s - return renderLayer;
5 m+ }; X4 o) [: Z* m# D! T/ K7 U - }$ [4 O) x7 k, S% C
- }
7 K# X3 G1 {+ f$ K& z3 z$ i - }
复制代码 |
|