|
|
1 T/ X$ ]" h9 x' t- C3 ?3 ?行,这个怎么样7 X l5 A, h% M8 f) z" Q9 H' G
- package com.xhg78999.mtrfac.render;+ A; Z9 |+ V$ \# I
- 8 e' A+ h5 J M& y& V! h
- import com.mojang.blaze3d.vertex.PoseStack;. s! E$ ]! ?6 K8 f- t" M
- import com.mojang.blaze3d.vertex.VertexConsumer;7 x5 D" C# q$ b1 @; E
- import net.minecraft.client.renderer.RenderType;
+ A2 M8 U9 n% X# b- N; L$ u - import net.minecraft.resources.ResourceLocation; c& ~, R A' c7 k' a% g
- " _3 q+ ?4 y t$ o' W
- import java.util.*;. m$ R. E; m1 b0 b: b6 _
5 J+ c& j/ \9 M; U6 z `' O- v- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! w2 ^$ M! r! g& Y/ C" i& D - 9 a! k/ a$ g( g% {+ q8 p, T$ K
- public class LineRender{
; v. u$ `( l6 n" ` - private final PoseStack pose;: Z/ y7 ^9 r. _$ u, I
- private final MultiBufferSource source;
* M6 I$ C: x& Q9 J# K - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ e" _$ k; |; j1 E - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); O& l. }9 z0 n( j. Z. w) C
- ! V0 J Q1 u7 b5 S! ^1 z
" q9 q0 ^7 [" G! g' j- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 J) T/ e \1 F. E* c - if(x1 == x2 && y1 == y2 && z1 == z2){
% H. O. g1 a& Y# r; }1 u - return;3 ^& O. s3 V' M. K# S
- }
8 ?' O* g5 ^- P7 u' y" N; q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' z$ t( m; t6 @* h% A2 H/ ~
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 I6 F! a2 e$ H& E+ l
- }
4 d& J7 |) ]1 W4 C! w* `1 T2 d - pose.pushPose();1 o( U3 ~; @- r
- final int newLight = convertLight(6);" P: G( ^5 {. F% S$ Z( X
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 v( a& [/ G! u, h: N2 R& I! Z
- final float lineHeightSmall = (y2 - y1);
3 G9 l. t7 @/ u* W, x - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 t1 O; n" E) h5 ^/ t/ ]7 n
- pose.popPose();
( Y$ A+ O7 O# P% p `+ { - }% w9 ?5 F. q2 r- N( a! w7 t
- S4 l: q: ~: n" i m( J( ^: g, W# i- private RenderType getLayers(String texture, int light) {3 F2 H8 d% q3 W: `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 b7 _. H7 Q7 k9 n - }/ h; k' @7 Q! @
- 6 r, R4 a. `, Z! ^. R+ H
- private RenderType getLightTexture(ResourceLocation texture) {
/ G# J1 b2 t( T' S, V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% ]/ ]/ L8 x/ S - }
" ~, j+ n; Z: g; U8 O
/ b" f% P" u) A7 |: J- private RenderType getTexture(ResourceLocation texture) {2 l9 Q3 m7 j. N/ s v9 l S
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; e* n0 u0 [# U' p9 Y) N4 L
- }
9 R. }) u# g" R5 m `; V& h - $ Q! |! Q6 q8 P9 g
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 `8 r/ x* M# K3 N6 x
- if (cache.containsKey(identifier)) {
. ]0 I0 h" ?/ ?- ? - return cache.get(identifier);& v9 I: [1 S( u" I) d* q
- } else {6 w# _$ S; G6 V
- final RenderType renderLayer = supplier.get();5 o6 ~- y# R8 D! ^) r( B. c2 M7 `, V
- cache.put(identifier, renderLayer);
( [) y; n2 K. J* g% U - return renderLayer;5 ~& {# o5 p/ h8 Q6 c0 I. x
- }
8 Z2 N @: d& \2 g% F3 z - }
6 O a1 V5 G& S% _ - }
复制代码 |
|