|
|
1 n( v$ @7 D4 S3 x& Q/ ]$ O4 b
行,这个怎么样$ }8 U% `" |& C# }7 G! `6 z/ m: R
- package com.xhg78999.mtrfac.render;
0 }: D0 H3 U, S9 z* `. \, ~
4 K% s% U6 Y ?5 ~- import com.mojang.blaze3d.vertex.PoseStack;
7 q y8 L# v9 X t% `6 R v' W - import com.mojang.blaze3d.vertex.VertexConsumer;
) ^% B% q, t: L - import net.minecraft.client.renderer.RenderType;
- @6 V+ I, _+ Z( G Z - import net.minecraft.resources.ResourceLocation;( |: V; o/ Y0 T
. _$ S1 q+ }8 z1 G- import java.util.*;
( `" E: z9 T- V, K5 ?* o0 `1 L
! u, U" e, I E, e) ^& {' A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ J! L% t* Y$ P+ J
- 5 X5 G8 q2 Z5 M; T5 `, \$ u9 q! Q
- public class LineRender{
6 O7 A6 w7 Y' r6 o - private final PoseStack pose;3 k9 T9 Y! p: w# D7 T" e3 ~7 G
- private final MultiBufferSource source;
: w& @3 O3 G9 l W' P& g - private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 z: q* u c. @. u5 ]! a: V
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); H9 q1 K* n; O) E5 w
: K' t+ \0 \. [- * u8 H7 @+ `1 Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! l9 q- y Z3 ^7 f. j) j( K - if(x1 == x2 && y1 == y2 && z1 == z2){3 w& G* X2 j6 S- H& Q
- return;# ~& I1 G A! L: ~6 d; r! c1 O
- }
& n. C/ k$ O, V! N8 N - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" k& e+ _; p8 o, B- }3 b& z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: s1 g+ l% r" b9 f; D8 H
- }
& B3 j; ^3 E+ _ - pose.pushPose();
! [4 B1 i4 X, [, C9 m0 S - final int newLight = convertLight(6);) ]" @/ W, p! X+ l$ q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 s8 W# H* H' D& |, L' `8 _
- final float lineHeightSmall = (y2 - y1);
$ @% w& n' t8 ^+ ^; x0 F* t- N - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
V6 H9 O& Q$ U; ^$ m1 y8 K- z - pose.popPose();- U5 x" c5 i& j4 N
- }) G' X% F F5 m" k
+ |: C5 h/ ^/ k; O8 ]- private RenderType getLayers(String texture, int light) {- S( ]* d ], F) |( J" B& F
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; n9 i: \7 ~* P1 w- i
- }
2 G, S6 W+ i! w: l
) x8 j% O4 U/ G" X- private RenderType getLightTexture(ResourceLocation texture) {
' b# ]+ U; ~5 s5 E2 J8 E - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. G6 a0 j8 N, Y9 _ - }8 v; K$ I# }. A
+ P$ M8 L; ^( f6 X5 Q( c2 ~- private RenderType getTexture(ResourceLocation texture) {
f8 Y7 S# W4 S% [: I - return this.cache(texture, () -> entityCutout(texture), CACHE_B);! ~6 N9 u8 g. a5 |
- } b2 g5 }3 ^! D1 D0 e
8 E1 H3 J u( U* ?6 B- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& b I8 t% N' n; d - if (cache.containsKey(identifier)) {1 E3 O8 q6 P# ]: x) o: J
- return cache.get(identifier);- g7 k. @/ I. i1 r
- } else {1 W& ~5 x4 U, ^: B z7 i
- final RenderType renderLayer = supplier.get();
1 C% { z% R5 T, X3 b$ t - cache.put(identifier, renderLayer);6 Z- ~' i; ^9 E. H+ C
- return renderLayer;
4 O+ m3 F! f$ K/ K& }6 z y( q0 T - }
. B, t1 X% [0 @( ^/ ] - }
6 z. o E& H( V - }
复制代码 |
|