|
|
4 q+ A0 `& s' \4 j% `) @/ E
行,这个怎么样8 v8 Y9 l- H% m0 a6 `" b
- package com.xhg78999.mtrfac.render;0 G8 C" S3 M1 M( i
9 ?( s1 |+ O6 Q% X- import com.mojang.blaze3d.vertex.PoseStack;
`0 b' @4 w1 Y" W1 a- J7 N8 k4 r - import com.mojang.blaze3d.vertex.VertexConsumer;
9 u" Y1 y# i# }4 B - import net.minecraft.client.renderer.RenderType;
0 _9 }$ v& ?! F6 B! t5 P$ o8 {1 m - import net.minecraft.resources.ResourceLocation;
6 a8 c5 Z M' i2 R- j - , j2 ]/ p% F& ?; M& s8 |' x7 R( M* c
- import java.util.*;7 H0 u, ^" ]- T
- 4 z2 S# `! n+ D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 k u! v) @8 E( `8 s, X - ; F2 H. ~) {$ v% Y: U# U
- public class LineRender{
' q C' b+ f7 ]- c$ d2 ] - private final PoseStack pose;& X @" ~8 B w
- private final MultiBufferSource source;4 ]; `' C! \9 h5 r
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 n2 y$ |( q/ r% o1 H ~. c( y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( @, r' a. X$ y U0 C& W' v
- $ I( R2 L$ d" g6 C2 i: o4 s
- E, l3 T+ @( [. Z c- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& j4 S7 r6 j& ^1 T
- if(x1 == x2 && y1 == y2 && z1 == z2){% P& r3 s: e1 A. ?9 N2 Y. y
- return;! C) S, S8 v; f3 R" r6 [
- }! A- E3 a& ]8 S2 |* i# Z+ ~
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 v8 p5 a+ T# T) ~# j( U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" V( s% [ H- Z* P) }4 X
- }9 R& ]# c4 s/ D% G' t
- pose.pushPose();% ?' O1 Z1 H5 O9 c
- final int newLight = convertLight(6);
/ ~) n; l& d% G# Z6 Q* w- [: n - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 a) x' S ?) Y$ z0 M2 ?
- final float lineHeightSmall = (y2 - y1);: W9 X0 w+ w$ G+ ]' @, a+ d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- ?8 P$ e4 u# [* J% @) \' H - pose.popPose();
' F+ a! s; R- Y) W1 Z% C3 C - }
0 ^' ]$ x2 v. y* T9 x - 5 l3 e, \8 g; r- ?7 b2 `1 W
- private RenderType getLayers(String texture, int light) {
+ ~" Z( N) H2 L! d# s* U* v - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" F0 F3 p4 h+ l: u. b - }
3 E3 A* j% Q! G5 J/ s6 e - 7 a6 a: B8 W$ y& K, d4 u
- private RenderType getLightTexture(ResourceLocation texture) {
( R/ I; B* v# G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 I# {) o2 b8 j, } y- `! f1 w6 K - }
! @9 c. E4 ?7 S( y& [
* C; n% P& t) l- private RenderType getTexture(ResourceLocation texture) {
) `3 b3 h8 h: b - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
X1 B0 s) Y8 e! O M3 @3 E0 l* u - }
7 A: |. Y& E$ P7 [- ?; o
& t0 c+ d* @( S5 S5 [8 S- s1 x- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" O3 b- ^. E+ q- C2 Z n, J4 ^( B
- if (cache.containsKey(identifier)) {
9 `/ O& c4 I8 e5 F! C O4 P8 {8 @ - return cache.get(identifier);4 G9 E6 t5 | h+ o% ~" L
- } else {" |% |' m# @) z! p/ K H9 p# K) O
- final RenderType renderLayer = supplier.get();( d* d$ f' Z$ f# W" J
- cache.put(identifier, renderLayer);! r, |1 D1 v) J4 D/ i, G
- return renderLayer;
1 d9 u( P Z* k# P/ H - }
& ~. Q, A" m, S6 l% J - }
9 t5 B; L# Y* N% x( O - }
复制代码 |
|