|
+ f) P7 v: ^$ q行,这个怎么样
- y' _9 u r( ^" _; M, ?- package com.xhg78999.mtrfac.render;
9 Q8 _0 y! h# q - " ^/ D3 A3 A2 ~9 R4 B# m
- import com.mojang.blaze3d.vertex.PoseStack;" g4 R W' {6 @9 @+ P
- import com.mojang.blaze3d.vertex.VertexConsumer;; Q$ n; r A! }. q' G- T
- import net.minecraft.client.renderer.RenderType;6 Y% N" d) U# @& g& F
- import net.minecraft.resources.ResourceLocation;/ u$ k y d" G7 ~
4 d! y$ X' u5 O. S- import java.util.*;, E, l* k( {5 h; \$ p. E. l k$ B
9 d5 H9 X( W* o0 s" P; V, R, v$ Z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& T, N! ?+ y0 u# f5 m" t; i - 3 @5 a! |- h* E# X- D
- public class LineRender{ |* ?+ j/ B6 |$ T+ q
- private final PoseStack pose;0 r; C: q: I) l5 R% ] A" m
- private final MultiBufferSource source;; K+ t5 p6 }6 |$ A( P' v
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();; o8 ^" ~ i" e' g/ O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 n5 d/ E a8 u
1 n7 S! O. f* N- t# @ c! i. V: U- " S6 {. e( S6 y6 M8 A! _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 |7 Y1 H4 X5 V6 N' P - if(x1 == x2 && y1 == y2 && z1 == z2){. S, q v; l3 F. y6 `
- return;
1 m7 X) P8 E$ N* C1 ]5 C- s U - }
8 j. D9 E( H7 W$ b. n j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
e, d( g0 A W. h& Q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. Q9 n; i- {4 e& G* B+ { - }
& Y( r& ?( T0 n% e6 h; S) }6 y - pose.pushPose();
$ `- m4 s/ H' d. U c* ? - final int newLight = convertLight(6);
3 y: \; n2 a5 x }& g# ]: G" H( t5 T# V - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* j/ J8 _. \2 g; H - final float lineHeightSmall = (y2 - y1);
9 W; U! T: v6 z4 C6 a8 |4 a* |/ { - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" Z0 ]# k: ^' R5 W3 f9 t - pose.popPose();
3 d! g0 D7 t0 e- g+ H - }* Z& G" C) Q. W' a. f
) N, R- c# `8 r! r: m0 Q- private RenderType getLayers(String texture, int light) {
( @6 E7 M& i7 i6 J1 y* R - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 u6 s+ B( L! H) i0 ^9 c3 r
- }0 V2 G2 M5 i# h5 ~
4 p; b+ ?( n/ f- private RenderType getLightTexture(ResourceLocation texture) {
8 B# ?6 W, ?4 R - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' Q9 J* S. U+ E$ u, g - }- j' d, q! e/ l. R# K: u2 r( l
+ [4 a3 d+ Z5 E y5 ]& O- private RenderType getTexture(ResourceLocation texture) {5 w; l6 k5 z0 K N6 E' _1 s
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# x+ X. i/ _$ k( T& n$ Z( H - }" @3 R% `3 L' b1 p+ A5 l, d8 S
- ' R4 F% x. ?$ `- G7 B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 l. ^. u, M$ X3 U- U' R$ v
- if (cache.containsKey(identifier)) {
) x3 {2 R) b: [4 z! B, i - return cache.get(identifier);
/ t' a7 a) k8 e. d6 w8 _6 G) L - } else {
* F6 d, k4 c5 T) P# F0 _! W. O - final RenderType renderLayer = supplier.get();0 f3 F* H$ J1 z8 j6 P6 I
- cache.put(identifier, renderLayer);
1 _( N a; { @: L0 \6 w( ?+ H - return renderLayer;' A, E$ p; J" W& x+ {7 H
- }% a4 P! H+ R, R- `2 \
- }$ V4 S; c6 L+ L% m
- }
复制代码 |
|