|
|
2 v7 ?- [' b$ r行,这个怎么样. i+ e2 G0 C! a5 {2 I
- package com.xhg78999.mtrfac.render;
% R$ {% Q, j# m3 c - 9 D' s* |5 A! o, e2 p9 u1 S! u$ V
- import com.mojang.blaze3d.vertex.PoseStack;
/ W- ~. A0 h( T - import com.mojang.blaze3d.vertex.VertexConsumer;- A2 O) S% O/ c9 J) M
- import net.minecraft.client.renderer.RenderType;
3 n# N7 H& Q! O9 Q* ~5 N1 @) f - import net.minecraft.resources.ResourceLocation;
8 h% K S Q. Q& J) e9 b
. J# `; K6 F/ z$ Q( M! Y) O5 o: N- import java.util.*;" l, B% P/ z5 |2 [5 ~# M
3 a3 }3 F9 M R- v- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; a/ G( A# D& A6 T
- 2 y" n# k2 C1 O3 p
- public class LineRender{4 [- q6 R0 X7 y" M7 i
- private final PoseStack pose;
" A' R1 [# g. d) F: @ - private final MultiBufferSource source;
! Z- R1 e, `, k6 C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 K( }4 k! Q$ J8 k7 g9 c$ y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% L! G. `& O( ?5 h& C* q+ d
" {0 r( Y+ Y4 J5 S w+ o- ~; X
0 m+ |7 }# j; T, z) e) ~' R. I) c- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* K0 k1 |* Y, H8 B - if(x1 == x2 && y1 == y2 && z1 == z2){8 u; Q, [# x7 u9 D3 y2 x
- return;4 ^! A, _2 a/ h( a! c% ]
- }( b; O4 T0 s% Z4 G" ?
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% @/ w$ j" `4 `; I1 R) m1 g - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% K8 M" w) z( C+ I, L- K, { - }0 M1 D: y& y8 U2 L+ P
- pose.pushPose();' E- t/ J# z2 _1 ?0 u9 A
- final int newLight = convertLight(6);0 q# q; c3 D4 x9 a
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 ]& t/ p6 Y. f, U$ p; A - final float lineHeightSmall = (y2 - y1);( A$ g3 Q( m( |, t
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 V% ~0 Y" t! c - pose.popPose();6 F( K# r5 p \' E0 a! I
- }
9 x; H7 K/ J6 w) B8 G& T
6 @6 D8 ^- a: t4 m; N# }- private RenderType getLayers(String texture, int light) {
, v# g; [% ~4 h - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 L# o8 \3 e5 b+ v
- }
7 s m# c- z: ^1 u f - $ F" U; U- K/ V* d* s- J3 Q
- private RenderType getLightTexture(ResourceLocation texture) {
- D( p, i" E" |# ~2 j* {* K - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 W k" Y/ A. J* g
- }
6 V1 ~0 f+ A4 e2 j# A) h9 a# X$ V - 1 J7 V% E2 ^ K3 e
- private RenderType getTexture(ResourceLocation texture) {
$ _0 c) o# d5 c8 B. Y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. C; C- Z2 e( ~ - }
: w( ^2 F) V2 L% }* S5 J - , d8 _) h2 Y4 [' ` |. I) I: }* x
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% ~$ M6 J' \ T5 g# J
- if (cache.containsKey(identifier)) {
, j, Q- H1 p, D s5 \ - return cache.get(identifier);) R' s: j" F* `& ]+ V8 w
- } else {
+ S; n& R8 O# E( c, ?0 m - final RenderType renderLayer = supplier.get();
, ~! |. ? v; G - cache.put(identifier, renderLayer);! Y8 L; d3 k+ z5 G3 q! e$ Y
- return renderLayer;7 _; \" ]9 e6 u1 E, X
- }8 h( f* P0 v/ H& P' h$ [( u0 g0 m" t
- }7 v9 M ~5 F( `# Y- P. o0 E
- }
复制代码 |
|