|
|
$ h1 `+ j# K5 s. X: U行,这个怎么样
& D: b- O7 K5 S; b# j4 N- package com.xhg78999.mtrfac.render;: T( h1 S$ _" N+ X v$ k2 ?) f
+ y. @" ^: e9 J! j$ D8 w7 `- import com.mojang.blaze3d.vertex.PoseStack;% i) ~- _' R2 J) p: o* F3 ?+ v8 X
- import com.mojang.blaze3d.vertex.VertexConsumer;) `: p0 B9 g" n2 x8 ?1 `" h, H
- import net.minecraft.client.renderer.RenderType;8 k" \2 H S! F: B
- import net.minecraft.resources.ResourceLocation;5 R# x; e2 E8 k6 |$ o- M
- , y: ^. K% a: P0 |
- import java.util.*;: u3 O2 O4 Q- f. @
4 S3 B2 c& ~. z" L- Q* _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( a7 v' Q) s7 Q) ]! P2 f3 g8 i6 H
- 4 y9 L4 \! P) S8 Z+ O; c( l8 X, x
- public class LineRender{4 G! n5 x2 q) ]# B1 h
- private final PoseStack pose;
2 P9 P0 A& c$ N9 p- p - private final MultiBufferSource source;
# R, J* |7 L7 i* v# F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 w! Q4 y& B" d+ @+ c% U; t
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 M8 S. d b9 E2 ]0 P# M6 k - ( M+ ~! b. ?' n) `
8 i; r& @' H r- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 _# O/ w1 J1 S) |
- if(x1 == x2 && y1 == y2 && z1 == z2){
# b- v3 i0 c" h& H0 J - return;
6 S6 E# z, M7 E4 [ - }: ^7 d5 @( N% E1 f& c
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 M+ @3 A9 v }- O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" z% i8 L: V" m# M - }5 E0 t5 [- u+ U
- pose.pushPose();9 u" ~; V) q0 d+ P) Y4 |; ~( s
- final int newLight = convertLight(6);
4 p* l/ ~* r" f7 W: A4 P - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: O9 z, o6 m; T" k/ c) U - final float lineHeightSmall = (y2 - y1);4 R! R0 y1 P: G1 s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 J$ H- D6 i% ^. G7 }, G
- pose.popPose();. J4 ^: w2 W( W" h$ {
- }
7 r/ A+ x# D. N: S. } - / o; n5 o$ ]8 X/ w2 N" T* K
- private RenderType getLayers(String texture, int light) {2 `. o2 z: e( U1 ], ?+ ~; v
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 L/ I+ @3 a8 q, w# ~/ T& C - }. b+ e+ d) C7 r1 v! L1 W
5 P" o; q; E' g/ F5 j- private RenderType getLightTexture(ResourceLocation texture) {
+ k' V! K' R) d2 v- Q& Q0 ] - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' O7 U# u5 d/ C: ?0 D2 ^
- }
9 @1 n0 f3 D: D. I+ M9 C: `: e
' m, A2 n( |) |1 A j- private RenderType getTexture(ResourceLocation texture) {9 s5 Q6 k2 K8 l- o' O9 b* D
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# `6 `9 q# X1 A" \$ Q5 E - }) t2 s0 i n$ g2 I- w o
- " d; j; J. e; ~- c( E# v6 b
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {& o. j6 H4 I) ?
- if (cache.containsKey(identifier)) {
6 f1 c; k9 D3 P0 |. M" N$ L5 B - return cache.get(identifier);
% Y0 \2 |" K+ F' [& O0 r' ~ - } else {5 W4 L6 P# N. A; Z# Q
- final RenderType renderLayer = supplier.get();
$ W ?8 S0 V6 H* h) E+ O - cache.put(identifier, renderLayer);
: ]( h% o5 H& K - return renderLayer;
6 Y( V$ ]: |% c% ]) g$ E' Q. H - }
! N5 M0 a7 N0 p' m( V - }
* Q6 n0 p- C: i) x) O6 ` - }
复制代码 |
|