|
|
5 g" J6 L+ R) t/ h7 Q4 J
行,这个怎么样9 W5 \* [7 y* z2 p& j( B4 R' i
- package com.xhg78999.mtrfac.render;
4 y" X; W. h4 f. y
6 ?6 n9 _% x5 m- import com.mojang.blaze3d.vertex.PoseStack;
F6 z1 @. Y$ F& ^6 H' [ - import com.mojang.blaze3d.vertex.VertexConsumer;
, F' y& u5 B; b% [: h - import net.minecraft.client.renderer.RenderType;
3 W" h U4 ]( e& T! _ L5 E4 F% |1 M: m - import net.minecraft.resources.ResourceLocation;
1 f1 B1 N) w% [2 z( s5 U' w
! p8 i$ Q& [# i) t6 d- import java.util.*;
. V9 P/ S; g' T; f. y: Q
/ y% w# m9 g5 b8 W c/ t- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 ]4 i0 n! Y; L$ _% ~# B - 1 Z5 L4 P2 p1 {
- public class LineRender{! D- |7 U8 Y4 p- U# p
- private final PoseStack pose;7 w! C! h; L+ q
- private final MultiBufferSource source;
. ~ S& V4 d" G( q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% g( N0 Q3 b! u- v - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- Q Q6 r4 e4 X5 j! G
1 z6 h3 d8 Y: K+ z8 S% s- 0 M! p% l! B. {! \
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){9 f* b8 N5 V7 Q# ^: _: p
- if(x1 == x2 && y1 == y2 && z1 == z2){* x* g5 H% n6 X% T' _0 [
- return;
- N, f4 ]' B& N9 @; P; p3 R - }
/ m$ k! h# L) n+ T - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, ?4 z2 G% D! c; O/ B e - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" D; m# ]# J$ w# T
- }
' x/ o( ^. b5 P6 r4 ] - pose.pushPose();- ?; z) B/ @" X' u
- final int newLight = convertLight(6);/ z3 ?* _( m3 V6 }% _, G/ h R
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
~) r. W0 V% G- u' k3 }7 o - final float lineHeightSmall = (y2 - y1);
7 @) O, e' ?+ J$ s+ {" X - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! z& l4 M1 u$ p - pose.popPose();
4 x5 y1 D, S$ ]7 i- g6 r - }! n8 w& `7 b2 s" A, n% e3 k
5 y6 R1 Z. @1 r6 m2 c4 c. r4 ~- private RenderType getLayers(String texture, int light) {7 Y% A* J# g( ?) ^) I
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 g# m1 x8 z: ]3 D1 r0 D - }( B4 m1 U3 O5 \, D/ T( Z
- * f/ r* C8 d7 k5 j5 l9 ^
- private RenderType getLightTexture(ResourceLocation texture) {( c1 ]# v$ t& U2 j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 |. [+ @; U: {; t9 w
- }
$ o/ H' i* m% Q. p C - ' Z" m3 r) W3 F2 T! s3 s" W0 S
- private RenderType getTexture(ResourceLocation texture) {
/ u' A. r/ F7 ?! h - return this.cache(texture, () -> entityCutout(texture), CACHE_B);. P. `: J' W. U% \! P0 Q
- }4 @5 ]6 o: o8 T& o8 D. w O
- " g/ K* A8 [( z# z }1 x2 H. `2 f
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! ~/ o2 l f+ |6 n - if (cache.containsKey(identifier)) {
* I. g# {7 q6 |& l( I: o5 M2 k9 X! j - return cache.get(identifier);% s/ D2 z+ C- i8 Q
- } else {$ P! A: w, ?& w; b0 ?
- final RenderType renderLayer = supplier.get();
* l1 [' I" w$ h2 |3 g* o - cache.put(identifier, renderLayer);
( h, _* K; S2 d- d7 P: } - return renderLayer;$ u: V2 \* |! B, ]
- }
1 f! R+ W- |$ K3 C2 i3 k - }
0 ?! d1 j& ` Z2 i6 c; [1 } - }
复制代码 |
|