|
|
" [% j; `; G j B9 t! J2 c8 u行,这个怎么样
; H7 u) t; |" e- package com.xhg78999.mtrfac.render;& p$ Q% U' }2 K3 B8 x
& H: z, i/ t$ B: x% p# d- import com.mojang.blaze3d.vertex.PoseStack;$ n/ i$ ?9 l( a! U' S& B+ t
- import com.mojang.blaze3d.vertex.VertexConsumer;
: `: \8 }( j) `7 K - import net.minecraft.client.renderer.RenderType;
" p6 }3 x( s; Y0 | - import net.minecraft.resources.ResourceLocation;
3 t# |/ f1 I" ?/ t% }/ F2 P
: e* l: m+ m9 l. H! Q' v- import java.util.*;- X) M3 u/ r# W/ s" u
- * V3 W- {7 J8 [% S! i
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) u" d: N& E/ @) w* T0 z - / w9 }8 ~( } S( Y& ~
- public class LineRender{
& f2 x* x+ v6 e+ g - private final PoseStack pose;$ S% f/ c1 x: O, T
- private final MultiBufferSource source; H5 i" C' y) H4 w$ t ?! @) H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ Y" w6 N) z# K& D1 C - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 }' F& N7 w: p$ p3 J0 u* x
- # S3 ^% C. M& H& S
- 6 M4 ^) {0 _! O$ i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& G4 G9 ?/ X+ A% y% |
- if(x1 == x2 && y1 == y2 && z1 == z2){* r8 ^+ i" Z% l5 f+ |
- return;
7 f! ?, t/ F3 _; P - }
" h, H2 v) a1 I+ b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. q2 \ C6 q/ s5 n+ b% a - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 [" T1 R8 T% s1 A0 ]+ E9 c - }, z6 H7 a# O3 s h9 I9 I) Q
- pose.pushPose();
* C& t2 F4 l! d" D( X! S( } - final int newLight = convertLight(6);/ `/ c( c) R- q, Q4 M. i* E
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; y3 Y& e9 N6 \5 h1 X
- final float lineHeightSmall = (y2 - y1);9 K$ i* r- ~) Y2 U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 v$ j# O/ v9 w* ]+ O! X" h) n2 C
- pose.popPose();) R6 W6 y: v9 M M; _. H
- }
. `# q9 P8 q$ H; J& j) s
) i! z$ c' ]. k$ m- private RenderType getLayers(String texture, int light) {/ V. b4 ]: G$ x) F: z% E
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ U X) X. e1 _0 C( j/ [ - }
# w, U. ~3 p v - 5 I* G' I" E) R+ v$ Y5 ?
- private RenderType getLightTexture(ResourceLocation texture) {6 k' s1 g& j) {
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; ?3 z" T+ k* y; Y2 b. _
- }, |4 @( ] ^- a6 G, H$ O$ v9 d
- & y3 O Z" e& _& E0 y
- private RenderType getTexture(ResourceLocation texture) {
, e6 ~! Y! \! ]3 v, w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 V$ [0 H1 m0 H9 d; m! G9 `3 s" c
- }$ z& |6 h3 g0 @* r3 j$ x$ T: S' L1 z5 r
- % w- m: ]( `2 X/ \ D
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 @" x4 l1 a! ?7 W - if (cache.containsKey(identifier)) {( L6 H# n* G( ~7 {9 ^
- return cache.get(identifier);
6 D# `7 u( _. `3 U - } else {6 Z* m% i4 ^4 v) N
- final RenderType renderLayer = supplier.get();
" ?0 d; ]" n. h" | - cache.put(identifier, renderLayer);
% v3 D4 |% E% I. N' Y7 v* |! ~ - return renderLayer;
! }# }. N8 O( t$ _2 I- l6 @ - }! c- i @6 E+ }( ]1 {
- }; j, o5 `& Z8 T& O
- }
复制代码 |
|