|
|
0 P3 S/ t3 i0 Y/ G; v$ D( N3 G行,这个怎么样) n& m' z/ ?. i0 k# W. B. S
- package com.xhg78999.mtrfac.render;
4 |4 L9 J, F6 k* Z5 R
8 \ D+ N$ ]( _9 b# w" O2 B0 j- import com.mojang.blaze3d.vertex.PoseStack;. f+ U1 i2 z7 q( R
- import com.mojang.blaze3d.vertex.VertexConsumer;( |7 V& f" _2 \1 |; W+ m$ `
- import net.minecraft.client.renderer.RenderType;
* c+ \( \. k9 }4 s/ X - import net.minecraft.resources.ResourceLocation;# `' i; Y6 o0 F R% o0 ?: s5 d
- ) f- `% I. Z$ q; f
- import java.util.*;8 t m; d, S. I# s+ _+ Q* a" Z7 r
- ) F1 Z7 M6 f- D* u2 W+ ~& y0 l
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 D! G8 I+ V H* W. G# f
2 b: V; X/ d6 T9 P- public class LineRender{/ U" J# U0 d& S8 A
- private final PoseStack pose;$ t0 f7 Z; A; {& g& o
- private final MultiBufferSource source;" w$ k6 R# r1 p% _5 ?0 K7 L2 G! `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' m4 n. g0 j+ {$ j! e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! v* k' F. r1 E% M% n S- Z( [
( }4 q5 K$ B* ?# j
" D; G @1 @! v* f4 X" ^- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ R. g3 G* O6 w8 w7 w
- if(x1 == x2 && y1 == y2 && z1 == z2){0 r" b# z$ Y& B2 U" w5 Q& K
- return;
. n4 m- C5 g! y1 ? v6 g - }
2 C) N- B- B5 _0 j0 I- N# O - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; B) W1 [ J& Q, j3 {
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* S) N- z7 ?! E( O0 M2 k i% f! i1 Q+ } - }
: Y& ~1 G1 ~8 H. G; m4 w - pose.pushPose();
7 b' U2 {/ ?8 b3 j6 A4 @ - final int newLight = convertLight(6);* g% @+ g* F2 ]7 B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: b( ^* c& J& k) E" d; Y# ?2 v - final float lineHeightSmall = (y2 - y1);
/ p! Y# }/ u! I( I3 l% a, _ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" o* t. N9 ?1 v7 m - pose.popPose();
: j }' Y! X2 {1 A: ^* ~ - }
/ `- y/ F+ P4 t( v5 B
) D5 D$ a2 V2 ~: X- private RenderType getLayers(String texture, int light) {
7 z; G& I/ n) _5 ?4 h, r - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' W' d B! u3 l8 u( B+ x
- }: R" C( A/ V6 f4 C# v
) r6 c& `' N7 C- private RenderType getLightTexture(ResourceLocation texture) {% r0 q0 D! s) b2 m! N" p6 s! y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) j- R4 E! _. c - }# n1 T; N# y+ Y# c( e# F5 [# z
5 c C9 P& x! n- [- private RenderType getTexture(ResourceLocation texture) {8 J2 g* E/ n8 X8 Z! ^' ]
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);. ?) N: _0 d; n+ |/ B( T2 I$ |
- }' y) m8 \% F4 T% q# ]- C
- ( N& P: U1 O" Y+ R& E" l% A7 }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 s0 _! C5 t+ R; T: @& r - if (cache.containsKey(identifier)) {
, Q) \0 p1 J0 z" v - return cache.get(identifier);. Y! E; r- I* M- S
- } else {7 s) g+ s) z$ E
- final RenderType renderLayer = supplier.get();
* G& E) f' S) I. V- z - cache.put(identifier, renderLayer);
, x% {9 W" q# D( ]3 R' y - return renderLayer;
" D! d* J4 Q9 t* c2 ]7 o5 U - }
3 f- R; x( o( m1 d. R$ [5 U - }
+ U7 b" C# T0 ^" E - }
复制代码 |
|