|
|
) l4 i. b5 a$ c r; Q
行,这个怎么样' {0 w% i+ v- m. U: O
- package com.xhg78999.mtrfac.render;
+ `8 W! }2 W8 y" U6 x
9 u# r, C/ d9 S8 c$ {- import com.mojang.blaze3d.vertex.PoseStack;, @8 Q6 O; ~: V8 s
- import com.mojang.blaze3d.vertex.VertexConsumer;
& E/ S1 ?( v9 m6 O5 E& u) G - import net.minecraft.client.renderer.RenderType;
2 E: u( Z) v+ o2 M# o' N - import net.minecraft.resources.ResourceLocation;& b- H7 `1 i( {: C5 V0 [
7 S& Z* W7 v2 r4 {- import java.util.*;: S- o% y* I0 C& T6 s+ X4 `2 [0 j' Y
- 9 \( q2 h/ F4 e9 ^
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& W/ Y, [1 F' r/ ]( `1 M* z, l
- # c1 L" d, h5 C: B
- public class LineRender{; N& L1 [$ l& R
- private final PoseStack pose;
; J# J2 j5 K8 n' q6 l8 _! G) U - private final MultiBufferSource source;* }! m6 O3 y/ C7 s0 h% q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- T# E3 }# X% _6 f - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- E/ Y) i. B; T - / P, ^" u; k5 X; m! n% S' Q
) d0 I- q8 X+ |- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. y2 G: ?6 G9 I - if(x1 == x2 && y1 == y2 && z1 == z2){0 F4 C" m$ {2 o, H' d
- return;
* s* ~+ A0 l3 u* E6 d) u/ s - }$ p, a7 B% B! V6 q1 q. e
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# G' h& B) q+ b7 X
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& Q9 p3 s! @& P+ v
- }
: X* R& Q8 o! @7 f5 @9 s - pose.pushPose();
" \6 g" |6 e6 J$ N# R - final int newLight = convertLight(6); |; ~# j- M: K( _' B; v! o
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, v! S m- H/ B8 }% l+ w" V" e3 M - final float lineHeightSmall = (y2 - y1);4 u3 f; ]. ` i# s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: q( m6 C3 ~8 }& [- l+ w
- pose.popPose();
% Y- L8 n' w. G - }
0 g: F Z# q; p7 W* l - ; C: r9 y% k$ g5 B, d: L
- private RenderType getLayers(String texture, int light) {3 k( }) Z* S( i' Y$ y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. E: F7 S% h: U$ ?" a; C* O# c - }/ S) ]6 U. ^) R: M+ N* g7 q
- / A% `% w9 V. k/ z
- private RenderType getLightTexture(ResourceLocation texture) {7 f8 ~/ _8 g9 v
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ S- a& Q F9 i: p
- }
# d9 n, S; }- g. r7 h
S& k# t0 G2 i% l- private RenderType getTexture(ResourceLocation texture) {+ G7 {* a8 P' P7 [4 r
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 Q% B: \2 M0 Y1 B" C9 a. B - }
! U9 f; \+ r- M9 {" y - / \" N5 F: A- n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
" j q; ?1 E( F+ Y" b - if (cache.containsKey(identifier)) {; } ]) [3 p# d
- return cache.get(identifier);
! _. O( Z8 Z4 c' M, }, A7 o - } else {
% M7 B4 c0 w1 X2 [ s* |& N - final RenderType renderLayer = supplier.get();
: |6 D+ K3 P7 t8 y9 j4 Z - cache.put(identifier, renderLayer);$ M4 C$ T' {- I! }9 b
- return renderLayer;9 D( z0 O a W2 `
- }
, [& s" ]" `5 G5 _+ x6 p% q( G" ^+ s - }
- W3 H& u0 a$ ^! G - }
复制代码 |
|