|
|
3 w. }% \; a) K, ~. `) c
行,这个怎么样
# s; b* a1 ]' N5 s- package com.xhg78999.mtrfac.render;: ?0 r. @5 m# C5 m: x+ C q
- ! ^. ^: x; I) K0 w
- import com.mojang.blaze3d.vertex.PoseStack;
! y, v( N. ]5 ^, |0 d! j" L! H - import com.mojang.blaze3d.vertex.VertexConsumer;+ t. u2 S2 {& O! |0 n" c6 R" G9 H! a
- import net.minecraft.client.renderer.RenderType;
$ S$ @6 R. Q( {( ?9 n% o7 \: a - import net.minecraft.resources.ResourceLocation;& u, n/ `& N) p9 A) t2 o( g. d+ j
- * f& H3 z1 k9 H* z
- import java.util.*;4 _! ~% ^ M4 z/ s8 z. J- p
- 1 g# }& s' j; P9 z9 O: Z5 X
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 z5 [) u- y$ }' n: m, R
$ J+ G& M! N& X( D& K* s9 C- public class LineRender{: P: X- P1 \) G' M" E
- private final PoseStack pose;
0 P" e; F8 A( F, T: K# E - private final MultiBufferSource source;
* X% A9 j3 ?5 x! i - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ `. y/ K0 u) H# {) t: e3 A& ^" _) h" [ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 ]' x& l% t" x' h$ o - . S$ t5 E5 F" o& V2 D+ V
2 O6 M( x: H3 [* ~& [/ v- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 v% R" ~1 { E' j% a: ~ - if(x1 == x2 && y1 == y2 && z1 == z2){/ N: t& v- t0 R0 s
- return;4 R+ z% `) R) Q% P( w
- }
( C% f' { _' E9 R( |+ ? - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& ?* d- B* g) c2 Y, _* P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 d5 d7 U- h* R) \
- }+ M3 m4 A. m. v0 A& R
- pose.pushPose();
% M3 T0 R% @; y - final int newLight = convertLight(6);0 ?0 b9 m6 e( q ?" r! n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 q0 k+ y; I( w0 i - final float lineHeightSmall = (y2 - y1);# k$ A. |( M+ q0 b) W1 B
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 n- k8 W C9 g) Y( i
- pose.popPose(); t+ x$ g \1 o" V( ^& ~
- }
4 O8 M! A% S- g% r2 f ?& S7 m - 6 n( \/ h- y* O8 U6 J
- private RenderType getLayers(String texture, int light) {
5 @* n$ T6 R. o3 y4 D0 ^! O - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 i& Y* e z) v: v1 W# K/ y6 t
- }( {5 X3 f) w$ j7 s \' Z
- # ~" m# W6 z" a( _5 c8 n; z2 m( U
- private RenderType getLightTexture(ResourceLocation texture) {
' k1 d0 U0 D# s2 C. A* H3 G* g/ N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 l. w5 v8 @9 _6 @0 }& U
- }
3 M' I! g" H# C# X - 1 {3 a9 D1 o# y/ ^. U" t b
- private RenderType getTexture(ResourceLocation texture) {
" a/ ]' j1 _4 w0 a. ~& [0 u - return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 _0 ? ]# ^- q* v9 n
- }( ?$ ?; h2 k; V; o
- 8 `5 J& f. C* W# k# k6 g. b2 \9 L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 |$ C' M. S7 ]$ A
- if (cache.containsKey(identifier)) {
4 ^3 V4 e/ I5 w2 y8 V! C9 \ - return cache.get(identifier);
& o+ X- F& _9 o8 j! B4 P8 v - } else {3 g0 G# {3 E7 e5 C- A! o
- final RenderType renderLayer = supplier.get();
) {( q6 R6 ]& s3 Z - cache.put(identifier, renderLayer);9 A4 `8 Z) g' c& g' i) o# O" p
- return renderLayer;
1 a9 Y1 K1 i. k2 H: J - }
) _7 q9 u( n' v1 F' @/ V, y, f - }
6 z* l. w: H8 J- n: I5 c - }
复制代码 |
|