|
|
7 _9 {1 t+ l; A. ?# `- r
行,这个怎么样) w4 a5 |+ l- ~3 z/ `3 ?) Q
- package com.xhg78999.mtrfac.render;5 \ |2 _7 ]* [# [3 h) L+ l3 k
j" f2 d; G+ S; i8 A" G9 e' g- import com.mojang.blaze3d.vertex.PoseStack;
# y. d% a0 `3 w$ M7 n. } C - import com.mojang.blaze3d.vertex.VertexConsumer;9 _5 j' I' R& x, w& i
- import net.minecraft.client.renderer.RenderType;, a' I1 h% U$ _- ?" v3 L. a
- import net.minecraft.resources.ResourceLocation;
3 i8 x N9 I; l1 h - ! m, S0 d& L, |' d3 L
- import java.util.*;
) z& I$ n0 P- v) V- P$ s - - K( A0 I) q& j* O, L7 p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 Y: Y) P2 U: p8 m
: t) V/ H5 \0 p4 N. d- public class LineRender{
5 o5 r2 d8 }# q( L, W - private final PoseStack pose;
8 T/ T5 n7 E, `1 o7 R - private final MultiBufferSource source;
" K' C! _ p2 i! X" ^, q( p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# _, U4 O7 p) K Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 i; j- |; o: a
- ! q! V) A7 k U3 X' T
- ) x* z/ ~2 B& A
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! F1 q2 [/ q1 n4 L( g
- if(x1 == x2 && y1 == y2 && z1 == z2){% R7 w7 S# T& p( k: [4 F
- return;
3 F0 C- r5 O5 G2 q. l) d+ Z# [ - }
. C: t7 D" a* B% r" b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- i3 b9 C+ W% m. ~8 \ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
7 k: l$ R9 d c* ~4 \0 u - }* s" g, k. K' p
- pose.pushPose();( I! Z# B% G# y% d4 y) |0 i
- final int newLight = convertLight(6);# s2 a' Q& J/ U7 f1 H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));/ W$ Z5 q" C1 h& r! L
- final float lineHeightSmall = (y2 - y1);: p7 ]; H* Q" {
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); E8 R9 i$ S' T# C6 h7 k
- pose.popPose();1 t5 E9 K4 g8 f" X* l g
- }
$ ?0 `( R; b! l2 q: ^5 i1 Y7 g4 X* }
7 [; h% [$ s- m- private RenderType getLayers(String texture, int light) {- |$ @! [% s& w/ n: x
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ } \6 ]1 ^% ~" A3 @! N - }
& [& F8 z h5 W - ' y4 l- M0 A6 Q% V. J# b" q+ V
- private RenderType getLightTexture(ResourceLocation texture) {7 C# M+ H) Z8 [, H
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' U4 u, ?4 {1 i - }
' o6 w0 a: F j% A, D8 t - 7 V' b4 S; D. S% n9 ]
- private RenderType getTexture(ResourceLocation texture) {
7 I/ m+ @" f9 T; f( |* t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& U8 {; r1 a! A3 G! G' H* ` - }& Y, w$ u+ x6 U
- 8 x0 f% O3 y) f- w+ m0 B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 s( i) V1 o/ w E( d
- if (cache.containsKey(identifier)) {
' ~( z- z* W# g% U9 N% f - return cache.get(identifier);
8 Y w$ S! W+ w$ q8 `" Z - } else {
+ m8 b3 K) W" g; ?+ ] - final RenderType renderLayer = supplier.get();( E& z) B6 O( D3 W/ g. v
- cache.put(identifier, renderLayer);; c6 q4 p7 L' ]! s* s; _0 [ G
- return renderLayer;% X, i1 W9 |5 ]8 A& A
- }
& e- a8 D" E/ W: a: c2 F* W - }! E3 a, Y0 l$ A( [
- }
复制代码 |
|