|
|
% q/ V8 E. \4 o7 q: M3 J行,这个怎么样
0 I% S! ]6 s, [2 B0 C) I5 X- package com.xhg78999.mtrfac.render;
+ }$ T3 |5 u: H6 n. q$ T, V0 d b
6 f! m0 i0 c2 N# X% h6 l' O9 ], t( P! L- import com.mojang.blaze3d.vertex.PoseStack;3 [: z7 Z, M9 }7 X; @; S4 m7 l
- import com.mojang.blaze3d.vertex.VertexConsumer;. U* b/ N! h7 k; q8 {8 b5 h
- import net.minecraft.client.renderer.RenderType;
6 d' b; }; ]' a5 ~; G - import net.minecraft.resources.ResourceLocation;
0 W) h/ L' f. a/ W
, n: B3 x* Y3 o1 H9 Q: }- import java.util.*;0 y1 l. X" R! G1 }/ z2 {# b1 |8 j0 m% P9 Q
7 F& `. ` O, j+ V6 R- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! W! x" U! u/ [: U9 _; E# K
m: `0 k9 b' L* @4 Q+ `- public class LineRender{. ]9 Y! d6 d. l8 M/ a
- private final PoseStack pose;
1 T2 e5 ^" ? h. v# b0 E - private final MultiBufferSource source;' ~, B0 d! K) p1 h; r, O/ [
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();, n2 P1 C; B( C' C0 N( j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 j1 I5 H3 {8 I; I2 f: v+ c
- t8 `7 D. H8 d) g) i
8 q' N# d, ~$ n* g) U- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 o* e& J+ ?0 B# c( M
- if(x1 == x2 && y1 == y2 && z1 == z2){
P* w1 O, Q: Q' L4 G. r8 f! y - return;
' X& N, u/ ^9 P( Q; X - }0 i. z- P x. T" l# s' p# N
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) l1 g$ ~) |0 b! Q6 V, s3 s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ g' z Z7 X! c; v1 {
- }
: o" n* M B' @: R- `6 v5 K - pose.pushPose();0 i# N7 w! A- e4 w0 A9 [2 y
- final int newLight = convertLight(6);: D/ u/ K: T% D; B/ g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ h. \: U: @3 U ^& q" @
- final float lineHeightSmall = (y2 - y1);& m, [3 h& d: x0 j
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" h' Q& v7 n2 g5 A - pose.popPose();1 n/ H; `8 ^* ~1 [/ ^2 J5 C
- }
D, N# Q8 P4 H3 f+ N - 8 B0 Z! e7 L" p9 h# y5 ~8 z
- private RenderType getLayers(String texture, int light) {+ F- a8 x9 s7 s8 K
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& J; ~! b( |& v! l3 @3 c3 w - }/ |, J0 K: {9 B5 V" f% l1 n
- 7 C6 v9 N* E/ Z) K3 O+ b
- private RenderType getLightTexture(ResourceLocation texture) {
1 B6 h z$ j- P) f l - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
7 \9 Y, Z. }' w7 G - }
* t& E1 V. h+ ?5 D# T
0 q; \. X: [# e. k+ F- private RenderType getTexture(ResourceLocation texture) {
( n7 p5 V# |6 K) G- V* U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 T0 n& E, z+ d+ e0 ~) l! [
- }
3 V0 E7 r p) n6 _' S
% q1 v/ f6 E, C4 W/ A- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, `' e" D3 b/ `" X - if (cache.containsKey(identifier)) {! }5 [/ n2 ` a; f! u- f1 y
- return cache.get(identifier);
( S( Y8 y1 w9 b% ` - } else {
5 B. q. M6 I) e9 b/ P5 V% M - final RenderType renderLayer = supplier.get();
$ j. r% w. O Y' ]0 f - cache.put(identifier, renderLayer);, C$ _7 a% Q% ?' S' \
- return renderLayer;8 ^1 k* [8 J6 _1 m" o& |
- }
' s9 y; x8 w. w. H9 o: B - }
8 p. e% }5 p9 Q+ B - }
复制代码 |
|