|
|
+ t/ s" V7 c7 p+ _( Y9 w0 n
行,这个怎么样3 u( X/ E Z% M& ]9 V
- package com.xhg78999.mtrfac.render;0 \1 m0 I# k3 j; H: j/ M
- 8 K5 _, s7 j" c% Q+ ]% }( w' j. F
- import com.mojang.blaze3d.vertex.PoseStack;" Z5 m9 @$ w* f: d% N7 W2 `
- import com.mojang.blaze3d.vertex.VertexConsumer;
; [4 t; J$ w7 A# W - import net.minecraft.client.renderer.RenderType;
* X6 `+ r, [+ j2 u3 n; I+ {" i' T - import net.minecraft.resources.ResourceLocation;0 n" h( i( G j/ h: h3 A
- ) [. H1 g! \5 F) N: S
- import java.util.*;5 ~, y3 x* D) g
1 O2 K: A& ?+ b( {- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& g" N; d V9 X( L' S) i
) z7 @0 V: ?1 _) p7 B- public class LineRender{+ R3 a6 I7 \) `, ^. C/ T
- private final PoseStack pose;
- Z( W/ R* j+ b) l8 w( M - private final MultiBufferSource source;
" P0 j9 H6 {; s$ E6 p7 }: ? - private static final Map<String, RenderType> CACHE_A = new HashMap<>();) D; o& E* Q) ^* w8 E
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" H+ s0 B) }$ S/ Q D
3 c1 Q5 O! P) W$ I) \ z# j- ! N* V0 S3 a' \: X7 S+ V
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 v: P! _3 n; I- ~7 n- d) ~
- if(x1 == x2 && y1 == y2 && z1 == z2){- y: ^4 T" q, c3 }9 X# R
- return;$ v. `+ x6 x1 d" b" P
- }+ X5 A9 I0 M& P# I% p: s1 t
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ s$ y. a3 K6 p9 r( F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 n# N+ m- S! m) r2 } {
- }; L& }) e% P; S& b& U
- pose.pushPose();
) q+ c" z: p1 `5 D, m - final int newLight = convertLight(6);- T+ Q* n2 Z% A# e9 D5 K6 k2 J; O V
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( }+ l \. L* J - final float lineHeightSmall = (y2 - y1);. M3 [/ i* G3 l7 R. \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 R' ]2 z4 t' ~5 i) T A
- pose.popPose();
( i: Y/ [7 O' i q6 L3 W4 t - }+ G* }0 t; D0 z
- ' G3 j- a$ i( B C- u5 T* _9 ?2 t
- private RenderType getLayers(String texture, int light) {9 O7 p, a3 C& j2 u. d" \, G
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 I3 K$ g3 w- H) X$ ?4 r - }3 }/ p! I* ~! E/ h1 \! a; }. c
6 U4 C3 n8 H1 _6 R- private RenderType getLightTexture(ResourceLocation texture) {
$ Y6 m' Y9 r v" J2 z; T - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 d+ } c! k4 f- G - }
$ Y3 i* J, ~: f" H - ( K; B; ]6 D# b, b. k
- private RenderType getTexture(ResourceLocation texture) {, A& f2 b. Y9 j
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 k" s7 f2 ]) G/ h; |! M
- }2 `, V: |3 ] N: h
- , s( {/ p1 j. \) g/ J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) {" ~% D d# [. z; \ - if (cache.containsKey(identifier)) {5 T' k Z5 ?" C' g
- return cache.get(identifier);& H1 v, i: I5 n! \- k! b% L. e
- } else {
3 T8 D# w0 J$ Q h! J- c6 e$ x - final RenderType renderLayer = supplier.get();" D, [# H1 `* W/ R$ l* Z" I
- cache.put(identifier, renderLayer);
& P0 m, d( C$ z( `" C1 d - return renderLayer;0 q0 t* P& r8 U( `0 P" f R a. \/ a; p
- }
/ P! k V& C/ E7 F - }% Q4 |4 P6 T: z
- }
复制代码 |
|