|
|
7 B E! |+ J1 _7 M
行,这个怎么样
' k& B* z D9 p4 v" z- package com.xhg78999.mtrfac.render;# a/ H5 K8 r2 T# i& n' l
- & X' o: `1 L( M: ?, W6 H$ B
- import com.mojang.blaze3d.vertex.PoseStack;
' u9 a# l2 c3 I9 X y - import com.mojang.blaze3d.vertex.VertexConsumer;
, ^6 C8 X* M' i4 I' Q6 i - import net.minecraft.client.renderer.RenderType; l+ ~4 C( `& X# I Q6 L
- import net.minecraft.resources.ResourceLocation;
/ K! r) h, ?/ G - % G$ g+ U8 L* V7 S+ p" s) N, l' y6 }
- import java.util.*;, ~2 R- [8 S9 k( O. C1 ~( ^; N
# M; ?: s5 v% i; X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 G+ f. ?) Y! `8 P
- 7 a+ D- A5 Q6 n! Q5 E. Z$ j( ?
- public class LineRender{" G5 G8 ~, D) k/ R3 k
- private final PoseStack pose;# w) E9 W4 H$ S" ~6 x) z
- private final MultiBufferSource source;4 v& L- h# _3 A% z& f
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% w4 l$ ^+ [6 n0 G% S, |
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& `" [' Q9 l* K# C
/ d) a. l z4 C+ U t- # d E$ } O2 a7 G3 l) F( P& c
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
n1 g- L4 k! s: v- e - if(x1 == x2 && y1 == y2 && z1 == z2){% `+ S& \' a G/ f, y3 O
- return;: B, Z5 ?; a+ M* e! ~- s
- }+ V2 r5 i2 S% K
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 b+ j" V5 a, \0 C
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. \; I; c6 N V$ a - }/ L+ N, E' A1 U5 C* G2 Y
- pose.pushPose();
# R% K( Y4 Q1 J. l) D3 ?6 p - final int newLight = convertLight(6); W# z, B! f3 o8 b
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% L. o/ R% Y! t& |; a
- final float lineHeightSmall = (y2 - y1);4 _8 |, @7 h4 `; d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) `7 A l9 B' o1 ?& p
- pose.popPose();0 O# Y8 z, e9 J2 ]' `+ u# B
- }
$ Q7 W( N3 S" G/ t - ( O3 V3 P5 Z& F
- private RenderType getLayers(String texture, int light) {% m" `$ k2 ~2 o% h: M
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 h/ O, A; D9 @& Z5 u( r
- }; s" M+ y% ] O0 i T& g& a: E6 K: `
& Q' K- @+ O3 Q& E) }; R8 a9 l- private RenderType getLightTexture(ResourceLocation texture) {" }, h7 R, _# |3 q! Y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 z2 g6 F8 d- h& [- c
- }
- V8 P1 ~( _/ K! X0 X - / |* u; V5 V1 A3 B+ B
- private RenderType getTexture(ResourceLocation texture) {$ I9 a* i! }% D s, U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' ~5 {& I6 P7 v& [; e1 J2 b# t - }2 {% y9 b2 D+ T, Z3 U. w
- 2 q$ I! K7 l/ t1 o4 ?' Y
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ \; B+ q& }- O& s& T
- if (cache.containsKey(identifier)) {% `& g' r; k$ K% w$ K
- return cache.get(identifier);
+ j! U: J% z3 y - } else {/ N/ P* w n, Y9 n( o3 @
- final RenderType renderLayer = supplier.get();
8 p- e6 V5 l$ n - cache.put(identifier, renderLayer);4 v p3 J; k" N- e& c
- return renderLayer;
" B. N5 I( Y' I - }( {; l# j, P% @5 s/ ?2 e) P/ s
- }1 d- v# L/ o, c( E! y2 e8 k
- }
复制代码 |
|