|
|
7 [$ F/ H, n* S6 v+ M行,这个怎么样
9 d" g7 H4 B; ]/ |- package com.xhg78999.mtrfac.render; s% C, S$ o3 N' P7 H
3 p" s! X, n! a* y- Q* c5 }- import com.mojang.blaze3d.vertex.PoseStack;. @% i4 N( {! b+ Q
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 x$ B+ ~: Y) o' ^6 W1 c - import net.minecraft.client.renderer.RenderType;
$ p( \2 c6 {" A6 A - import net.minecraft.resources.ResourceLocation;
0 D# e4 {+ C1 s: G, z
4 T* Z2 G( ]0 \5 p {- import java.util.*;
& u1 o3 S2 `/ C - $ r/ n( B5 r$ w w- k3 f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% V( Z$ Q% E) O! v8 ^" F7 q
- O; L! m: w6 p- |# b \) W' e- public class LineRender{
, D/ g, s3 L! C3 r3 I+ S: X) L; a' N2 T - private final PoseStack pose;- o7 o, i* @) T7 g
- private final MultiBufferSource source;9 \7 u/ i# B4 D" g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();& J7 U0 @1 w& i6 p; w1 d+ o
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ ~1 l: ^, j# k4 o' D. t - . b- `. P. C4 \4 D
' }6 g& s& T. I* S' [+ e% H, K+ A- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; I3 e. w5 h+ G( k9 b
- if(x1 == x2 && y1 == y2 && z1 == z2){
2 @3 _' a# I/ e5 S) m4 D - return;
6 ^7 Q! O5 v3 G/ N. ` p8 N - } S+ F* b4 `0 k* c# j
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* t2 h" `; L0 V/ j% L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");# L7 z6 z5 ?* R0 v' Q h6 p
- }+ E$ Z! H( r* h F- K
- pose.pushPose();3 q6 z% l, C, ^$ W& W0 S( m/ C
- final int newLight = convertLight(6);3 @+ D5 }- D5 s' i4 L
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# p- T5 w- [6 J
- final float lineHeightSmall = (y2 - y1);! f2 H% {$ `# b7 C9 s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- Z+ I) U- R- A0 ]9 q0 }
- pose.popPose();& W1 ]+ L7 s$ N9 I0 ^; @! s
- }6 m3 X0 C1 ~& J! i" s2 A, p0 E9 ?
- 1 D" r' I6 d, W9 M: O( l; e" r
- private RenderType getLayers(String texture, int light) {+ y ~4 @" X8 j1 Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( V$ {2 M% H9 Q! v3 f( I - }1 u: g/ B1 |8 a1 k4 L8 H4 C; u
- ! w. V" B. O4 }$ ?
- private RenderType getLightTexture(ResourceLocation texture) {$ G6 `" p) s# O! J* ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, B5 x& d- a8 q/ [2 a* K, t
- }$ q: `7 @- a% c3 t0 L; { N6 B
* n7 W) M7 O! \, b$ T- private RenderType getTexture(ResourceLocation texture) {
9 J5 I8 U: r+ K! Y, R% ?; p - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: t* L$ |! P, H. H9 P$ [+ C - }4 O8 U$ b: o( V Q2 ~
- ; _/ r' Q3 }% d- K. Y$ x
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {, U% Q6 s8 B. `# p& M8 b% {' ?( H
- if (cache.containsKey(identifier)) {+ L2 g. r4 A0 S! e" B
- return cache.get(identifier);
) K: w% `8 } H% \: V$ {& o& C - } else {, z( O- w: }9 X" z2 t
- final RenderType renderLayer = supplier.get();
* t8 T" C0 h. V0 C$ {- v - cache.put(identifier, renderLayer);2 u H0 m. t$ O
- return renderLayer;
! v8 U: G4 h7 c3 y1 h1 d. k - }, \/ z1 Y! D# e) Y
- }4 f6 Y" M1 Y" v- Z
- }
复制代码 |
|