|
|
& P( ?3 J, a/ W e; G8 l: p
行,这个怎么样) E+ |/ U E1 }1 ]
- package com.xhg78999.mtrfac.render;9 K$ q5 ] U, a% e/ u
& G" F+ E7 ^) w- import com.mojang.blaze3d.vertex.PoseStack;: e& t/ x& t$ b8 u0 N
- import com.mojang.blaze3d.vertex.VertexConsumer;! Y: ^# D, _" X- L1 R- R, Z8 p9 L
- import net.minecraft.client.renderer.RenderType;. b! L/ V/ ^4 ]% f/ k! w: }
- import net.minecraft.resources.ResourceLocation;
t9 N7 q. @9 p. T% W
7 K4 j8 i7 E. L/ Z( \ u( k! r) b# k- import java.util.*; E% [" V0 ~1 G0 U) g
A/ W& `" b) F* Y. @- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 ~5 E* J S- p
0 C9 \. Q2 s' X- r# Z$ n2 u- public class LineRender{0 @1 I5 n( b6 K# ?. E' ?' ^
- private final PoseStack pose;
# }$ c8 d0 i* \' L) [4 t - private final MultiBufferSource source;& m6 U3 Y4 ?% A) e+ _" T, ~
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# F5 Q$ Z$ t. _1 V - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 f' k; X+ j/ h& F
; {: o& O1 w! u- 2 B$ G% S$ A9 U0 v+ p$ n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! I3 J* Y, |6 {8 W4 G - if(x1 == x2 && y1 == y2 && z1 == z2){
6 {& h3 b9 t" o7 d! D. z - return; |, ?5 @1 b, ^4 ~, q
- }
$ l- _" q+ P: z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ `) q" S5 U! N0 m - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 h- \2 [% k. j/ |; o% r& o
- }1 K" H2 S: Z1 Y4 @5 I4 D' v
- pose.pushPose();
1 ~7 G- |* L6 P2 c* G - final int newLight = convertLight(6);
Z o; d' K1 L7 I; S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
& l2 b5 s# k8 y1 }) {6 v7 X+ R. [ - final float lineHeightSmall = (y2 - y1);
$ E8 x/ w$ ]) W+ Y' l m0 Z! r f - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 h* ^2 t5 r& V B+ l
- pose.popPose();
; o0 N# k8 E# p% K9 M2 G3 w - }* H, V l# T; y0 T4 W1 g" X
0 u& Q9 |4 X/ H3 j$ r# I5 n6 s- private RenderType getLayers(String texture, int light) {7 S7 ]$ ]4 C3 u x Q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 ]9 W8 w% Q- ?7 e - }! K# m O7 I" P/ N
- 9 d6 B6 z! U* q+ h* L
- private RenderType getLightTexture(ResourceLocation texture) {
% o2 _, T5 `: a5 W1 J2 E) F+ ] - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 i% M5 K4 x2 @# y3 P" p" n: b
- }# u& w, D8 H. ^3 d
1 P6 S9 U+ \/ J9 q1 \! s- private RenderType getTexture(ResourceLocation texture) {( @, \$ i# b- v( C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& [* Q, C m3 F - }
# w k7 N9 Q3 x. z8 Y
c4 L5 s8 A2 o8 K# w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) n3 G; _. N. v( s/ h' P - if (cache.containsKey(identifier)) { X/ ]% Q/ K% f( e8 _& v
- return cache.get(identifier);
" e- f$ p n% h# t& x# h8 F( a - } else {
; U* c2 N9 b) ^1 @: p, s6 | - final RenderType renderLayer = supplier.get();
% P: {/ T! a5 v. W" {) r% G9 D - cache.put(identifier, renderLayer); f! b. j7 e6 P
- return renderLayer;" N) t- v5 d& I9 g, {- [
- }
7 `$ Z" r! J' f1 P/ q: A, M% X, ? - }0 s7 h6 n5 A8 `9 h) Y* Q
- }
复制代码 |
|