|
|
& w3 c' Z# a; h* Y* F B2 a9 g行,这个怎么样
, B1 A0 I7 _% `/ O- package com.xhg78999.mtrfac.render;8 E8 g) c: l% P, M
- & G% O# ?7 c# M2 a
- import com.mojang.blaze3d.vertex.PoseStack;$ Q/ H0 T, N& h. k5 k, ^
- import com.mojang.blaze3d.vertex.VertexConsumer; W9 A- d. c6 L
- import net.minecraft.client.renderer.RenderType;
8 \6 T2 A0 P4 O C1 D - import net.minecraft.resources.ResourceLocation;
' n- V' ]; h2 P. s
8 K1 A9 `7 K7 V4 W% H- import java.util.*;" \( _ _" H8 a3 A
( H( [: `6 V: C0 a+ T0 Z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" n4 T ~. F9 o _- M$ X - 7 z. }; j7 x/ b+ }. Y' m5 S
- public class LineRender{3 k7 ~ |4 S! j( r
- private final PoseStack pose;4 R( H3 d$ I! J0 @ p7 g7 w& d. B
- private final MultiBufferSource source;
, ]" h" `0 I3 \' x6 ^ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 w$ V3 B h& t2 R! q6 n- p - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, R! U) }- R" i0 S
+ t+ d9 B& Y- V0 l- 5 i) Q9 T# f. L; _6 y" k8 N
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. G1 X+ k; O5 b6 n( u) x - if(x1 == x2 && y1 == y2 && z1 == z2){
w, P% L" k ~# ~/ y4 _. l+ V - return;
% b c3 F$ n( G - }
+ l) p) f! k+ C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- i( u% h* Z; v
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. ^$ ]- R: q$ y" ? P
- }
. N" O. G$ [9 K) q. U7 |: j( z, z1 n - pose.pushPose();& o) ?$ g- E7 V% c
- final int newLight = convertLight(6);3 L F3 w: z2 s- {, b. Z+ ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' t: j4 \2 D& y+ |2 m( ^* V9 z, y
- final float lineHeightSmall = (y2 - y1);
& }" o% G, [# ~6 n5 T# M9 h - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- e; n5 d: T8 g5 M; {# X# j2 W
- pose.popPose();
, K! R7 d5 G, u- P: O$ m - }! J* W1 a& t6 s. ?. z( y
- i, C& Z, {: |- ~# L& i' o) U$ G- private RenderType getLayers(String texture, int light) {
: f/ P6 k3 F! C/ g; V - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% D& A1 W, l) C6 s# Y - }( u4 C, a; w; C' U5 [
+ j+ z& c: b% ^* b5 [" i4 e- private RenderType getLightTexture(ResourceLocation texture) {
$ C. {/ k0 x; c/ Y. n - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, N* m/ i3 X- G" O j: o - }
/ A: X! k9 `, L - P- I6 w# }: |8 l2 `
- private RenderType getTexture(ResourceLocation texture) {
7 o# U `/ L4 t7 }( A - return this.cache(texture, () -> entityCutout(texture), CACHE_B);) ^+ @- T: A+ N4 N J% p# Y& K
- }1 |+ k4 f$ V \% k) R k; B
- 4 W+ m/ Q% E6 i7 N# L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- e, R# ]' ?# C) A
- if (cache.containsKey(identifier)) {! T7 N3 g! G6 Q2 J
- return cache.get(identifier);
( C6 U! H1 I9 R5 O8 k- u$ J. q - } else {
! Z% Y) f* E* _4 Q# j/ R$ V. f - final RenderType renderLayer = supplier.get();
+ y% a+ k3 V- D( P; p - cache.put(identifier, renderLayer);
0 b- b0 G) ^4 ]7 b: n( i - return renderLayer;
+ w) c- W0 f/ Z& U- t9 z - }
$ e3 V5 B. B2 M) N% ~! J - }
* q% n7 I7 X" r - }
复制代码 |
|