|
|
. k) j, H$ p. E% \% C' e1 r: Z
行,这个怎么样
" c9 i0 g v* H$ o- package com.xhg78999.mtrfac.render;
* n' ~1 D' C+ e* I ]3 u - ) w4 E- ?9 i4 V+ @
- import com.mojang.blaze3d.vertex.PoseStack;% a5 X. \: n' S, [
- import com.mojang.blaze3d.vertex.VertexConsumer;
! `2 X9 ~9 t( ~' e4 A. R# u3 A - import net.minecraft.client.renderer.RenderType;
) P! T# A4 v+ M4 O- R - import net.minecraft.resources.ResourceLocation;+ C( c$ Z0 d9 H' n
- + i7 @5 \5 @( L& B* U# b9 w
- import java.util.*;3 Y2 Z: g6 J# ?: [4 {
- F2 m |- [: g; y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; u! ~! M; k( w) C+ I7 n - ( F8 A" R: v( ]. z: z
- public class LineRender{
- A! c/ [. o2 k5 h: Y. N - private final PoseStack pose;! j" u% ]) ^: u4 B2 C+ q) V
- private final MultiBufferSource source;) t# b2 V% R+ m. u4 ?
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 y% [+ d- v" E( }1 [
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 [& D- L; A. S) R* p
- / d6 h) E9 J% D/ F; a( x. b) A
: f: k8 G% c3 _5 k- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# N$ K7 H/ x: |8 d" J
- if(x1 == x2 && y1 == y2 && z1 == z2){
* ]( ]+ v) ]2 q2 ~5 \/ Q# x - return;
% [9 \$ f" z t# O5 v% m - }. y, h" v# b/ p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 |2 Q7 n! u. M5 _/ v. P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, K3 j/ S1 V- L: p4 ~ - }
$ Y5 `- s( T; w - pose.pushPose();
* Y0 A% a4 }# y# l; R$ x. F - final int newLight = convertLight(6);
. t# W& v, e5 l# h/ x/ R* R+ U - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% n: E" X# Z" ]5 I* B4 C& O
- final float lineHeightSmall = (y2 - y1);
( P/ T6 X7 F3 n! k( @ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# X: w* R# | [/ K ] - pose.popPose();
( Y6 F( B; o K - }
) [8 M6 b5 B6 ]" y9 Q& }, t1 ^! ]
0 t3 v. g; M, B X- private RenderType getLayers(String texture, int light) {
" ?: _6 m1 M5 S1 w - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 U }1 [- P6 S, |) I% L - }' ]; h, Q; d! V9 K( ^
- - b. ^' O/ v1 p5 c6 @: l' j5 p3 a/ n$ o
- private RenderType getLightTexture(ResourceLocation texture) {2 i8 g. ~1 q" d; X$ D, Z- @
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* Z$ f6 Z. J5 b - }
/ j/ \0 B9 ~- n" O& q
7 L4 [- r n; Y- private RenderType getTexture(ResourceLocation texture) {
4 j/ K: \5 J8 { - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& B1 p/ Z$ O0 ^2 G$ } - }
' O0 Q8 n' y; ?: ^ - ) R4 V8 S) n p
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ \$ d a0 p( j: W - if (cache.containsKey(identifier)) {
0 T0 B' d* P8 {* j8 v. a8 h$ `# m- D' r - return cache.get(identifier);6 r9 Y2 {1 r, [; D
- } else {9 W, w9 a" M- n9 R0 d$ P0 R, o
- final RenderType renderLayer = supplier.get();
* ^* H+ t; ~* R - cache.put(identifier, renderLayer);
# J9 n7 f* B- s - return renderLayer;
0 Z' X4 R% y. ~9 Q - }
) K) W; V5 z1 ~, f* t - }
* ?8 i! h c) I+ {" J; f1 G$ k. a - }
复制代码 |
|