|
|
. Q8 e. q0 j$ |2 _ u
行,这个怎么样4 J! W" g8 j7 e+ N
- package com.xhg78999.mtrfac.render;
* u w; s5 N% P" R# u2 i/ z - " K' ]8 k2 @4 D' x* d' U
- import com.mojang.blaze3d.vertex.PoseStack;
* }; \+ y0 U9 m) E5 ` - import com.mojang.blaze3d.vertex.VertexConsumer;7 u. z9 h- L8 C+ `
- import net.minecraft.client.renderer.RenderType;: ^/ ^1 ~/ _8 Z. u9 B) ~: T
- import net.minecraft.resources.ResourceLocation;
5 W, t, w$ i6 [: a - 7 U# i- w9 a* W. S. [( L+ t
- import java.util.*;
! P r! r" b) o - 4 n9 O3 f# a( L3 E- |5 ^
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ v2 G( _' r( L% Y; V* `
4 p, C e/ o5 U; \: M( ?- public class LineRender{0 o6 e/ j9 g! G
- private final PoseStack pose;
5 D% h& P4 w% @2 }" @; H5 Z - private final MultiBufferSource source;1 f0 ?9 l, }. C+ U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" \- K1 j6 e; R/ O5 q# o3 j% e
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();3 ^) _. o" m0 W6 Q
9 |6 W( Q8 [( X1 R u- 8 I d' [/ G! D! I" v4 X* ]1 a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# s! q; T) c+ W9 M6 m" Q) ~ - if(x1 == x2 && y1 == y2 && z1 == z2){
* r; x, {) j" B$ i# P2 B! V! Q% Z6 s - return;
1 ^; W6 Q7 c1 s0 m3 A - }& b! I1 v# ^5 ^- T# o6 C
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) Q2 Q' \' k: H$ c) t6 i' M
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
7 u7 e0 x; K1 C0 x( O5 M - }
1 A/ W( o& L0 k - pose.pushPose();; H$ q& u% m+ j+ b* s- Z. h
- final int newLight = convertLight(6);
2 I5 ]* m9 n$ C7 L i - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 ~( K4 c E7 b1 c" ]* e% {6 M
- final float lineHeightSmall = (y2 - y1);1 w, n9 q* o$ s( a( i# M
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ X7 d/ U* _) e! z7 ~ - pose.popPose();8 u0 n3 Y, a/ X9 V) V
- }7 e) r" \$ R' k: }
! R5 P# H% P( W5 e- private RenderType getLayers(String texture, int light) {' g3 D3 L+ R# v, C4 L$ V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 a* H: K5 Y- ?/ v
- }) l- W) u: H$ a) n G) N! ^
- " G( A- \4 n! ?; j
- private RenderType getLightTexture(ResourceLocation texture) {2 L, J$ v9 D: L9 \: ^2 x0 [1 Q
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 M+ j* n$ P7 x! B2 ^$ W1 ]9 K
- }
* i5 W5 Z' E2 T7 J1 Z) R - ( N; q) r5 b$ J) i2 U( D* ]
- private RenderType getTexture(ResourceLocation texture) {
3 D2 f- z! ?* I; x4 i2 T+ b8 D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);* j- V) E" H- H: p
- }( n U$ Y, s, \- J0 A" G1 v: r A
' ]# Q+ \. `9 i9 \- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
" F# z- L) d! s: U- b% { - if (cache.containsKey(identifier)) {
$ n0 a3 x. Y: r2 D- ~1 q9 f+ g - return cache.get(identifier);' t+ j5 @8 R# m* e! w
- } else {- H% @. p$ W- e! K8 ~( `' i
- final RenderType renderLayer = supplier.get();4 u H7 q* ?% m; b% G4 G" Z; [
- cache.put(identifier, renderLayer);7 U1 l' w- h4 o6 E& @$ |( d4 ]! L
- return renderLayer;
4 W8 \/ q4 b, Q) V3 J - }
7 D6 n! p0 ]+ h: e7 O1 i1 `3 K+ z - }5 Y$ V4 p5 d1 Q& H; ~
- }
复制代码 |
|