|
|
; X& N9 u: Z# p1 I1 m; ~行,这个怎么样2 R; E6 g! O+ `8 |' j" a3 ^
- package com.xhg78999.mtrfac.render; @- X: ?" b# w9 B5 r
& b& h$ V& X; u% L: ^" F2 ~- import com.mojang.blaze3d.vertex.PoseStack;
2 B1 O4 R. J: T& w: [7 c' o - import com.mojang.blaze3d.vertex.VertexConsumer;
% M$ F) k3 H4 e3 M" c0 F6 { - import net.minecraft.client.renderer.RenderType;
9 S2 \$ B$ N) a/ o+ B - import net.minecraft.resources.ResourceLocation;
2 n( c$ w+ U$ h
" U! [% T( G- ?! j- import java.util.*;, J+ K. ~' C9 r2 ^3 }+ V" w
/ M) V; S: [! a- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, a8 M+ F' v) I, K* d9 U
- 7 f; E. V. s( J. [( q
- public class LineRender{& J6 C7 z. A$ {/ P1 m( }' m
- private final PoseStack pose;9 Q1 o% @/ D) A9 @ `$ l
- private final MultiBufferSource source;
, V- M: @! R( a9 J' x7 T - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ B7 r! }2 |# r: [0 I; m. M - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! m0 r# N5 ]! _0 L5 D - 3 L9 X. ?. o; H4 K- E% r1 M
$ k: r& J# r" B- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- f- X6 Y3 K+ A, m- N* L& k" M - if(x1 == x2 && y1 == y2 && z1 == z2){" L9 A! H, j8 r! a$ H% p) o! v
- return;! i) T! R& E/ i
- }: H0 ?& O: ^. Q+ u9 X& s q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 M) c! p! Y2 o3 D" N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 ?+ \' _6 J6 J, h! S$ }. D - }
, J: t8 Y5 Y7 R Y3 S - pose.pushPose(); L" j+ s, L( R
- final int newLight = convertLight(6);
! A% ~7 r1 D# H. R F - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 i- q E1 d7 C9 n- w7 y - final float lineHeightSmall = (y2 - y1);
& n( y, n! y) ^$ q& q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 |, ]9 c$ K6 m4 A+ v
- pose.popPose();
" n1 M5 o1 w' \2 I2 S9 a - }
4 ~2 d/ D/ C( |) z
" k) G! d& b) m+ R- private RenderType getLayers(String texture, int light) {
: T3 U! Q5 ^3 f' s) d L% f1 _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ P2 l6 `/ @8 _* @ - }
* T5 M+ z) ]6 k; ? - 2 U3 m$ ~5 I& S- o& ]3 N0 r; D# v
- private RenderType getLightTexture(ResourceLocation texture) {
4 w- _4 C- j8 n! G- ] - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: M$ N- w& D. r
- }
0 j4 i6 z, [' V. Y
: W0 b6 t* K; b: ^6 ~6 |& o7 {- private RenderType getTexture(ResourceLocation texture) {
; G5 _8 D3 }" A7 o - return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 _) {" Z0 V6 M5 e' s9 n% _3 C, l
- }
& ~# V, G& U. q/ B! |) v1 }/ w - ! \6 B3 l( f% u9 A0 E1 p" X) u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 K3 M, ^6 O/ l8 g - if (cache.containsKey(identifier)) {
. {; |5 r) ?- D+ v7 }8 T3 t- F - return cache.get(identifier);& ]( s( E8 ^; F9 g) W: s
- } else {
% x& [0 g, i( E4 m - final RenderType renderLayer = supplier.get();
% h$ C8 b, A1 K - cache.put(identifier, renderLayer);$ y$ R) s+ s; ]( o
- return renderLayer;6 H0 U- c) p/ `" |
- }
% |) f) I% Y9 S: D; j) \4 I7 B - }8 y7 r& N$ \% Z. r' e0 X; R
- }
复制代码 |
|