|
|
5 u$ x! n& c4 T! Y0 Z7 q* B行,这个怎么样
0 { X& Y/ @2 ]- Y. e' o- package com.xhg78999.mtrfac.render;8 ], A/ R( C. H6 m- r2 F! {
- " z/ |8 F9 q5 n# d L4 c! D
- import com.mojang.blaze3d.vertex.PoseStack;
6 ^- [# {6 o5 N - import com.mojang.blaze3d.vertex.VertexConsumer;, x2 X7 w7 C% ~$ n
- import net.minecraft.client.renderer.RenderType;
o& v- Q2 k' Q. t; L9 r( `( ` - import net.minecraft.resources.ResourceLocation;
: o& i' g4 l. a9 R
5 W( T% {0 ^* _+ K3 I* G5 P* L- import java.util.*;
* [' i3 y" f! V6 q0 p3 z
) b. l% e0 e* B( ~9 e- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ P' ~$ m; i% R$ j' L
6 }, ~6 C$ U5 d, I4 U- public class LineRender{+ E. V; v; C9 E' r. e- }
- private final PoseStack pose;
+ R( P& ^3 }. r, _- K$ N. v - private final MultiBufferSource source;
) \: ^) W( ]# a$ t/ I. Q6 w S - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 b$ s7 l) J. l( M4 O; y+ S6 V0 K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, I# t! @" \: _; [' \5 o( \
- ! J F" c' g# }% B, k* [" m* H
- ; O9 d& ?* ~; P& O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: ?! {' W' V H: E) C3 f1 B" b
- if(x1 == x2 && y1 == y2 && z1 == z2){7 Y x. R2 {9 N
- return;5 j8 o$ n' V2 u/ y1 `. D3 Y
- }
0 L; w% V6 Q$ _8 @) G - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% `" n5 x5 v, G1 ]$ X
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& d/ w1 v7 B! i& G9 ~' k - }
' g5 V+ _" ]0 a F% [" A- i- e" i7 P; @ - pose.pushPose();
2 y) N# n; D% R$ c6 Y* o - final int newLight = convertLight(6);5 Q* [6 z& S$ @$ Z9 O0 z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 Z3 _0 X+ i" A7 X+ ]- A/ b - final float lineHeightSmall = (y2 - y1);: i5 S6 r9 ^/ ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 f7 i8 N1 f% b' J9 i, u
- pose.popPose();
. b- I# ]+ m" t8 |+ M6 l - }
' n L6 z X: F0 h/ e" h+ @& D - " `0 x3 r6 r- h6 q
- private RenderType getLayers(String texture, int light) {; y5 c- a, l$ Z1 t( P" f+ x# I$ F
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: x- q W3 B! ~) v l
- }
4 p9 ]0 @! W; ]# B7 c - 4 n0 M5 R5 k& ]3 D; E
- private RenderType getLightTexture(ResourceLocation texture) {
$ c) A0 m# w+ \; }2 d+ j! u+ N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) b' K+ X2 D! I
- }
9 i0 @6 I% F% u! g$ O - . K: h& K+ a. N. j7 ^8 F
- private RenderType getTexture(ResourceLocation texture) {, Y6 V6 R4 E& g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 {, G3 O/ }0 f8 k0 Y7 w - }9 u4 g" U' k: |. l0 W
- / }% T0 u: L$ K+ ~% Z0 u1 t
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ w7 j# P( _1 {- ?7 b K, {
- if (cache.containsKey(identifier)) {* |5 V/ |7 h, k! O/ Z
- return cache.get(identifier);
/ X5 H6 e# f5 D. b; q/ j - } else {
: y( Q8 n1 u# `3 l& ]8 { - final RenderType renderLayer = supplier.get();
5 V& I: a L' A( }5 C7 |8 W$ {( K - cache.put(identifier, renderLayer);3 j! W0 T7 F5 e U+ u% a/ h
- return renderLayer;
3 }# i" @# L$ I - }
4 K' B" c$ [. N: l - }, L7 n# t4 H" k0 U. P( b
- }
复制代码 |
|