|
|
5 \2 w; x; d5 L+ X& g' y行,这个怎么样
% w$ i7 p5 ~/ S- package com.xhg78999.mtrfac.render;: i* W5 \2 p! r3 Q
- ' K* I! t- S; [% O
- import com.mojang.blaze3d.vertex.PoseStack;
4 z" r3 O1 K* S: v) Y8 @ - import com.mojang.blaze3d.vertex.VertexConsumer;
% i0 a/ q+ M! c. g" X - import net.minecraft.client.renderer.RenderType;7 @: k5 S; y. |: d
- import net.minecraft.resources.ResourceLocation;
$ d4 W) q3 I8 J8 Q. R# K' O# g, K
5 K3 m( j( L7 a( Y& B; `9 i- import java.util.*;
# Z1 l, B7 L! Z% g) L
( |% [, P8 t3 L8 B; Y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( k+ L3 M/ W7 ]2 k1 V8 r
+ s- b: P; H( O* L, a* b& \- public class LineRender{
' w% S( m/ M4 F! Y0 }" V - private final PoseStack pose;1 O6 z4 X# v9 G V0 k* h) c+ h# d4 d4 L
- private final MultiBufferSource source;
6 j8 u9 e0 A4 ` - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 q( l5 S3 Y' Z, p - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! k. C; x0 R, s& S- n; [
- / h2 Q+ U5 ~+ w8 V" {
5 U3 f: E, [+ b D( [. x$ l- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; j! M1 u2 L# _2 x/ _: A - if(x1 == x2 && y1 == y2 && z1 == z2){
2 }2 r/ G0 d8 [ - return;
2 E: d8 p; W; I+ |5 U+ z. E - }
, R( o4 O- h7 N' A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 {, E! ^9 m# t7 m3 V# ^# i - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); H2 g3 m6 |: _6 T; F$ H
- }
' m+ ]8 i3 Y$ h - pose.pushPose();
* _4 f+ }& }0 i - final int newLight = convertLight(6); a- O c/ J" I& L# n+ d& M
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. U/ ^ D8 K' O% h
- final float lineHeightSmall = (y2 - y1);. l8 R% ^6 K7 v! @0 e
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! [+ [4 K, e& e& c: `1 u: a - pose.popPose();+ V& u+ u5 o% N# H# x7 v: {
- }- T' @, S8 n9 |# p0 M$ i" a4 |
- 3 H$ F; {& X% n- p! @2 [
- private RenderType getLayers(String texture, int light) {
3 E. r2 J0 T& A* f' L7 Y+ Q" N: S - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 z @+ W$ z* l - }
% `* u0 S& c- i - 2 V% L1 W0 o) ]4 ]* V
- private RenderType getLightTexture(ResourceLocation texture) {
- `: e- _# d w R+ t6 ~ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, j7 W. ]. D3 o3 O8 m) |3 T
- }
& ]& q: W2 e) F+ e( ~$ e
# q3 s6 W% q$ t- f; g' d7 s- private RenderType getTexture(ResourceLocation texture) {! U: o" K9 Y' i8 y9 P$ \
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# c' g9 n- j7 i& e: T. T
- }; k) G4 p7 d Z" h Y
0 B; o6 r) w0 u( b- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! _0 t7 F- N4 v( t
- if (cache.containsKey(identifier)) {
$ u8 y* o( @3 J - return cache.get(identifier);
7 o1 ~1 L9 H9 P" s5 v - } else {
4 h6 E" K; d! t - final RenderType renderLayer = supplier.get();4 w4 h+ |" ?) y+ B$ v
- cache.put(identifier, renderLayer);
! s; C* y& U, U4 Y2 }7 D3 l" w - return renderLayer;
0 T! [( i- E0 [1 \6 G - }
( B" M/ K- a7 g! H8 M( N - }
- k4 k# } q% W, [1 p1 R) i- l - }
复制代码 |
|