|
|
8 W9 S: R! _5 _
行,这个怎么样
. d- ~/ P6 A; e9 D0 h- package com.xhg78999.mtrfac.render;" ]% D1 A& y* c0 b5 _# \ G" i8 X
- $ x w& a! s8 b4 W
- import com.mojang.blaze3d.vertex.PoseStack;( L9 p$ E. S8 D3 {7 U! f+ p0 ]
- import com.mojang.blaze3d.vertex.VertexConsumer;
1 q K% B1 b1 i7 E - import net.minecraft.client.renderer.RenderType;$ E4 h. Y8 `& T$ Z
- import net.minecraft.resources.ResourceLocation;& G# Z: F$ Y7 [) y" B
: ]1 ]9 \5 }- I2 l- import java.util.*;( p# Z* a( E3 [5 A* b
2 l8 Y T* n' J a- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. T C0 f5 M/ A( d$ D
! J. z1 M* V7 S7 Y- public class LineRender{
" [- ~1 Y2 V. P: {% i$ ?- L6 P - private final PoseStack pose;- [4 F- w. C! Q6 Y4 L) }0 w
- private final MultiBufferSource source;5 z: @. @3 h7 y4 n4 y% L
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();# W' I9 F: ]6 Q( g
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- a! }+ A% |2 }
- ! s5 x% e& ^2 r. I# t/ f: M
4 v1 `' `3 h7 O0 i" k8 H- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ d) M/ [& K/ J7 N R
- if(x1 == x2 && y1 == y2 && z1 == z2){
5 K" x9 @! ]/ Y( y% R" t - return; Q; i+ K5 G0 @. K p2 t
- }* X! u. R" y: N, A9 n
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 _; s( T* }! a6 \! c& p - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 F6 g3 C3 k0 E- H - }' |; L; q! V( g7 g/ V. Q
- pose.pushPose();& g5 v1 m3 ?- r/ I1 ^) e. @- `4 g
- final int newLight = convertLight(6);
' d# Q* M! T; ]7 ?7 y" r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* c$ A$ w) V3 q8 J2 Y, }! E1 E - final float lineHeightSmall = (y2 - y1);
6 \" t, [, j4 t* d9 N3 x, ]1 u9 g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ l+ R8 p6 s8 s$ f/ q% A; J# {4 J
- pose.popPose();) x4 @* [: c$ z5 U! i- ^; B
- }
2 B9 _; b/ X9 \( l - ( e- h( r- C4 F4 s( V, k
- private RenderType getLayers(String texture, int light) {
. l7 l2 _' R+ s5 M+ Q7 q+ @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, A% b! w3 ^( R6 ^& } a7 F0 r2 h - }# s' J* k' S/ U5 \6 Y: f
, V3 ^* U: a3 h+ b, P- private RenderType getLightTexture(ResourceLocation texture) {8 ~! V5 C8 a3 q6 I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! X6 E0 _3 ] ^ - }
3 D2 `4 N; ]0 u% C( C
$ t- I* [2 v9 W! r% s ?0 C- private RenderType getTexture(ResourceLocation texture) {
2 P9 {, j8 g' f+ e* d! _" Z$ w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. \" U [# t. L) b3 h5 [ - }
) z- L0 }) W" v. G2 z" V/ _ - 7 X) w5 K; {, C: m6 J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 z1 U7 H8 q5 C6 a - if (cache.containsKey(identifier)) {
; q- ~% \7 c& L. X - return cache.get(identifier);
. B1 F; P- W! t7 z( F( | - } else {' B' ]; [ j4 P) h- }4 b# N
- final RenderType renderLayer = supplier.get();
U" t ?7 l( x# }% D6 L$ T3 v - cache.put(identifier, renderLayer);
0 N( j& I5 v3 |* u) b4 j - return renderLayer;
0 f) J$ g; w' z. X7 d - }1 S' q; T4 }8 W2 V3 H1 c5 |
- }
0 b/ Q1 |. E7 l; W - }
复制代码 |
|