|
|
2 r* V: u( M0 q- R行,这个怎么样3 ~0 [2 y+ ^- Z) W, s4 b: B4 m
- package com.xhg78999.mtrfac.render;; m8 L6 ^: `) l0 w/ [ h3 Z; Q
- 4 W2 c; E% C& {8 I) Z
- import com.mojang.blaze3d.vertex.PoseStack;
) u9 N4 U0 e# U. l! p, L - import com.mojang.blaze3d.vertex.VertexConsumer;
Y0 l$ b A# T8 U" v3 ]! Q - import net.minecraft.client.renderer.RenderType;
9 W( J5 F4 G" P% R# v - import net.minecraft.resources.ResourceLocation;, f: i, A! }& a1 Q; f
- H4 ?& t- |9 [6 k, p, H! [- import java.util.*;- g% B0 b$ t+ ^4 `3 b
- u5 Q b- N; R- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 M N7 A3 u2 D- A
1 `" y& D4 b0 Z) E" B' Z; y. \5 r a- public class LineRender{
7 I$ {6 o3 X0 N& |' k6 ? - private final PoseStack pose;
& i) h% Z# O- H: W$ i3 n$ x7 F - private final MultiBufferSource source;& I+ K' A: T* R+ Y9 o1 r- i# N
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 ^' i: u' R; ^; |4 M* a% }1 X
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" U% T" ~% d5 ^0 d( Q( a - ; V9 |- o4 I& e ~4 \1 M9 [6 A
, d% }# `' U/ ]$ f1 t. C o- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 b( o9 R9 M: j6 Z7 l! i6 k% X
- if(x1 == x2 && y1 == y2 && z1 == z2){' r) X) D! ?/ a+ n
- return;9 J' m9 V/ _9 X; E! c' B! q
- }4 P9 C! r. a. N9 o
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 D( H" v' |- M/ i& O
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) _. Z: v8 l8 {) s/ R& j% M$ u - }
) u& y- C3 T9 l1 P4 P; H - pose.pushPose();6 }6 ?3 G+ D! ]: a( l
- final int newLight = convertLight(6);
$ y& x2 \8 v) `) H% @1 p0 K, r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));3 G5 ^* x% @) `0 d& d
- final float lineHeightSmall = (y2 - y1);
# N# K. s1 c4 P4 O - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% r( C' `0 ^' [& i7 Z* v
- pose.popPose();' y% r/ z* z) O }. g& G
- }$ l) M- Z S+ t$ k% o5 n7 T
& i4 N- d2 m5 ?. t+ \: E/ R0 g0 ]- private RenderType getLayers(String texture, int light) {; N# l O7 @9 K: B% V! l2 o* ~. W
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: }2 K( a$ g* A, D% m: \# m7 c, p: ^% S
- }+ `& v' @0 H0 T8 r" Z* K- D
* ]& j" O: U$ C! N0 |- private RenderType getLightTexture(ResourceLocation texture) {4 s; ]* g' n0 Z: @' D Q( c
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% ~7 a X0 {! v: ^- e, N1 P - }
' R6 i' f8 E. x2 `# |9 v) \/ V
) i4 F" [, F8 t& U2 G8 e9 h- private RenderType getTexture(ResourceLocation texture) {8 O' M0 M+ M$ K8 w
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 T; M' [: k& y6 l
- }
( r( U! t7 F& A& t0 }7 z* u - ' K V: x/ O# m, k& B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% }2 c' U& g# L" A& O4 u; E2 i
- if (cache.containsKey(identifier)) {
) x0 }+ U! J }8 \, U - return cache.get(identifier);
4 q- B6 r2 M& e! R, m( i - } else {: ^+ `2 X! W, w/ ~& E- y6 P: S
- final RenderType renderLayer = supplier.get();+ a! x( u7 M# W. T; Z9 t! V8 J: k; \
- cache.put(identifier, renderLayer);
* {$ {9 R2 Q7 [ - return renderLayer;; J& M3 x' {0 D/ @* E$ q! W
- }
0 ~/ v4 o7 B& ?! @! }. b - }/ f- u' O& u# R ^$ P
- }
复制代码 |
|