|
|
; a7 j, c9 N R6 b7 e行,这个怎么样
( y9 L1 `! H# ~6 G8 g( q- package com.xhg78999.mtrfac.render;/ }- `6 i; ]8 G$ V
& l. a' S3 N& ^# E3 n* i( U. t- import com.mojang.blaze3d.vertex.PoseStack;
( Z- x& h) v: F, }% r8 I* d - import com.mojang.blaze3d.vertex.VertexConsumer;3 Q$ o" ?- h/ b: i' ~
- import net.minecraft.client.renderer.RenderType;
4 m$ g) C+ ]0 ~3 i8 k - import net.minecraft.resources.ResourceLocation;/ v& C+ d4 r7 S
- ! Z) [5 e. N4 T- Z
- import java.util.*;. e& u! l6 h% i# H6 P4 C0 x# o! m' B
- 1 P$ Y0 w) L8 E4 {* E/ b0 o
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# U, m9 f3 h5 Q, | - + p6 b, A: d( Z' z5 @" X- w
- public class LineRender{7 C. [4 |7 b% V# a+ t- U
- private final PoseStack pose;( s6 `( Y* D" w% ^
- private final MultiBufferSource source;5 S% V2 V" |2 X1 o% q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();4 b0 v/ T; g1 u
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# l5 L9 l" ?0 \" ?; ^$ R6 F
- / V% [! d, z* `8 B2 Z
+ {) A1 P. b1 U1 b; Y) F- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- Q& D0 H( H7 [. {& n
- if(x1 == x2 && y1 == y2 && z1 == z2){
( ^6 i' i7 u. u% u9 }, j - return;1 h) H- B9 y/ A' X# I& r: y
- }
6 t& x q6 b9 d( X9 r- C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){& E, o v6 n7 O- Y! d
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) G* g* V# K8 X- a - }$ ?4 X9 k$ n. `* E( E! ?
- pose.pushPose();
: `9 X$ x8 g5 p! }& [ - final int newLight = convertLight(6);. |. ]3 j$ F1 b& H/ H: d4 k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# S, W/ z2 Y! z& u+ |$ x: i
- final float lineHeightSmall = (y2 - y1);
! ?% L) p/ B/ @0 I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 }. h4 Q: g+ C+ Q; F
- pose.popPose(); n4 y. ?3 i3 J9 n( a" P' L. E- ^- j
- }) M, p; ^. A+ m) g+ m* O
- & a) A; e" p# Q# _2 a" p
- private RenderType getLayers(String texture, int light) {
( q0 G9 e/ ?- M( W( A! Z* v - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 r0 q5 P+ t" A. F1 ? - }
! K4 }, S# o! U: ~6 e: S/ } - ' M/ g1 I T, U7 j' p
- private RenderType getLightTexture(ResourceLocation texture) {. v8 N$ F" m* ?; h0 t: G
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# Q8 D2 m2 O" U5 y5 f2 v1 e - }4 m( n7 a" l# q
- . D4 K, t; U# N( `7 g) @0 T
- private RenderType getTexture(ResourceLocation texture) {
8 v/ B; \0 y% F7 m3 T, P @6 k3 N/ N# x - return this.cache(texture, () -> entityCutout(texture), CACHE_B);- W0 L/ ^$ h2 o" Q; m! f: @
- }( k% d) l* `: P* j4 C. @: p
: C3 Z* s4 V# [, e- l5 D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 v; G6 Y* F- B - if (cache.containsKey(identifier)) {3 x) Q; }( h: o( \0 G9 s4 N
- return cache.get(identifier);
- Q; @1 V/ g# n% _$ r - } else {
g0 X: D& t% g - final RenderType renderLayer = supplier.get();
! U3 M7 P) M1 a! F* Q' p& n9 b - cache.put(identifier, renderLayer);
4 B7 [1 {7 \% E' B( F5 u - return renderLayer;. a" f! C1 f; h7 e/ {7 p/ N. p$ \
- }
: r5 K3 {( H1 E: b# g - }
4 b- J5 g# Q5 s% K' P - }
复制代码 |
|