|
|
% x' d2 A) @8 t
行,这个怎么样
1 h' ]1 n6 [6 w/ y3 e- package com.xhg78999.mtrfac.render;
& R: v0 S& F2 A5 s
( N- B/ s3 O: o5 g- import com.mojang.blaze3d.vertex.PoseStack;3 r/ K- k+ q- C# }* c
- import com.mojang.blaze3d.vertex.VertexConsumer;
, n5 I! r% t, G5 ?! Y; f9 y- W - import net.minecraft.client.renderer.RenderType;
. S+ R. Y' Q$ u: u7 o. O: ? - import net.minecraft.resources.ResourceLocation;
7 ~' \$ h' L* Q- r
% c$ P4 N- ?/ C% s, U( N4 k, C- import java.util.*;+ Y: X. t4 i9 g" ~
. }, W- W+ o) \5 j% j7 ]& U8 ~- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* `2 Q$ K6 E9 B7 U5 A; j$ ^ - + Y3 L& r, N2 t9 d1 n0 G
- public class LineRender{4 e% G/ I, ]9 o! a
- private final PoseStack pose;
& y& v4 f& o) K" Y9 G! H - private final MultiBufferSource source;3 ?5 v* _( q' e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* C0 o2 m# r* n5 d" h6 Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! U/ k- r! o7 E( g" |: J# M
- . n) E! ~% h$ P% z
6 c/ w; P" W- f# M2 c- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: Y& c) T- x( f, o \ {
- if(x1 == x2 && y1 == y2 && z1 == z2){
* _( f( F* A8 B7 J, W6 W" h - return;' h, C2 D) V W6 y( a' u; y
- }
/ t% }1 I, o {1 A C. f) O - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" J5 F9 M; y" P# O! l+ |& t
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' J/ {8 R5 U/ n* N+ o
- }
6 i3 T9 o8 D- J0 j - pose.pushPose();: Z9 Z( A1 Z$ E& L' `/ A
- final int newLight = convertLight(6);
3 M! O; ]) M: L. `3 m* U# i2 | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" D& F) Q g4 F6 |- m- \: U) X - final float lineHeightSmall = (y2 - y1);/ |% n& b$ |& o. b1 z% U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: Z9 c$ y: _+ @) H5 M - pose.popPose();3 Q% T# t. N6 R& {1 v
- }
3 l" M }% ]- F - / s- _( s& f1 f' g0 D+ t, g3 f
- private RenderType getLayers(String texture, int light) {' E) A6 C- k% F9 |" E
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));2 J b# W1 w# |" w6 _' b, j3 m
- }
7 ]! Z/ \ [- L0 d. e8 X+ i - $ _8 B- Z' ]* }0 h3 \6 R
- private RenderType getLightTexture(ResourceLocation texture) {
/ c% {( _8 d& m& A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 Q: o( U8 p( F1 [' C* V; U
- }
+ j+ h. E' ~3 s) }- C3 q( f0 `' k
7 a/ m0 S8 }" I+ w! P) p1 ^5 D- private RenderType getTexture(ResourceLocation texture) {* n- H# v% x' v( a9 n
- return this.cache(texture, () -> entityCutout(texture), CACHE_B); Z: U9 D; @2 p. h% f
- }" D# f* m+ G* @2 M
" s* O! P, S" L: v. X( i- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 p) _& R/ Q7 |. }, r( J+ U
- if (cache.containsKey(identifier)) {( R: b0 e) T0 N# g% S
- return cache.get(identifier);
4 p h3 e- `2 Q8 }" [6 Q - } else {
7 U T% U0 @7 |2 p - final RenderType renderLayer = supplier.get();
4 v" F! e4 N$ b' e - cache.put(identifier, renderLayer);1 g( J5 K' E2 T3 q5 Q! M2 z2 f f
- return renderLayer;
" [7 ^8 p/ N$ H8 L5 h" ^ - }( m0 q& L. j4 L
- }, n, _6 q9 D. ~) V& d. l# Z" P2 z
- }
复制代码 |
|