|
|
* O& Z% Z [7 w. @+ @$ E0 D' V. o
行,这个怎么样
" E5 ]9 I! C1 W1 z! A* @ n- package com.xhg78999.mtrfac.render;
: ]# x/ J6 ]% m$ g, ~8 `+ V' w - ( P# D' l2 O- q- L# F6 y5 M& E
- import com.mojang.blaze3d.vertex.PoseStack;7 |% l: U7 ~( W2 @
- import com.mojang.blaze3d.vertex.VertexConsumer;* [) B$ ^; V( i: n! @+ ~: Q
- import net.minecraft.client.renderer.RenderType;
1 h3 D4 I! S4 H1 J5 L: k1 V) d - import net.minecraft.resources.ResourceLocation;# M' Q; ?9 y9 N3 U U; y& R
; ~2 M! H$ I+ B! }, A0 {6 q) B) u! S- import java.util.*;
% V( D$ k; @. s5 m3 g: b
2 a q6 p3 [7 y5 A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, G9 K5 ~, q, a
; _# l6 p2 s$ |* }- public class LineRender{
: a/ V" ^; k, s3 X - private final PoseStack pose;# f& }- i) A& t9 t ^& a
- private final MultiBufferSource source;& T6 @! s5 b4 \+ Q3 g- u/ K: U4 e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();* N7 K) q8 R& p# t
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();3 M) H, R4 u8 k! l# `8 X
- ' K% A4 y' ~# F) t
3 y( d; r( V, s- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& H8 n+ B2 D' V& g/ L - if(x1 == x2 && y1 == y2 && z1 == z2){1 h5 e/ r' \1 \& k: |( z
- return;
1 Z& t# s% q+ F - }
$ f3 D8 B+ Z E( } - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 I0 f6 h" r$ Z# Q3 e" i e
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); J1 E+ N" j: o( j1 R3 S
- }
7 R2 Y1 n: @3 u - pose.pushPose();& L0 t( b( v8 }3 T5 y- Z1 |; u. K
- final int newLight = convertLight(6);
0 t, q. u' z6 u" T3 R5 ]4 y" V$ A- r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: V( B' t$ V( e+ v2 _ - final float lineHeightSmall = (y2 - y1);
# ]( ?% _3 r, }$ |9 y. J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- y# P) F1 G" |
- pose.popPose();
/ c) p$ b2 ]5 M, E! L$ \ - }5 C# @* D2 a' o( }2 M" k. d
- ; P: j/ ?+ y1 t
- private RenderType getLayers(String texture, int light) {
3 ~3 ?0 U* X( J9 d% M) h* W* K - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 o; X' j2 U+ n! ] - }
0 l0 S7 b c1 J+ R! A - 3 m8 }+ L; |0 t' ^7 G# h
- private RenderType getLightTexture(ResourceLocation texture) {( ` l- O! v' f$ {& {+ v7 n( O
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) U; j6 q9 h8 e. ]7 S# C: }0 L
- }
9 ?- ^+ E( ?( e8 F5 E( I - + @1 {* r. L2 P% r! u
- private RenderType getTexture(ResourceLocation texture) {
7 N. F( E; M7 @( j3 { - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% ]3 N5 U. _0 ]) N" ^+ v/ D9 L - }
- h9 P4 ~) [' m6 ^# p; R
& S9 R/ R$ ~: T4 J2 c: z* C2 X0 N1 V2 V- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! i: Y5 S4 }! K) ]' A1 C9 c/ D5 D7 I3 U - if (cache.containsKey(identifier)) {3 T: r! u6 I2 F& t$ [' T! }9 r1 @
- return cache.get(identifier);
p7 c+ ? \+ l - } else {
$ O# R+ T5 G) s8 K | - final RenderType renderLayer = supplier.get();8 P& U. H( \& A) C1 ]
- cache.put(identifier, renderLayer);
+ p- l& u4 p2 u4 F8 o. E - return renderLayer;
/ {3 r; e! U, L X3 R - }) B* P: {) V1 R+ O; O, N& x
- }9 c/ p$ W3 P8 d. a) B/ Q! `
- }
复制代码 |
|