|
|
1 j/ e# D) d* _* s5 k6 }
行,这个怎么样7 d' o) ]+ m# y4 M. [5 k
- package com.xhg78999.mtrfac.render;, m8 A7 b6 j! z. z% e+ ]
: D) Y2 \; }* W% ^- import com.mojang.blaze3d.vertex.PoseStack;
8 c9 r& p1 y8 L4 E6 O - import com.mojang.blaze3d.vertex.VertexConsumer;
# P, n# X: D/ w, M( C8 ? - import net.minecraft.client.renderer.RenderType;
. x( F! a2 D$ h4 c - import net.minecraft.resources.ResourceLocation;
6 Q. y/ o& t C( N$ Y! U7 A
3 h, E5 Q" c6 m: R- import java.util.*;
7 k, @6 h* ?- S# J# @ - 1 R, ^) b1 A1 h1 L$ z0 o0 ` J2 Q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' b( A# o( p, @# F+ J5 U% X - 2 i. K6 y6 d5 z: e7 ]0 T' a
- public class LineRender{
: m7 q/ s+ G7 G. J - private final PoseStack pose;
; \* K- \$ Y9 B3 Q - private final MultiBufferSource source;
7 f5 x6 Y6 x" F. x - private static final Map<String, RenderType> CACHE_A = new HashMap<>();% f1 B( U" \6 l2 l9 z: ]# `, t: m
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! y, T( c0 y! c& C3 {- h! s
7 Y9 h. ]6 @' u
% `0 {4 u' v( {& A" X1 S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' ]2 |3 c/ s D8 m- _$ K# p& t - if(x1 == x2 && y1 == y2 && z1 == z2){% b& r k# w4 x! d
- return;/ s. X/ g0 F6 D* O- F* R. A
- }
, _' U: w k* v5 S3 R9 D - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 ?+ _7 y0 X( z7 _7 R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" p! A/ L8 c) F, [/ ~
- }" f& M4 a: m% r% X
- pose.pushPose(); _ u% T) c4 l2 v+ d1 ]3 p5 S
- final int newLight = convertLight(6);6 g( T3 q9 b8 I; b( P) {# x. Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ Y- u/ H& R ?" ^ - final float lineHeightSmall = (y2 - y1);
5 e( d$ T3 z- w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 t: K8 A& e3 g" C' u, x( G - pose.popPose();
: N$ k m |3 ]; B) X8 L3 M9 O% Y - }
& H: S# O: P+ G9 z - v% [8 P8 h5 @7 i2 |6 U3 ?
- private RenderType getLayers(String texture, int light) {
5 Y! j! ~: `# c4 q, r2 R, z( I - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, c1 f4 S3 x# ~ w {8 L w- k* w: `7 Y - }
! L T- C2 y( |' R: L8 i6 B) |
. o% J) Z* y! |- \7 j# K* A- }- private RenderType getLightTexture(ResourceLocation texture) {
6 E, q- `" o D9 X1 [ E8 A" W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);% F1 {% R2 [( H" T( p; O
- }* P( ~0 \& l9 z4 q
- " Q- O1 {. }# m1 ^5 j8 L* C
- private RenderType getTexture(ResourceLocation texture) {
% \; d6 ^7 G C- O - return this.cache(texture, () -> entityCutout(texture), CACHE_B);; j7 I! L& J% h0 h7 _4 {* F1 q# V
- }
, L8 W/ m* R& s5 i
* [. o* J$ K2 e; p; h) h) X+ `) F- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 u7 N, k; p+ O+ R' v" ?4 e - if (cache.containsKey(identifier)) {
: o' s5 C8 @9 O) F* ^* D. A - return cache.get(identifier);3 ^$ S' |- _- {& ?" e$ E* ~
- } else {' S+ X/ P$ c+ B+ _ v+ [
- final RenderType renderLayer = supplier.get();0 U& N% `8 X7 F( S! r3 B6 h O, v( C
- cache.put(identifier, renderLayer);
0 X+ A9 Z6 j7 i3 y8 @% m - return renderLayer; ?: |0 e. c0 A6 n7 K
- }
$ m2 j1 Q7 u7 D \6 O - }# t8 t$ _7 \2 ` ^
- }
复制代码 |
|