|
|
2 i9 W7 I7 G k' }7 M( g行,这个怎么样
, K* R: }2 z" U- package com.xhg78999.mtrfac.render;
) M$ C) j2 \0 c- K6 Y n& o
" }7 y; z4 s: e- import com.mojang.blaze3d.vertex.PoseStack;6 b5 ] }( y5 }8 X* i/ g% D/ `* {
- import com.mojang.blaze3d.vertex.VertexConsumer;0 o! E q I2 B+ k: H
- import net.minecraft.client.renderer.RenderType;
; H& J. y+ S, E/ ~- [ - import net.minecraft.resources.ResourceLocation;
0 n& T9 }6 x- l# } - $ s. Z. h) K0 C" B, A5 t8 r( E9 N+ S
- import java.util.*;. n) J* _- l j' A
- 0 [1 F. s- N y h/ ]0 Z/ k" m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 s$ o. l* J9 b( P - ( _ P# j" x/ M% r
- public class LineRender{
I' \/ \! M% d. P" ? - private final PoseStack pose;
1 m; Y3 S! H% D+ ^ - private final MultiBufferSource source;
7 L! {+ Q! {4 n. M( u# I1 I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ n/ P: J% D$ c) C - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! a0 ^4 s/ v; j. @
- # L9 X* I) b; Y( t( E# a
- : ^: y! P, h2 Y+ Q. P# L& x2 C8 i$ [
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 y7 V/ E! r3 b( J5 J! ]) V - if(x1 == x2 && y1 == y2 && z1 == z2){" [: ~$ F0 Y. `" R
- return;2 q7 x( }3 Z6 g' t8 T# k/ z
- }
. H! ]! D" W* D" B7 h5 A; B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, D7 ?) r6 w% h% t8 s, q
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; ^% u0 `$ p/ }0 f4 T8 a$ Y! q - }
8 s* S- D9 E: x2 u - pose.pushPose();4 S8 f5 } ~+ y: t' B
- final int newLight = convertLight(6);6 l. |& T% m. k, N8 L0 C, a' t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 X9 O, U, ?- A' `* d
- final float lineHeightSmall = (y2 - y1);, J. Y c7 r" t+ z g' S2 }
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& \2 T M: J2 P) r- }+ l( n) T' ?7 O - pose.popPose();
6 ` a/ \# \ C) _/ Y( f - }" f( T9 l& B& K. p! j( l4 o
3 K# c+ U% n! R8 g- private RenderType getLayers(String texture, int light) {
* x7 x+ B9 F3 {# g3 A, m f( s% B) i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));2 S; T+ s, v% c3 N8 ~1 T7 _. J' l
- }
W8 h; b1 n# d W
7 M' T6 x! m; n7 j- private RenderType getLightTexture(ResourceLocation texture) {/ x; S+ P6 k' K9 Y) `5 M N4 b
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( F! |8 x: ]# R, E( [ - }
# S3 m+ O$ r6 [) k" ?% q7 G7 \/ Z0 k
5 j h# [9 {2 n- s! c8 y- private RenderType getTexture(ResourceLocation texture) {) k. q& n4 S3 F6 E" w# G9 d
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 j% \+ d& |) P- Z: Q, b! T
- }& D' t5 S) M. @" j/ L
7 Z& ?+ P# z! ?8 W8 [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { z1 i8 R- b3 `7 [+ z8 u
- if (cache.containsKey(identifier)) {
8 }) s# [8 \* [& v+ k0 ` - return cache.get(identifier);
1 B6 q: {! i# T0 N - } else {
- I5 ^8 ]- Z- {# V* x$ @& Q$ ~ - final RenderType renderLayer = supplier.get();3 _" t+ p2 ?( D/ D/ h9 g
- cache.put(identifier, renderLayer);$ o9 O2 q4 ~6 b* X" N8 N3 z
- return renderLayer;, q4 N: A2 v( t3 u1 e& V
- }
* G3 S* w% p0 i1 n" g - }: _8 R# s; G: f6 F |
- }
复制代码 |
|