|
|
* i3 n1 `6 }" e: M$ h! O- w$ I6 j
行,这个怎么样
7 ?+ W" U1 M" |& ~( s' O8 L- package com.xhg78999.mtrfac.render;
" m' r6 o# U% h3 J# J6 z
/ a" S, ^1 \8 b% i& ~) |2 K- import com.mojang.blaze3d.vertex.PoseStack;
" R0 j9 w5 X5 @4 [4 D( D7 D - import com.mojang.blaze3d.vertex.VertexConsumer;
% k6 a- |2 C, H - import net.minecraft.client.renderer.RenderType;
* X, D4 Q9 d1 {5 ^4 t! r - import net.minecraft.resources.ResourceLocation;
: J# z" Z: N% a! B8 M& \) ?
( C2 h' ^/ |, Q# q% `+ `- import java.util.*;# E& w+ |) q! M8 `
/ f, q8 d) `" g. `. j* B9 X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( O Z' K f$ h7 h/ U, |, K" p) H8 n
1 C0 _4 e2 a/ [8 `/ b- public class LineRender{+ W, P2 E. F. E$ t) ~
- private final PoseStack pose;& x( y- [! x8 h5 w/ D
- private final MultiBufferSource source;. E' A9 u; T+ V- M+ y# z: ^
- private static final Map<String, RenderType> CACHE_A = new HashMap<>(); T U& V3 w( S5 J- a# r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 m: f6 s5 Z2 H
- # J* C( K C# ~+ R) i" i
- ; _7 r" H! B+ y9 G- E0 A) E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# H$ @8 M$ F( \. d - if(x1 == x2 && y1 == y2 && z1 == z2){
1 d4 U' ^2 c2 n: G. z* F$ f2 J& f9 p - return;
+ Y1 A+ `4 s8 K- Q5 ?0 ^1 \ - }
# |% {% h( {9 `0 ?% m. I - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 u' b% B' M& { v; Y @8 ~ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" P4 H( [9 B8 a$ v# O5 F
- }7 C9 b1 ?: i8 m4 Q8 [# r
- pose.pushPose();
L/ w, L% G, \2 b: p - final int newLight = convertLight(6);) D% Y7 j0 [, x6 W
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; n2 A) R; p+ }) j5 n& N- J
- final float lineHeightSmall = (y2 - y1);
& T/ B# m) ]" ] |4 D- p! F - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: }' e# j) A7 a. n6 v6 W N
- pose.popPose();
* O" y3 O( B1 ~& M) A9 k - }
% u- b8 H) b# j8 r
% a+ h. \% c. E- private RenderType getLayers(String texture, int light) {4 F$ w. g3 I0 A0 v6 O4 x$ Q6 H
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" A1 W# i* ?& \* W" a7 ~: Y& M - }
o$ o& S! ]$ `
* e+ ~3 {. k9 l' X: F- private RenderType getLightTexture(ResourceLocation texture) {. v6 w; A& T8 b S' G8 Q0 o% U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 V+ w. k0 I0 D# X3 i - }/ F d7 O/ p6 Z" s* y" j
\) p2 g+ R. i- S! }- private RenderType getTexture(ResourceLocation texture) {9 ^1 g) a& q" R) n! {) p" k' o: k
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# z' w* O: Y& y - }; C, }* }( r) A. |
' r2 _' E% ]! e, W+ |, o- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ ^$ T3 D2 M. E% B' z4 F' d3 a( O* O/ B
- if (cache.containsKey(identifier)) {
5 ^! n5 F) g& g ]1 a5 {4 P - return cache.get(identifier);. W4 q0 f9 h) S I( M4 q3 f
- } else {
4 r: l9 `# I$ u! u - final RenderType renderLayer = supplier.get();: l( K0 o& K7 c3 m2 W
- cache.put(identifier, renderLayer);$ p' H' p* v6 V. M
- return renderLayer;
$ f$ v2 T: `- M - }2 t0 i! f6 x- p: m5 Y
- }
9 R8 g( t* d% Y0 d4 B8 S" L' h - }
复制代码 |
|