|
|
9 p/ Z8 q- D! Y9 U, k+ e# [ P行,这个怎么样0 d7 E- A) R5 D: S
- package com.xhg78999.mtrfac.render;$ J: T$ N4 L! ?% Y
- R; | W$ C8 W9 V2 L
- import com.mojang.blaze3d.vertex.PoseStack;
7 O6 q# L& X5 x0 I% b! o# e - import com.mojang.blaze3d.vertex.VertexConsumer;
3 b4 i" ?7 q) [, o4 \( M6 S, c - import net.minecraft.client.renderer.RenderType;; t9 T: n3 W+ s& j- _; z( C% d
- import net.minecraft.resources.ResourceLocation;" R) b# m: x/ T
- ]' R: s4 {# K. n3 ?- import java.util.*;/ I0 q7 P( Y; V& _9 a$ c3 P
- , x( U3 C8 V5 @' M2 e" A% ]& i
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: ~- I* J9 S' T3 G; \# Z
: [* \' B, F6 X% y- n- public class LineRender{
/ ^! S4 i1 k5 l) i5 Y/ C/ H& v - private final PoseStack pose;
7 r- v3 c" d {- u: M) o; [ - private final MultiBufferSource source; l/ T: T2 p! P5 B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 W V3 r' ^" G2 {& x' C- H
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( o5 p% U# H# V( f; ? - ( R5 ?. I) N+ Q. S' \( O
{/ T' b$ r6 i D- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
{& D0 g0 O p t& X! V% D# q% m- H - if(x1 == x2 && y1 == y2 && z1 == z2){
- F+ \4 Q, S& A' H( d; q9 D* g" S - return;8 Y. i- o4 \. a
- }- w. ~7 U9 r6 D
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ w% ^& R$ T v9 K; C8 a- F1 e- k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& A$ H7 [2 w2 ]5 I( m
- }% |. k( C" X8 a1 S8 ^' Z' n
- pose.pushPose();
5 H( T& K* i+ N - final int newLight = convertLight(6);7 w0 u' t5 U2 n9 n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 _/ ~0 F5 n( c; L5 @; Q0 q4 g - final float lineHeightSmall = (y2 - y1);8 ?; A4 O4 ^* b$ J* W
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
`! p1 {2 v, t2 [+ l2 f - pose.popPose();
) [; L5 ^$ H$ H5 }. U* d+ @ - }, _' p+ E' }) \4 L: s7 R
- 1 ]' [6 J, z% m) ~7 Q3 r
- private RenderType getLayers(String texture, int light) {/ f! \3 U& C7 O6 x# Y$ ^8 O; @
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* A: l0 I! U: L - }
1 V1 N7 x; H) _8 {
) ^9 E6 z3 h. o- private RenderType getLightTexture(ResourceLocation texture) {
9 l) p8 r) b* O; U' V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ c. b) L% C) {5 c* C
- }
% G5 g o8 E' o: l# } - 6 g/ Y% M l( t! P. v$ X# b4 l: Q
- private RenderType getTexture(ResourceLocation texture) {
/ I0 o0 c% y/ Q: S' O& o6 J - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) ~6 a" d% @. A1 |! b - }5 }1 S8 ^- F8 G* R* W8 O
- : {+ b; c8 ^! Q% }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 U* ?# z: p. v8 C- O
- if (cache.containsKey(identifier)) {1 L( P6 C4 Q( s+ ~/ V9 ]5 P
- return cache.get(identifier);
% N$ f4 b& A1 D( O5 H% y! K4 S9 | - } else {! Y& ]. m x7 L
- final RenderType renderLayer = supplier.get();3 x* Q3 { V X7 p8 Q
- cache.put(identifier, renderLayer);
) i% H( w0 H9 e( y, C - return renderLayer;, D7 m4 F: m! l+ {8 S" y# b0 H
- }
) g4 ~' u" j8 x- V7 n$ e - }
- M& I- H! F9 T8 I! { - }
复制代码 |
|