|
|
+ C1 x2 {! |8 N. |4 ?- Y$ G
行,这个怎么样, \# h" H# Z. o% q- {1 A
- package com.xhg78999.mtrfac.render;
( f2 _8 Y" x3 L! k# \. d
" N7 t1 O" ], u( Z8 D! V- import com.mojang.blaze3d.vertex.PoseStack;
" Z: Q* q' Y/ d) M2 Z: C - import com.mojang.blaze3d.vertex.VertexConsumer;
/ P) k6 C5 g2 l% K5 ]3 H - import net.minecraft.client.renderer.RenderType;
- X; z0 P/ z3 q - import net.minecraft.resources.ResourceLocation;, ^/ ?, t8 C6 n6 |* ]4 X% k( i
- ' v: Y1 T: k% f. x4 J* Z) o4 o' V: l
- import java.util.*;
) ]; _( a8 M# R1 ~
% Z+ a d8 T+ m1 y# `3 c9 U5 I- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) Z: x" h! D$ _: G3 J& C - 4 D: ?8 o& f7 }" X/ u) Q2 z
- public class LineRender{' R7 T/ J, o( ]4 Q D) C3 V# l
- private final PoseStack pose;8 O. C& \( q2 G- n. H% l% A
- private final MultiBufferSource source;
" H4 ^, k% r1 `/ A6 L" } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 G! T) c! U: h8 a G - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* {. t( G1 O# j! e# G# m* d# A
! {* a0 q$ O+ Q$ j1 i& a! K; V- 9 l, @& J' ?$ p; {; N. I/ t
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: m5 o/ s. f: g5 ^% V/ I5 R - if(x1 == x2 && y1 == y2 && z1 == z2){9 T: z$ e6 T8 F( H$ y( Q1 L
- return;
0 C1 L0 w) e4 C& b$ \0 D- R4 o( R% g. a - }
6 S6 t! y# E, T% o" N - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 X: F! ?) Q' Y6 N: H2 V
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 [8 _8 H. z9 F; D( \: B+ t
- }7 V# _& e+ w2 p
- pose.pushPose();
9 u0 x3 j1 z) p - final int newLight = convertLight(6);- X! \, `" p& G( A5 \: h
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 F) a/ R$ y# ]$ w1 r1 d4 }5 X' x - final float lineHeightSmall = (y2 - y1);, g$ I" N% I. u2 q9 \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ z! E) ^3 ~; L8 P& ] - pose.popPose();" M& I0 R! A ]+ s6 ]
- }- R% i7 ]1 {% ^+ f1 f
. {: L: m- Q6 g+ G" s5 x- private RenderType getLayers(String texture, int light) {
$ P6 x$ R1 h2 h, T: ` - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# ]6 A! B9 K n
- }
* [% T+ s$ z$ x - 4 s& S0 x6 K! R: }: U; n! _0 `" Y
- private RenderType getLightTexture(ResourceLocation texture) {+ b" b4 L8 _5 Q2 e. u$ }9 o$ E6 F
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);% F* }7 }: I5 ]; B0 w# C0 R w, R
- }
& `, H! H1 t4 e8 l6 ~1 p
8 Y" l, ]1 q$ i1 q( A- private RenderType getTexture(ResourceLocation texture) {
, u' Y* y- q; k - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# I: n9 {; | e - }
; _- Z& H- [, K+ h9 w - " e3 M1 Y. `. b) l& z0 |6 Z
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 \4 }* o1 j7 y- Z# \
- if (cache.containsKey(identifier)) {
; d3 A# Y! b7 j; a3 ~4 w - return cache.get(identifier);
- A" D/ ~0 _: e2 E$ N+ A - } else {( h" Q3 s! o' B" B3 f f. R& _
- final RenderType renderLayer = supplier.get();" B' V0 f# x, q
- cache.put(identifier, renderLayer);' L% |9 f/ w3 A! r4 }
- return renderLayer;
( v: A' E, D8 O% [8 O7 o - }
$ m: R( ]8 I, q5 y% K9 B `' H - }) u& r& G8 @& d I
- }
复制代码 |
|