|
W2 c T# Z7 A行,这个怎么样# J( j, N ^! _9 U! q! c5 m" Q O
- package com.xhg78999.mtrfac.render;
4 N+ h) S; c- q+ _" }
4 P2 _2 ~) d, S: T- import com.mojang.blaze3d.vertex.PoseStack;
+ e. U/ Q8 p4 b$ q5 d; q$ r: u$ _ - import com.mojang.blaze3d.vertex.VertexConsumer;, L' @# E k$ Q; b6 i% Z) d
- import net.minecraft.client.renderer.RenderType;2 _4 \+ i5 a2 F2 i3 l7 l0 Y
- import net.minecraft.resources.ResourceLocation;, ~+ \% |: n. L u: W
& r, k$ Z# |$ w+ q- import java.util.*;
" b% |1 P$ o( l' d - 2 x! x: b( o5 H
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, R. f+ r4 l& z7 u7 \+ ?- L7 L
8 u; x. \' _ V" y, H p- public class LineRender{
4 }: b9 ^/ O: S7 ~' N8 Z T( y - private final PoseStack pose;
6 ^7 b" [- S% D9 a- @; r' @ - private final MultiBufferSource source;
6 n' S0 v' I: j. n - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
m j' ]) }& X" P6 l) v) P - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: {- b2 i; `; R( i* M. I5 A: p) h - 9 S5 P4 k& P# \8 V0 E, t
( g$ Y/ x- N$ O1 o( R7 M _! ?- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 X3 v# h [: M+ S3 d5 y - if(x1 == x2 && y1 == y2 && z1 == z2){5 \, D5 T/ S6 e8 c
- return;
% S8 n* v) u: P5 L - }+ g0 G( [% ^+ v8 g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){+ W' z7 r! \5 B% Q# k2 y6 y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: z- J; a3 K( N
- }9 k3 e) P; O) g( u5 N/ R7 ]* w X
- pose.pushPose();
: K2 T& L; m8 y6 p0 |/ q0 `9 R" W - final int newLight = convertLight(6);
3 r, e* d) }0 N% n7 b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" u2 r8 I( o2 S3 |7 \! g, _ - final float lineHeightSmall = (y2 - y1);
2 U# R: m. b1 c/ y5 N4 @ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! I' D) d! A# ~/ A+ O: q8 L- c) u" T: E
- pose.popPose();
1 y% Q4 {( s" f$ ~. `( s - }
# m) Y# I4 k, s - , E- ~5 W+ C1 l8 G
- private RenderType getLayers(String texture, int light) {: k1 g/ g, B Y7 X0 h* D u' S* B
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 P+ C: X5 X5 `5 {( i+ x
- }
! o+ K; |/ J- j4 d/ r, B - # ` @; D9 T" p/ M
- private RenderType getLightTexture(ResourceLocation texture) {
2 n. {) L) z" _' _ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); P* q6 D, t6 d
- }
$ y, ~, f5 c5 B) f' [; K% j2 t - , m8 K" H# U+ w9 n: V+ N
- private RenderType getTexture(ResourceLocation texture) {2 i4 Q Q7 m8 x' ?. Z( y5 v
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);& [" x. v" x @% }1 c, l1 G6 S
- }
0 U& \0 ~4 g. }1 N$ L" D( _ - 9 t: m7 S) Y3 A- r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 ?9 n8 E! }9 ?. W9 R+ x1 |/ P& X8 h
- if (cache.containsKey(identifier)) { A+ Q7 f" b, _- V
- return cache.get(identifier);
3 w7 n5 d9 p5 D1 L+ R - } else {
9 y+ I) O* M. ~0 m( I& ~ - final RenderType renderLayer = supplier.get();
3 X. `% p/ { p" v4 J5 Y% h6 o- X# K - cache.put(identifier, renderLayer);; u9 O2 Q9 W& u* v
- return renderLayer;/ u, t. ~5 P& [- ~' [+ e8 I; E
- }
: A9 m# `( A( a. l, N - } | F2 `; h) \' T
- }
复制代码 |
|