|
|
' H; }8 [" w# p7 J
行,这个怎么样
; f: P4 R$ g4 G# f- package com.xhg78999.mtrfac.render;
& I* u& g/ j. p" y5 E - 5 D, R/ E. A5 d6 ~: z' m
- import com.mojang.blaze3d.vertex.PoseStack;7 T4 Q- A3 V# w% B5 P) i
- import com.mojang.blaze3d.vertex.VertexConsumer;( H( s5 {# i2 Q: W" B
- import net.minecraft.client.renderer.RenderType;. n/ @* o- l* E) J
- import net.minecraft.resources.ResourceLocation;
+ j( m5 D* A8 A; h
0 t& n9 U+ P% t6 ?0 E2 l- import java.util.*;
7 d6 u( W6 E* F C, `* B# J# e - 2 r* ~9 Q" D2 g1 c7 g
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() B$ P& G B# `* Y8 q: F
- # k1 U; S2 r9 `7 K) `' H# k9 s
- public class LineRender{
1 a' h+ Z, a$ M u5 B - private final PoseStack pose;/ O3 a8 R& ]' z
- private final MultiBufferSource source;
$ s7 E# y/ u' b8 I2 R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 a0 A) A) T0 x5 f - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% i1 b0 B0 @: V4 o) k6 e& `3 I. A
) o9 ]9 s5 V' y6 z4 v2 h: r3 O6 F- ) W" f9 R4 X( A& I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
e4 O, g! }7 g3 i, T9 h/ z4 X+ h - if(x1 == x2 && y1 == y2 && z1 == z2){
2 b7 m6 } F2 g - return;' m- v% \+ t$ b! o- [
- }; |6 L, w7 q$ c! e' ~* _# k! H" \
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 y: H; Z% U" z0 l
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- w* L7 Q! d7 W- N7 g% G - }
. A2 E% {7 h0 n$ N9 K/ Q) s - pose.pushPose();1 ]8 Z* c5 o, D/ z
- final int newLight = convertLight(6);
3 P; d+ g- [$ s/ s1 o$ H - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 X% y" U( b/ r! m - final float lineHeightSmall = (y2 - y1);
% t, }% {( p- U6 O0 ?0 J' _# P+ {0 S - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 j- w, V Z" }2 o. \ - pose.popPose();
- S& I) [: \ z2 @* T1 q7 w# ~1 U, A - }
" l. } E% g* i# e4 v - 7 f" E' @! j& g3 \
- private RenderType getLayers(String texture, int light) {; P& x! m2 ~8 O! a# u8 |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 K+ O* p$ Q) f. t# B. a
- }3 C* P. q+ I' n. l" W% ~
% z* W/ h: `+ w* |, K9 }8 j$ P- private RenderType getLightTexture(ResourceLocation texture) {
9 P$ u+ x" | w! Y9 I8 B - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" k6 \" O# t; O - }- M, x0 Q8 {; ~: M0 H `1 U
- : V3 H" O2 H# E k8 g: d0 ^
- private RenderType getTexture(ResourceLocation texture) {
) O9 S" m# p" k1 j: a# @ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; N& q" U) g+ d: V; h3 I8 } - }
$ R) u" K- Q" v" V2 g& D
! C% T# j( i& g4 C- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ R4 ~5 Q! Z, G* t/ y4 P& s - if (cache.containsKey(identifier)) {4 p, [, d4 m9 O: b9 O) F& ~
- return cache.get(identifier);# F8 x1 u9 r; u) {& U4 N7 _
- } else {: O' P; Y R! B6 i5 ]; Q
- final RenderType renderLayer = supplier.get();+ {' K+ R* p4 h/ |
- cache.put(identifier, renderLayer);
7 d8 m+ n- Y5 B# _+ x. D7 U - return renderLayer;
& w$ q( m$ z+ v/ d; [ - }5 A; K& C1 ~( K1 y! ]5 [
- }
; [! J6 I4 ~2 E6 m, m# i" ]) f - }
复制代码 |
|