|
|
0 x3 b4 [% L: Q+ j$ e- y
行,这个怎么样! A" l' G( c. _3 }
- package com.xhg78999.mtrfac.render;3 g. w- G$ O7 Z8 N; s% V
- 3 X g" h; h8 d" ^6 o
- import com.mojang.blaze3d.vertex.PoseStack;
5 O# [1 B1 n+ ]+ }% U' u - import com.mojang.blaze3d.vertex.VertexConsumer;
- X. N% \0 R. J9 r" |9 r - import net.minecraft.client.renderer.RenderType;
8 N- s0 e! q; |. G6 w - import net.minecraft.resources.ResourceLocation;
' S" D+ Y3 H. C* ~8 b
; A( Y1 ?" E& ]) G+ `% W0 l- import java.util.*;
/ i" c+ c) B F9 [0 O8 t
' ?+ S* a7 t7 K- k, b- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( N1 k) W" z- S$ D/ y: x9 A
- I S! K+ f# v& X- public class LineRender{
4 V) D! N( q, U# D4 W6 K - private final PoseStack pose;6 S& H7 M& x! q7 S; M7 U
- private final MultiBufferSource source;7 h4 s: _* C2 t- D1 J, G
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 D' e6 Q6 j8 c6 b1 ^
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 {( {2 d6 N8 ?3 k( U
# y: @ a1 V( H2 j& j5 B4 V% t4 m- # ]' B& C e: h2 g7 w$ `% h/ f/ S3 ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; l5 f" v6 p6 y: E1 Y% n% `. }# C
- if(x1 == x2 && y1 == y2 && z1 == z2){
$ {& d, \4 h: j7 c; l - return;6 A( N# Z) x% Y" o( F
- }) X F Z' Z8 k
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){5 ^* m0 l" p; \# k/ v& s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: s9 D7 C2 ]0 Q4 `6 y9 ?# F
- }$ b- \& W) U: Z# S7 A \" f
- pose.pushPose();$ F! N# Y7 i; A( Y8 N. b7 f" k ^4 p8 G
- final int newLight = convertLight(6);; [) T" `7 y- f) J& x6 u: G
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 d( N, O9 n: B' }
- final float lineHeightSmall = (y2 - y1);
2 |* O. b7 F9 }6 c - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& ]& ~# H, Y6 r
- pose.popPose();
# Z; ^! g. _. L/ C - }
6 _4 ]: T4 H, ]3 f9 l& F6 T
' r% y+ J( k8 K- M1 u- private RenderType getLayers(String texture, int light) {
% |9 H1 ?, D7 Q4 @8 x1 V - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 k) V8 o: {! ?& y* J4 }0 Z4 v
- }5 d# X+ p) B+ r9 r% f9 c8 Z: H
- 3 H6 i; u( h- U/ h+ j
- private RenderType getLightTexture(ResourceLocation texture) {+ b+ {1 `7 u- g9 }- v
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) {' H+ a; _0 T9 N& |) _
- }1 p' y/ |/ H9 N/ M
n( j2 ~0 R- ? o& L& J, Q- private RenderType getTexture(ResourceLocation texture) {
& P9 O0 |& c8 l3 \% ~# {7 l% ]7 W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 P' L( \1 d& E
- }
: ^/ R5 r! V( U8 s" c
8 i* d$ m+ Z- B3 ?; t' L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ ?; N& I( z5 H& o, H
- if (cache.containsKey(identifier)) {
5 r# M* m$ ^5 y8 i3 a# c - return cache.get(identifier);
1 J4 n5 V( x- g - } else {
8 G8 ^/ b- m8 @$ M' q - final RenderType renderLayer = supplier.get();
# l8 x4 n; z( r! G) `0 N, c- Z - cache.put(identifier, renderLayer);
: ~: F4 r/ E2 t4 T$ } - return renderLayer;4 h7 h) M8 |5 A8 m9 M/ f Y5 u
- }. C7 W+ b! X& U X
- }
, d1 O7 O2 l# M2 o6 R" W3 w4 H - }
复制代码 |
|