|
|
% N. P! O5 T( s% |
行,这个怎么样
; h/ e. B2 x, g, B$ p5 _- package com.xhg78999.mtrfac.render;
. K8 H2 O* {+ U' \
3 S& ]& l' A/ x6 n! U5 G4 o0 B- import com.mojang.blaze3d.vertex.PoseStack;
) h" o6 x6 L( l7 D6 @) z - import com.mojang.blaze3d.vertex.VertexConsumer;
7 J, N* w1 x8 ]1 q* b- v, W3 B - import net.minecraft.client.renderer.RenderType;
; X# L$ T! G8 I" b0 Y, \6 p - import net.minecraft.resources.ResourceLocation;
+ g% N: N6 I* _% q9 y/ t% U - ( \( z% x. B2 b, z& a m5 I
- import java.util.*;
' K1 T9 M$ O' ^4 x% n1 O+ }; ^6 Q! C - 7 G+ V9 g( \1 P1 S! F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 z5 X7 U+ l4 |+ H5 O' \! |$ I
- 6 P) v) q+ B( k
- public class LineRender{+ |7 L4 H3 P' y$ X. u: @+ y, r! K6 y
- private final PoseStack pose;
" [5 c6 y5 q, k! h! b2 [ - private final MultiBufferSource source;% j4 I" `# B% I: e/ O1 D1 f8 g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) V: E7 c! S+ Y* I& ]+ { - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 V: p4 b) D9 n
$ @5 s a9 M: m) ~& ^- 6 P* Q$ r) L Y) _4 P- n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% @4 M9 c3 ?8 ?" X
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 @1 V0 e' w: l - return;
, o: V& ]) c, v, d: | - }5 _% X* f3 O; \8 u3 p4 N' g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# y) p3 _7 k8 O3 c. `8 Y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 P& u: N: S5 P9 u) J9 V, t - }# M* o9 Q# v" P9 I/ R" G1 O- i
- pose.pushPose();
; @ @1 g% Q* C3 q- t% A - final int newLight = convertLight(6);3 n1 d- s/ n! h" k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));4 Q* N8 v/ j! q/ `# m/ @
- final float lineHeightSmall = (y2 - y1);
+ c4 N$ D/ u# s' U5 `- | - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: R% W6 x5 ^# Z9 j
- pose.popPose();
# H' k" X" Q$ F9 M- p% D8 c - }
( k0 o% n; |6 Z
. L/ ]( o( y! e. q9 I, x7 P; L- private RenderType getLayers(String texture, int light) {
1 m7 ?1 o4 z; w+ _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 D7 }8 w4 @7 {* z. r5 W - }3 p" Q9 v% `- {% t6 f6 P8 [
! m" P, i. W, v* c1 N7 O. z- private RenderType getLightTexture(ResourceLocation texture) {* d# P: \, I& f6 M3 p U0 j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 r. p. p9 d5 A" }+ R! v, m4 _ - }1 a2 Q' N2 t8 j
- # _4 w( |- A; C. o) s
- private RenderType getTexture(ResourceLocation texture) {$ h& D3 ~1 F( @' M) [
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 V. G) v6 w; G |
- }- C, N5 b0 L3 Q8 }3 Y1 N
- : |4 n3 @2 K4 v/ |. N& L4 u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 O2 Q$ U5 F. {4 N+ d, v& e! Z - if (cache.containsKey(identifier)) {- U- S6 Y# V& \7 ?' B1 e
- return cache.get(identifier);
# ^" z' b, Q0 ^$ B, a% k2 A - } else {
: |5 x C& W9 z3 w) e; ? - final RenderType renderLayer = supplier.get();- r# B# {. B( d% \
- cache.put(identifier, renderLayer);: u' L8 Q7 h8 K
- return renderLayer;3 w. r9 _2 M1 b+ j
- }
* H' F' j7 T: g; p - }9 O$ E4 N6 {4 e3 b, `7 X( N$ X
- }
复制代码 |
|