|
|
9 a" Y$ l, n! ?/ O0 A行,这个怎么样
5 H* S+ x* W* X( o: @' B! r9 x- package com.xhg78999.mtrfac.render;+ F0 K1 o! b* P7 U5 b+ K
- 8 F; r' {% T h6 k/ P. e1 P
- import com.mojang.blaze3d.vertex.PoseStack;
# l9 V1 F7 {' a6 E2 q/ k- J - import com.mojang.blaze3d.vertex.VertexConsumer;/ P) h9 A% `# S" E, ]9 C& c3 \
- import net.minecraft.client.renderer.RenderType;$ M2 Y* H5 Z/ O' {0 e5 [+ y0 ?/ e. P6 p
- import net.minecraft.resources.ResourceLocation;
5 Y, X5 E* M% A1 E
/ R( h* d8 E; A0 l- import java.util.*;6 G5 I& ]9 q& n
- 2 J! Y- |3 Y, Q2 J, \. n+ W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 p, u( H2 F, `6 _: v- {: w$ d9 V - : S$ B3 C3 R: E# F3 q7 j6 J
- public class LineRender{
' {7 s1 d+ i4 z# @. y - private final PoseStack pose;* w2 h/ P9 P8 u
- private final MultiBufferSource source;
$ v e1 v/ g+ a/ ] - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 p- ~ f0 S) {& c3 C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( g7 k# h( p* K4 X. C - ( \' Y8 T+ l8 a, o5 {0 \& h
4 |. `2 D: B, h4 l" h3 l- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){+ f! _( \$ q/ J6 G# \8 a' @% P
- if(x1 == x2 && y1 == y2 && z1 == z2){4 \/ O$ m. Z# K9 y9 M
- return;
) |% T) {; \, W9 m - }% Y& {* e3 I$ I$ d1 K) l" ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, J% i- H- N; y+ r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) m: D; E$ H& X+ q- C" x
- }/ i: h/ ?& {$ e$ W% U V; S: |
- pose.pushPose();7 I* E! w$ [& {# k8 l4 v0 j
- final int newLight = convertLight(6);4 d; ^) y& ]+ w/ `7 Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% G% k1 v2 T8 ?$ q c; N
- final float lineHeightSmall = (y2 - y1);1 U: E* p4 u. e$ J7 ?+ F
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) X$ Q' e9 W4 r6 K - pose.popPose();
4 K8 L+ c) A" u; D. h - }4 g5 }) r- H( _% h D1 Q
- : x h6 I8 C/ J, ~
- private RenderType getLayers(String texture, int light) { l. M U+ p2 {
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 [/ J0 x* a A& `: v; O V# y$ n - }
/ D2 B5 \9 t' B - / t* o3 \% l0 o7 x. E) Y5 y$ \
- private RenderType getLightTexture(ResourceLocation texture) {
# M( Y' U9 e3 Q$ R5 D" h( V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
7 [* x" V: P9 ~- C) z - }
( Z" W$ l3 N$ Q, Q' t/ a - : n! x t0 H8 H6 v3 L# H7 x
- private RenderType getTexture(ResourceLocation texture) {1 Z# j: U7 t4 b
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ ^# v% o# M, [$ X; D. b# X* x - }
- V6 a7 a6 S/ C6 g5 h& W. Z - 1 K0 `; S: s- A9 t3 h$ J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 D8 y; c0 h% s
- if (cache.containsKey(identifier)) {
5 S1 J/ @% A& a+ N. O) M9 S - return cache.get(identifier);
1 }4 c7 o1 \$ f" m! x - } else {
& y6 n, Z0 A# b# l# | - final RenderType renderLayer = supplier.get();9 e2 K7 _+ I6 x) q% G' c
- cache.put(identifier, renderLayer);
! H" o4 k3 c8 _- f, h - return renderLayer;
2 `7 s% r) x" X% I6 P: | - }6 U4 K- h9 F+ S6 y$ L- _% b M# @
- }: S) ?6 T3 ~) d& h! S0 a
- }
复制代码 |
|