|
|
. A/ C4 p" Q& s( F! Y0 W1 Y4 D行,这个怎么样) G7 U5 }' }5 N6 B$ ^
- package com.xhg78999.mtrfac.render;' {7 {7 @: B+ @( L5 q
2 K* D! T- v' O8 E4 @% B- import com.mojang.blaze3d.vertex.PoseStack;
9 g* A \' V8 L0 l5 V; f - import com.mojang.blaze3d.vertex.VertexConsumer;
) O7 i: X. f, J+ E$ Z6 e - import net.minecraft.client.renderer.RenderType;
% ?* q# L+ m9 b) A1 W - import net.minecraft.resources.ResourceLocation;
: B- o Z: l+ J! s, E& X1 a
) E* V2 l( q: R- import java.util.*;
! T: d8 j# ]: w0 G/ U
# w% d& K* u1 e3 w# }; ]9 B( j& v, p- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() }& ^$ t$ Y7 ]$ ?
- , F- M3 A3 d) {4 Q. S
- public class LineRender{
& g& E, \3 ^1 m) Q7 B - private final PoseStack pose;
3 C/ z6 X9 T" m: f; E7 _* J; Y& ~ - private final MultiBufferSource source;) D$ |' z& ]) l, H n% B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ J" f& l5 k8 ]. i" D/ `) _/ n8 L - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();7 F( ]; X/ z; v
, X1 x" v9 @0 `1 f7 l/ ^2 @- " N `+ }+ G( f$ ~, Z; c7 W7 S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 J) z9 v; x- g2 e f
- if(x1 == x2 && y1 == y2 && z1 == z2){3 D! A. @. N/ N. j* s, K7 N
- return;. d" @" Q6 K% Y- c X- m/ `# s
- }
" k7 F2 |% w% _6 y$ S% ? - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; e s& z4 J6 `' _ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" K8 L4 P0 r4 b( b. ~- u
- }6 w) w- u% W- f6 i" z6 K
- pose.pushPose(); [) z4 U! Q" N* _3 Z1 P
- final int newLight = convertLight(6);+ ^! t1 {7 W1 S1 z [* O+ v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; K# P* K2 w! i) a5 l2 o# |% [& N - final float lineHeightSmall = (y2 - y1);/ i% W. z' o! d; s0 {
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: ]% s, r# K* y8 ~2 y$ t
- pose.popPose();
3 O2 Q) Q; g `4 g4 u# @ - }
( a( {( ^8 R% O* Y- q
) K0 y6 {7 M7 f8 e. x R9 m( s# V1 R- private RenderType getLayers(String texture, int light) {0 J+ l! o Y- i2 O1 k: H
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 D( y, l" R |% J - }
9 R; b' y% f: p0 C: p$ e
' p% i! \% h! l; F- private RenderType getLightTexture(ResourceLocation texture) {- g$ [' X( I( o6 Q8 s% w
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 V+ G4 m. i% b: \% b5 V5 L: P
- }
& ~, \* ^0 Y; s- }- V8 {! \
# m4 X G0 ]& F2 Z2 w- private RenderType getTexture(ResourceLocation texture) {5 v7 a+ E+ u4 o: h! U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 W% k" s8 e h) Q# U2 Q - }/ m$ o1 H7 ?$ R W) I
- ; l4 `0 h5 |3 e4 s# i6 Q# D
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& v i1 D9 H$ L; b" J! K - if (cache.containsKey(identifier)) {
4 {1 B$ u) _/ V2 a& s - return cache.get(identifier);, H1 l$ c: A/ D
- } else {5 ^8 b m) m9 E
- final RenderType renderLayer = supplier.get();
* _. O, U6 x3 T0 E$ r2 e - cache.put(identifier, renderLayer);2 T9 B: Q' a5 W, \0 U, G
- return renderLayer;; J% } k1 N/ {9 @1 X
- }
; {" F* a1 s/ p - }
, D7 n* A T+ v5 v( `, v9 W - }
复制代码 |
|