|
|
9 O, g/ t4 E# n9 `; q
行,这个怎么样+ T' I, \1 }$ y2 z% ^0 q
- package com.xhg78999.mtrfac.render;
$ g% a- O. [0 n: H# d: p - ' C+ [( i* _' g1 O
- import com.mojang.blaze3d.vertex.PoseStack;+ k2 A+ |" z' s0 x1 g3 X0 _% _7 h4 ^, A
- import com.mojang.blaze3d.vertex.VertexConsumer;
( w* V) a$ c6 m - import net.minecraft.client.renderer.RenderType;
5 a$ g) J3 P3 i5 ~5 D - import net.minecraft.resources.ResourceLocation;9 X p9 y& J' U% \9 F
|9 c& @9 Q' `; _ n" c3 Y- import java.util.*;
$ [# y% o) m1 z - + U3 ^- k6 A" _/ r, r8 x0 @
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 o$ g. i4 F# p a6 N9 k& r' Y0 @ - 1 b( W3 S1 f# F6 |! j
- public class LineRender{
+ ?3 G/ B7 j! v# E" R - private final PoseStack pose;
, u! l0 R; |" A+ j: @ - private final MultiBufferSource source;/ [1 Z# n. A+ }5 z" O
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 }6 Q$ l; e0 n. L - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 N8 R. n9 B- _/ [7 x$ i! ^# ^5 X" ?
& v5 u) P. w( U* P: R7 `' v/ v! E" n- U- ( I5 ?7 k( o1 ~( F) s8 G
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){" p5 [5 Y' {- r( N3 n, i8 v
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 p# V! c5 J; } R1 u' c# F - return;3 f- U6 M' E8 X" o& J
- }$ m: W! w: M2 c ], y! ]. j/ _
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 `" ]2 W6 a4 I5 Z! V$ S0 y. | - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% k0 {0 t# P; n z- L5 { - }2 ^1 G' n% K; I6 ?
- pose.pushPose();
( F6 B9 w0 B. q1 c9 b - final int newLight = convertLight(6);
) i1 n% t+ q; o1 p - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; x- ^4 W3 X i" @2 x+ S: _; K
- final float lineHeightSmall = (y2 - y1);
S$ x3 \% M9 F) P1 g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! B3 T, L5 V; \; A x) n - pose.popPose();
2 g) ]% I$ a7 u! B8 e+ l - }
1 v1 O. g0 v3 \: f0 R, K
+ u3 K5 I+ H* y! ?8 X, Z9 X* Y- private RenderType getLayers(String texture, int light) {
2 ^. l# L! x- T8 x- P - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 g0 E' H! C0 _8 J4 _ - }" q$ E* K4 C% |/ R; ^- o7 R
, X7 A3 x) y9 t; t5 B R- private RenderType getLightTexture(ResourceLocation texture) {
# d( A" o) I( D2 }% O4 ^" f8 P' t! \ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! g5 U ~ J" Z# s2 O: \/ K - }3 Z o* v7 K2 w& b: y/ ]$ w! G
8 F- Q9 `5 `- b6 a& ^- private RenderType getTexture(ResourceLocation texture) {
0 x" {. d' q _3 S. I0 h - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- B8 l3 B: v3 j' _* h* L - }
) `# i/ z5 e+ z- @ E- W0 w - " X3 W" u" j; B$ _) z
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ Q, \$ E9 h, w+ C+ a3 c
- if (cache.containsKey(identifier)) {1 d; x- i/ V$ i# |; h
- return cache.get(identifier);
$ R( n2 C2 q4 B: h# e* F - } else {
5 i2 [. @% f @/ X/ ~" B - final RenderType renderLayer = supplier.get();
5 E' A! @5 U+ p8 m! f1 ? - cache.put(identifier, renderLayer);
0 p0 i: ~6 s3 J; v8 S% H- K - return renderLayer;) N1 C* A5 P/ B" X
- } \, a H2 _3 J) `1 J6 i
- }' S# r& k' s7 R4 n
- }
复制代码 |
|