|
4 C4 D5 t# D" l/ f
行,这个怎么样
$ g2 A& B# t# c; ^; n1 H1 R, m- package com.xhg78999.mtrfac.render;3 u, U: n1 E+ r+ `: ^1 s2 l
- 2 e5 n# t+ b* _/ ~, B& q i
- import com.mojang.blaze3d.vertex.PoseStack;
( |0 c: n( J) f. K, h, G# z8 e# y - import com.mojang.blaze3d.vertex.VertexConsumer;
) O. r9 b2 `/ C/ W4 A9 t( e X - import net.minecraft.client.renderer.RenderType;# D' }4 Z* a/ W* t! d
- import net.minecraft.resources.ResourceLocation;
* M1 z7 d' D0 R
$ x Y! }" u" X& J h- import java.util.*;4 W2 P' I8 T& c" f- g+ p
- : M8 o. O/ P2 g
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 }9 C# Y* J+ w5 f7 q
, Z, \+ N& y U! F9 \) c! k- public class LineRender{
/ J9 U* D/ T+ L( j7 A: w7 x5 k - private final PoseStack pose;
3 t! e- j; O3 y* U - private final MultiBufferSource source;
# C# u; m2 C! C0 @ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% x5 j8 r2 C0 v# @, ]/ T ?" R7 D - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) ^' n) i; g# H8 ~ - " g! f0 _1 W% T! a1 P5 X# i" m J
- / W3 {5 k, B: i; y9 Q! E! s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 b. C) w1 W0 p
- if(x1 == x2 && y1 == y2 && z1 == z2){3 L6 X2 K4 c6 Y. w* c
- return;: C7 x/ E. `5 b4 A/ }" R! g, V
- }
8 n' V% j3 ?3 v) ~$ U, S. J - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 e* k, T. Z0 N# a
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! V9 M# a5 U1 l$ A: T& Q' o
- }
& g! D0 Q4 A, U0 P2 i - pose.pushPose();% F: Q8 p+ `" V" H7 t
- final int newLight = convertLight(6);2 o+ @3 e" L% r: b6 D: E
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 n- C `% G8 U2 a) Q
- final float lineHeightSmall = (y2 - y1);
5 }) X3 f3 e( ^+ } - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ P$ s. t( c& V$ ~ - pose.popPose();
. s& i' A# _* T; y - }+ ^; G; u0 K% t. U0 e
- * E' C9 [! {& P
- private RenderType getLayers(String texture, int light) {
; u8 ^) Y3 k% B: m2 N( d- [7 A - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* d& b" @: d6 N [3 w, W/ x2 G# E
- }
7 X$ h' G4 d0 S& A) R - , r2 ?: {3 r9 O/ {
- private RenderType getLightTexture(ResourceLocation texture) {
9 I: C! w. ]# ], A. L9 M+ E - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 P- N3 W( \" w9 { c! d - }4 p2 P/ y7 Y- p$ V4 G
& [& ^/ ], n" F. s0 G; _- private RenderType getTexture(ResourceLocation texture) {9 A3 X+ u/ I- J7 _& L6 z
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 l1 K8 X1 i" T, R
- }5 M8 y. i4 m" {* q+ W$ C
- 8 V6 M O* h) `, Z9 q7 h
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# u5 j& F# \) Q. u% u - if (cache.containsKey(identifier)) {2 m! U5 ~; ]2 ]% e7 b
- return cache.get(identifier);( ?# I {5 b: ]9 K& L5 Y0 J" O2 M
- } else { X; j( o! x6 u1 @
- final RenderType renderLayer = supplier.get();" o& O, V; {* \7 _$ S1 f8 K6 c* d
- cache.put(identifier, renderLayer);0 h7 m% ~ G! i! W w b, U, n% \; a
- return renderLayer;$ I# Z3 U) |) N6 x' @2 L% {6 `
- }
; M, G: V7 K( t' H6 m - }
' V$ J- |$ A. r+ L- e' V - }
复制代码 |
|