|
|
4 k3 i7 q5 a( l" B行,这个怎么样4 `' `% g$ `4 c2 e y
- package com.xhg78999.mtrfac.render;! Y! v$ Y2 S6 `# v% v& H
- / \. d+ g6 [7 z5 ~$ h' G; [ M9 r6 C
- import com.mojang.blaze3d.vertex.PoseStack;) Z) Q) E$ a$ v& J' y5 a" L9 I) N2 P
- import com.mojang.blaze3d.vertex.VertexConsumer;
) d$ k9 f8 Z1 d% A - import net.minecraft.client.renderer.RenderType;
& h7 }- e: ?4 } J' Q, |4 u - import net.minecraft.resources.ResourceLocation;3 E$ @! g8 M3 [% E% _; L- S
- ! a8 @4 H5 S8 J+ j0 @
- import java.util.*;
) [( l6 j% A5 d% Y$ D
/ G; [- c! k9 j' `% a0 o- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() ?- X; n) t0 y* @! d& b6 F( P+ t
3 M! M7 b r+ v. g9 J% ^" r8 _. V8 l* f- public class LineRender{
" x W0 U9 ]( q1 g! W. x0 ~+ x - private final PoseStack pose;, M7 e2 A) L! j& g% t' o* F
- private final MultiBufferSource source;) L0 o+ Z2 y8 u) f h9 B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 u& R3 S* Q, T$ x - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( x2 e) y" H9 S4 I+ k - * [% B1 E1 m' m- | l) ~
- ) A8 J& `; f/ M1 n& o$ H
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 x7 u- b, L Q! j$ |
- if(x1 == x2 && y1 == y2 && z1 == z2){! A" y1 Q" q( j* d
- return;: R9 Y+ n5 R* _' n
- }
U& A- H' v! Q: N% T8 m# H - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ f. V" z, t% N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: j7 G" Q$ @: ~" O; v& x$ R
- }
% G2 Y! Y- L0 t2 M; ~ - pose.pushPose();
* T% x7 o6 r# ^ - final int newLight = convertLight(6);
R( }" T- W2 A - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: Q4 B' P; j2 y0 Y* V$ j - final float lineHeightSmall = (y2 - y1);* X* X0 [9 z& y: l! v- ~8 L2 d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 t- r$ e |* L, ` - pose.popPose();# s0 E; H2 n- w V# O; \
- }
9 K' V Y: _2 ]% E; a: _
0 A" ?& S$ U; z. Q- private RenderType getLayers(String texture, int light) {! ]& G, v ^8 E7 z; l. B. j
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: i2 B* d; }. q d* w
- }
$ p9 n- C9 |& I" P& b2 X: L' j) p
, e- ^" k2 ~0 V5 l- private RenderType getLightTexture(ResourceLocation texture) {) z2 }, C9 ?: T, h
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 j) b' Q$ s4 |, `2 ]4 L: p
- }3 E" k& G7 R& a
- / G o- B4 v' _/ S* m7 L* d. ]! ]
- private RenderType getTexture(ResourceLocation texture) {4 o: U& [! y8 l0 r
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' s- o5 O O' s - }3 G, D7 q5 d. {' Z4 y& {! @5 o
- " ^$ k* t1 h/ B+ V* {
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 K8 ^8 s l, O! X& A, R( A5 V
- if (cache.containsKey(identifier)) {3 v( J8 B7 j( A P6 Z& s
- return cache.get(identifier);
' a$ q* t1 Y% Y - } else {
* b9 V! X- ^2 z - final RenderType renderLayer = supplier.get();) H2 J, q* w5 c+ |% @- k, P5 G
- cache.put(identifier, renderLayer);" ^+ q u6 P1 @- O4 r7 W2 R7 @
- return renderLayer;* {- @0 W2 M0 u. {( R7 b* G
- }
( i) O8 l+ r* ^( Y - }
! t. {+ ^% P' u$ Z( k/ p: C9 _* } - }
复制代码 |
|