|
|
; `0 ?- Q+ S3 ?- g4 @
行,这个怎么样: T9 _9 ~9 L' x8 |: u ]7 S( i
- package com.xhg78999.mtrfac.render;) _! |1 z1 |' d1 g
7 f/ E1 w6 a$ [$ c- import com.mojang.blaze3d.vertex.PoseStack;
$ w5 S' e7 [& O! r+ q - import com.mojang.blaze3d.vertex.VertexConsumer;! ^% T/ c# Z6 \9 f3 }
- import net.minecraft.client.renderer.RenderType;
8 w' R6 R- ]# \! i$ }6 T - import net.minecraft.resources.ResourceLocation;
w. f0 K% D7 A4 X
0 z6 S% X) j$ _3 Y2 H# Z- import java.util.*;# Z& u" G# Y5 J6 u
6 U1 z( f4 d# f6 l7 m- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! `1 T. K. _8 Q% Y/ N+ x- P8 h
" U, n3 M6 w! l- public class LineRender{
2 ]0 J) G8 j. M% |! g K4 ` - private final PoseStack pose;) \; _4 E$ ~) [# p5 k' h* m
- private final MultiBufferSource source;
. I2 w( Z2 {9 x( \. W - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 X, x4 [3 C9 `1 y' W7 D0 W2 v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* R( j' Q/ K$ f1 P' |/ L" ?
- ' P/ j" N: ~( _6 g
) H4 M; r# ^$ C. ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 r4 O* t( r" {3 l& L/ a8 } - if(x1 == x2 && y1 == y2 && z1 == z2){
+ ^/ K# X) \0 `" D6 s - return;. |3 `/ b) ^9 B/ p; e! y8 h1 ~$ o S
- }
0 J* Y, l$ e* y5 j+ E1 V - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) {; `# n( ~9 h0 ?+ c
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 H" ~( y& T+ a' x5 g9 ]8 w% x - }
0 s( N, {9 [# t# Z - pose.pushPose();
3 Z, \ U9 [6 i# j9 H4 Q4 [0 W& M# ` - final int newLight = convertLight(6);
v5 E. R& m+ [# W% E6 \/ w S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 ^$ g1 v6 \6 U9 s
- final float lineHeightSmall = (y2 - y1);
. [/ f, E, ?9 O1 q- d. J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! ]1 L0 F/ @ H( z0 ], `
- pose.popPose();
. O* L- Q9 _5 {# S; b - }1 P6 u9 H2 I: @8 a
3 i. d% f! r J) l/ [- private RenderType getLayers(String texture, int light) {) K. {( k0 y2 P" ~2 \& \
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ l" ?& K* _2 x$ Z6 [; a* b! k - }& Y! L' l3 s$ j* `" Z! t( Q* d$ W
- 0 o8 {+ E! [$ I( j- j
- private RenderType getLightTexture(ResourceLocation texture) {
! |- O0 _. Y# I$ N8 L - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 x* g) n- W, `% X( b - }. K! |+ ^* U" y# H2 A
/ G% N( e* B8 h. g7 h. w- private RenderType getTexture(ResourceLocation texture) {
1 W: V/ _1 C# V: o - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: {8 E0 K# E) b/ Y* F9 m5 U - }
. ~9 h+ `3 B8 n/ Y; Y' k
4 }6 \, g' q; |0 g& C- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; f4 w; W: c- s# O% v- ^
- if (cache.containsKey(identifier)) {7 \3 f$ g2 y# T# t6 J" M0 _
- return cache.get(identifier);- i# I k+ j5 D1 F$ e: x( Z) U2 l
- } else {$ g, h: w7 D( m9 H( m" F/ T2 O8 [/ k I
- final RenderType renderLayer = supplier.get();& i5 ^' B' m; k0 I, Y& e- P$ V
- cache.put(identifier, renderLayer);
2 F, V y7 S5 ~$ [; L2 J& } - return renderLayer;
& S4 f9 L% F' M- B6 _! a% P/ B7 a( D* ` - }
# L# Y' W/ {# j! h. |6 k - }
, B/ x+ ?, d! C# H4 @0 q - }
复制代码 |
|