|
|
! D! g0 G+ O( m9 M( Q$ c
行,这个怎么样
2 k- C, \6 z3 f! k5 g! I' d J p- package com.xhg78999.mtrfac.render;( Y6 _1 t+ Q$ h8 S1 S
1 a; C7 J T, O3 t- import com.mojang.blaze3d.vertex.PoseStack;$ ?/ Z% r/ \( H/ T9 A
- import com.mojang.blaze3d.vertex.VertexConsumer;
+ u; l, P' Q, V2 o: r& m6 q6 ~ - import net.minecraft.client.renderer.RenderType;
$ w0 {/ f% B! f* S- l - import net.minecraft.resources.ResourceLocation;
& L& ]" H- t& [9 g6 d& H
! Z- ^$ O3 C/ j" g- import java.util.*;
( C& Q' o9 Y+ O ^) L+ B6 M
# w2 | U. U( H9 E& d- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ J! u6 t% l$ d" u$ n - ) `* X4 W, z& S$ x
- public class LineRender{
/ m' X9 Z; d, w$ Q6 c - private final PoseStack pose;" v- T/ s4 ~' t1 _/ j
- private final MultiBufferSource source;6 l: d; |2 B7 x' u9 u& u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ {5 H1 [6 T1 H4 e/ p( N! T
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& `' x% f1 }4 _! @; k, ? - & z, {9 z i U; s1 w G
- 6 s$ P+ ^2 o% }# k; |
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 S! O" G. T: p$ y* y, F# ?9 J$ Y - if(x1 == x2 && y1 == y2 && z1 == z2){/ E/ |1 e7 x+ |: p
- return;: d( S4 U( g9 n6 B( y. m
- }% f9 ?& m+ D3 ?9 e9 G4 A
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 h4 s' h+ l+ e" n5 L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
7 m3 D1 e8 f7 w - }
6 V% x) |2 q5 o6 e) [' O9 E9 Y - pose.pushPose();9 x$ | }, q0 Q* G: Y
- final int newLight = convertLight(6);; N5 F9 O6 D! ] _
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& D7 M2 x. {* y& R3 c8 X6 M: O
- final float lineHeightSmall = (y2 - y1);* ~' \4 a% i; K6 P% H. o+ Z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( f- M) P" A. L r j - pose.popPose();* Q5 I5 H* I; Q$ \4 v8 c- x9 n/ z+ h
- }
6 j3 Z, g, J/ l- F
& D1 I$ O! |! D# w5 o- private RenderType getLayers(String texture, int light) {7 k% Q' y6 ^0 b. \, K0 R
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! q0 B/ b) u* Q1 Y! n - }4 d* q. p+ f( d* x9 n
7 U% P# U7 S/ c( `6 I* R- private RenderType getLightTexture(ResourceLocation texture) {
! F' _+ p6 w- ~8 A7 \9 r - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% w) z) M m9 ]- B% p- I# m8 N - }3 h( Y$ O$ F& H$ |6 u
5 l% |# N! i! z; _) |+ [- private RenderType getTexture(ResourceLocation texture) {
1 s6 p V( j4 q4 d* G: b - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% F4 }$ Q: C7 L% u# M5 F - }$ m/ U+ _+ S. R
- 3 U8 z. |3 J( K1 q3 R: H" u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! J' ]/ Z q2 H
- if (cache.containsKey(identifier)) {) ~% x( F4 q; z: F- ]& I+ x6 b
- return cache.get(identifier);
& ]) i. J0 M$ T4 o1 N2 M: _ - } else {+ g) w5 {* Q6 W* \8 i/ A3 R
- final RenderType renderLayer = supplier.get();
@% u' Q& @4 @$ J - cache.put(identifier, renderLayer);
/ {3 J$ v. ~8 I/ E" ?9 a4 ` - return renderLayer;
( ]4 x8 F; p, {2 P' T5 [! j5 Y7 H - }
# D- E3 g. z3 k& p( j - }
# s( w9 `# U# c R4 @8 I3 p+ B3 x - }
复制代码 |
|