|
|
+ l& J( q/ w% f7 I2 Y+ f
行,这个怎么样
& U3 C$ Q9 w1 V! j& b- package com.xhg78999.mtrfac.render;
, G7 d! Y/ W3 q) e - # U! P, `# g3 ~5 X3 l9 T# |
- import com.mojang.blaze3d.vertex.PoseStack;* V' V' P: h: i/ a
- import com.mojang.blaze3d.vertex.VertexConsumer;7 P+ u- D B* D/ ~
- import net.minecraft.client.renderer.RenderType;
( R, R/ [, o M" Y* ]7 r9 e# h. a - import net.minecraft.resources.ResourceLocation;
. M; m0 o; \$ t* O, u
' U4 k0 j& q$ k- import java.util.*;
0 i% J$ m; |$ A$ l, v0 H0 Q - + v" B ?+ r4 K, _0 r5 f0 |
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: {* T3 n8 g+ v9 e+ W6 a2 r - 0 f, Q6 {2 C1 l' N( e! x9 b
- public class LineRender{8 L& ]0 @7 P0 `
- private final PoseStack pose;
; ]$ q+ y1 h* V9 O- F) B - private final MultiBufferSource source;2 Y$ l3 `# ?1 e* N5 G. S, I
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* L% Y# \2 a3 }9 P - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 a- D6 j |- C+ F! |/ |/ \1 g" B) c! _
9 }" Q7 D: t5 U' N: w/ l% M0 b- ' w9 S" _9 a. g' a$ S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) Q, X) a+ |; Q# u' ^1 f, i - if(x1 == x2 && y1 == y2 && z1 == z2){
# I [+ V( }8 `7 [) b. c( d - return;' G; F1 _6 F2 {- T* M9 X
- }
) ~6 |) [; i1 Z, M9 H0 ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* T& P$ I G6 Z* K3 ]3 `) e+ N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 ?! B9 A; p! r - }
! Q8 X- ]' N$ n# b' Z3 @ - pose.pushPose();
4 {3 y/ R% O$ J/ e/ |/ D - final int newLight = convertLight(6);
6 n0 q: N$ c1 j7 N6 M1 } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 a3 h. {0 S5 ^9 D
- final float lineHeightSmall = (y2 - y1);
$ @8 H3 W8 u% T; Q6 T& C0 q: ^, w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 f- k: w' S8 [& e5 A - pose.popPose();0 X2 R! w8 t' x% h3 M
- }
3 X, s1 c! u4 ~( J$ z3 T
r3 F* l4 R2 H0 D& Q- private RenderType getLayers(String texture, int light) {6 I& G1 z" c! \/ U6 |3 s, g
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ N( z$ {! [/ R3 Z
- }( S0 h5 v X; b8 ~
q7 D$ m3 ]( M u" [9 D9 |- private RenderType getLightTexture(ResourceLocation texture) {
( ]; V; W( m q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);# N) r1 z1 }1 H" H, K5 p* K+ B$ B
- }
* F% A3 J5 Y: `) L9 i' T" E
3 k7 ]. I4 U" [7 ?5 b1 u0 J; U- private RenderType getTexture(ResourceLocation texture) {
! r* ]" Z X+ h - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' i$ S4 G* p# v& a2 V# |3 U - }
5 v7 ?' E8 J- X3 X0 e
# f2 Q; _( z7 q, _& v- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 q, \4 z+ B8 p% D - if (cache.containsKey(identifier)) {
7 D9 D& u" S1 h& E6 I' w: D I. q8 S - return cache.get(identifier);6 @( k1 O7 x$ M4 O- Q
- } else {
" t3 b% o% `* Y T - final RenderType renderLayer = supplier.get();
: P( S6 w: L6 x q/ [# ?; N - cache.put(identifier, renderLayer);8 R3 E# a8 z( W) b- g$ ^# V/ v
- return renderLayer;( h. [# I! R' a! ]6 x4 y
- }) x0 \- v# v! R4 \
- }; s$ N) _3 J5 @3 R; E- W) l( a
- }
复制代码 |
|