|
|
6 l0 k8 a* v, ^0 A% t4 r c
行,这个怎么样
* X. H! R7 _) K& Q: h% J- V- package com.xhg78999.mtrfac.render;% U- r" [, t1 Q1 a8 Y3 z
/ H) O! d- V! n- import com.mojang.blaze3d.vertex.PoseStack;* D+ m3 f% _( E
- import com.mojang.blaze3d.vertex.VertexConsumer;7 y& Q: ?* [& g4 _6 Q2 b9 {4 d
- import net.minecraft.client.renderer.RenderType;
) T* V! B! e) ]0 H. }( S6 ? - import net.minecraft.resources.ResourceLocation;" g( b( t% K8 b$ `8 j
- / w8 t# E' T# ]. ?- b7 ~/ q7 E5 r
- import java.util.*;/ ~0 k$ S6 D( R% g6 l0 U: |
3 {9 w: P1 k0 a# U) K- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 V0 X& Z/ [( ]7 `. K8 S
; B- f+ _- B+ I" E" f9 P$ [- public class LineRender{
! j+ ?: x2 ?+ W! {6 v - private final PoseStack pose;4 `8 S# }3 b" J9 z8 w
- private final MultiBufferSource source;
T! L7 A# L3 V$ t - private static final Map<String, RenderType> CACHE_A = new HashMap<>(); p, {# G9 ], L9 p. s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" ?+ l, i/ X8 t W, [ C& r - : W7 [& ?) k9 d. X+ `1 r
7 Y% e. P; f" K8 S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ e, G* z0 }! T" q* U4 k - if(x1 == x2 && y1 == y2 && z1 == z2){
/ T, i: F+ m3 _& F0 v2 E9 C# G - return;
4 D7 `8 o$ e; Y% w( I4 J9 k - }0 s) X! J2 t/ |% J7 p( a `
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( O1 f4 P5 ]# D; i6 q" V A# N9 S
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! z( F) s+ _8 F6 x' p
- }8 i& M7 c+ g0 D
- pose.pushPose();
) t, E7 I$ ]1 h' C) p8 ~9 r - final int newLight = convertLight(6);% | g# r6 B, N' G2 J) c% I
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
. {0 j- b# _$ S; s - final float lineHeightSmall = (y2 - y1);+ U. K2 H7 q, C6 i V! \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 X( c2 a4 V) m o3 I; `8 {; V% x
- pose.popPose();
; b6 d% N1 e8 E% W - }
5 R, v) D/ R6 |$ F
2 S- W0 [$ Y% i. Q( _- private RenderType getLayers(String texture, int light) {: `& O" Q; }- g; M
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture)); v( J- c( }# d2 t0 Y. c2 W( a4 Y
- }
5 |( v2 l+ R$ b T - & [8 ~1 G# E$ B( {% q( J) K" ]' L
- private RenderType getLightTexture(ResourceLocation texture) {- l8 \9 X3 m( C, W
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ g6 e/ d, \; L: p# w9 B8 T
- }
$ Z* g1 Q; k; h! {5 `' Q
# c" U4 `; k1 y" d- private RenderType getTexture(ResourceLocation texture) {
# w$ N- K) ^: C0 b# h7 V+ n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);. M+ B5 i; Z- B$ w( i5 V9 E: B! I
- }
% Z/ Q: G8 E5 }0 M8 D. x
, }( c1 l6 Z3 J; m5 [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% p: d$ E1 E' k7 {! Q/ O
- if (cache.containsKey(identifier)) {2 S" H8 a, H( @/ Z7 W( J2 u& g
- return cache.get(identifier);
0 @4 ?$ r% ^+ P0 ?/ Z - } else {1 T! S+ U) Y- i0 z# b
- final RenderType renderLayer = supplier.get();. ^" o* [0 S6 X
- cache.put(identifier, renderLayer);
4 [# n5 m& R5 w& {& h - return renderLayer;
2 `) E1 a4 r1 k9 o - }
3 V& p6 W' B3 W W( H - }
$ j9 i+ Q. b; a/ L" m; |# e - }
复制代码 |
|