|
|
! h3 _! {( M4 ~) a1 p
行,这个怎么样" R* L4 F2 l" z& @: b, n- T, A
- package com.xhg78999.mtrfac.render;, C& L) Z" R5 }7 k
9 V+ X* u" A2 Q" Q- import com.mojang.blaze3d.vertex.PoseStack;; w. T2 m$ C1 W9 W1 f
- import com.mojang.blaze3d.vertex.VertexConsumer;
' j' G; Z0 f* c$ p/ f& q! F3 `* k - import net.minecraft.client.renderer.RenderType;
9 Y# j% r3 S& t# U% U - import net.minecraft.resources.ResourceLocation;
' W% Y0 ]' U/ j& ~8 W; j1 ~
3 U9 b. U K% }- B- import java.util.*;" U/ v, i O z- n
- 4 F( R9 _% y2 D1 Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 X7 {7 ^2 u5 B' r2 I - 8 ]! M$ k( b/ ^
- public class LineRender{
) D- v8 g# s* n9 g' @3 d/ V - private final PoseStack pose;' c6 l; {, J2 q8 {4 l) ^1 P$ ~4 x( O
- private final MultiBufferSource source;
/ N6 ?+ c" V% O5 P/ c: f - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ e6 b% Y. j1 v4 B: ~0 t - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
C9 v3 c' S7 m8 I6 ]) I3 t
1 Q. O' \/ L# [5 h: j- " W" V( V* B, G, a4 M- q
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 e$ |$ o7 `) \1 A4 b4 Y E - if(x1 == x2 && y1 == y2 && z1 == z2){& X1 N5 c5 F' ?$ T
- return;
& M& N9 v5 T6 c! P6 ]9 C8 { - }* k" k7 G5 z2 @
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: D- o# I6 b" M: J' S5 I( J: r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 a# o& g% N; E2 G5 L$ B8 K( L
- }% q& }6 R# K; M% \
- pose.pushPose();
0 D: B4 W0 c2 u - final int newLight = convertLight(6);
4 {& g9 x5 w. g+ |' g/ a( ~ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 t# F/ j0 `* I/ X( ?% q5 G
- final float lineHeightSmall = (y2 - y1);- u6 S e1 L: K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( Q/ ~$ ^/ n2 F( } - pose.popPose();
7 {9 K9 F0 C1 D' A8 h - }
% {7 n" \. }+ t9 T; ^( S
+ t7 D# H3 l) N9 k. b- private RenderType getLayers(String texture, int light) {
$ r$ J+ c% }. t0 C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 A/ M) Q% {* T8 P0 [
- }3 M8 T- \7 j5 z
% ^; J0 h9 R# V- private RenderType getLightTexture(ResourceLocation texture) {
" ]- }% p5 p( I: Q4 ^+ K - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" f' P; X+ K$ X5 v a
- }5 W6 \7 a% } @+ T6 v6 T" v
# j7 x O3 z5 E- v( n- private RenderType getTexture(ResourceLocation texture) {( \* X3 `6 k# W. w* s; ^* A1 N
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; G9 M" W* U" \. J
- }
) |. h$ {% N0 F, H0 L
1 X( p4 _# H$ Y; U8 o% y/ j% n" o- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* x9 F4 Q) x9 \2 t4 F4 ? - if (cache.containsKey(identifier)) {
. q/ A/ S7 v$ s0 F - return cache.get(identifier);2 q& t0 T6 S4 R% M, A
- } else {6 W7 Z+ G) T) L5 k% R$ \) |
- final RenderType renderLayer = supplier.get();1 @* G9 L% C' ^# L. W
- cache.put(identifier, renderLayer);
, l% j; t" f5 i K6 G& X% ]# u - return renderLayer;
2 J% u% J" ~, v/ D. `6 H% _9 e/ V3 \, _$ v - }8 i) Q, A4 t# u9 c. Z
- }' }. [/ q# ~5 J+ ?2 @. R
- }
复制代码 |
|