|
|
# i% z" v; c4 Q" Y2 b
行,这个怎么样7 E* p* @4 Y8 ^1 f, @8 {$ k
- package com.xhg78999.mtrfac.render;
& X) b8 F- t6 H8 T
" t( }6 e ?" a" ?' S- import com.mojang.blaze3d.vertex.PoseStack;
) _, {* C$ e0 o7 }9 f3 U* f - import com.mojang.blaze3d.vertex.VertexConsumer;$ O9 M5 ~3 N% d4 @( R- M" G( a
- import net.minecraft.client.renderer.RenderType;' G. G( V4 Q: P6 U6 B) u
- import net.minecraft.resources.ResourceLocation;
- Z3 m- O g0 X0 Z& X
3 J, z- a- ^2 y B- import java.util.*;# h5 c9 e4 Y. I$ {3 }- ^
f0 G. ~! E) b- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; {+ K2 h! `+ c0 }- Z- ~+ z - , H& g+ v1 E9 M( V1 O" n0 s
- public class LineRender{
* J" [1 {" _3 w. i) o - private final PoseStack pose;
, |8 a; b5 c, t6 k4 A4 c - private final MultiBufferSource source;
8 C) ?- M2 j( ^0 C+ d - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 L; Q: O5 c3 v# W8 a9 S5 H
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# j. [! m: u: u; B' M8 Y
1 V* [' l& B5 v& i; W- ' x! m: p/ p$ R: B' T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 ^3 U" x C1 I1 V( c" Y
- if(x1 == x2 && y1 == y2 && z1 == z2){
. l/ M, q$ E( K% k3 i5 ` - return; T) Z# q% l( c7 r! |+ ~3 ?
- }
: `7 c2 ]) ]- m% Z! W - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){4 a# x P/ H; G x& S4 L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 V; j7 ~% W8 F1 q+ P) r$ W' o
- }9 }2 }5 U, u. O' G
- pose.pushPose();
! {6 J3 R9 l0 R2 I5 X; o2 p1 b# u5 [ - final int newLight = convertLight(6);
2 T( ~7 ]+ V) s5 { g - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: B K1 \" K( F' r. C, ] - final float lineHeightSmall = (y2 - y1);
4 m4 E5 C8 ?' W, O - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, I% U+ H2 Q3 R& p- j$ ~ - pose.popPose();6 z1 X2 e% m# n6 W4 T( R
- }% u: G7 G0 H8 H* Y
- & f% z& t! E* H; |5 D7 D/ ^: x
- private RenderType getLayers(String texture, int light) {; m' |) H* p, l2 a- P4 i
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 u' E, c1 ]! p5 h - }
& O3 |9 \8 u& q; t5 g( A3 `( S - ' O6 m* d) M( M9 t, {+ R
- private RenderType getLightTexture(ResourceLocation texture) {9 W0 C0 T9 [5 q, L, `; ]
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' ]6 t* f) r4 I: Z: ~ - }& g1 f+ V7 w! R: a9 M
' t- d9 R# t6 S% s$ x- t- private RenderType getTexture(ResourceLocation texture) {
% {$ g% @7 Q( p5 ^/ E - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- k4 e1 z# Q$ ^, O" G* |! u' _ - }
5 u9 C. y# L9 j; X% O1 l: A
" |) g4 U' E7 \% j8 w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 V6 S% ]# S' n+ T* F q2 [. Z$ X - if (cache.containsKey(identifier)) {# q( H2 z! _ U0 F \
- return cache.get(identifier);
Z3 L+ X' ~( R# r7 v1 | - } else {: O7 t8 a# H- H4 Y) e+ X* D/ |$ l7 O
- final RenderType renderLayer = supplier.get();1 S6 a- n5 f$ n4 I$ U- G$ b$ W
- cache.put(identifier, renderLayer);0 O: Y2 A3 }3 l: R
- return renderLayer;
7 z% D7 d4 W# y2 C - }( T0 ^; {2 `2 Y6 A" F: a6 b
- }* Q" h3 r2 e, @8 b8 v
- }
复制代码 |
|