|
|
& f8 U% b/ h% w9 N. R4 x
行,这个怎么样4 g7 @. K% w+ x" w4 V
- package com.xhg78999.mtrfac.render;) r' t# w& }4 R0 L( W
9 z1 y2 _' p8 B/ B6 V n! u2 I; d- import com.mojang.blaze3d.vertex.PoseStack;
8 b b, H6 m( r - import com.mojang.blaze3d.vertex.VertexConsumer;6 r/ Y* u$ r2 ^- w
- import net.minecraft.client.renderer.RenderType;9 ^& K$ v4 r9 ?4 m: [1 ]! m# f* ]
- import net.minecraft.resources.ResourceLocation;3 ^. [: ` |$ ^: E5 B C) w6 O
- * O+ F; s$ o7 k1 X2 Z5 h. \ }1 ~$ @6 ^
- import java.util.*;- U% J) {4 a& n$ t/ ~
/ m7 O# ~- O5 M r" S9 H- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# ~- H: Q4 `- E$ I
& W3 q$ w4 m7 ]% m( ^9 ~, A- public class LineRender{& a) k2 R5 N* ]) m6 Y% O
- private final PoseStack pose;. o. o" u: C. @# d M9 }
- private final MultiBufferSource source;
I! J) p: V: y# A3 z, ~. M( z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 a3 j. q' _" r# c6 Q* l& t& O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. ?) ? @2 d4 i* Q7 u - : A( _; c% c" e. t/ n
- # g; E; o/ u- ]8 e. \* F8 r6 F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ n* |% z9 Z K$ ~- A( M7 f, \ - if(x1 == x2 && y1 == y2 && z1 == z2){
- Z" t: a9 K7 J2 n6 E - return;% |* P; j h) C& C1 G
- }, [) f" G2 U3 ~5 `# x" B7 q/ R8 F
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 ^" q# h2 h4 g3 v% m$ i& E
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 N5 F. I2 E- J: s" `
- }1 j/ I, D3 U" d/ y' y! q
- pose.pushPose();; C1 s Q: C9 b! O6 b2 D0 c
- final int newLight = convertLight(6);! X9 [& M2 d |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 O. Z+ k. Z! m9 p3 }$ A, D
- final float lineHeightSmall = (y2 - y1);- C5 E' J, W* a' ]+ G, {! j
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 @" Z, v, i# W0 V - pose.popPose();
+ X H8 w0 g# p( l - }6 c# i, G* m# B( g
! |- `( Y- u) l1 _, b- private RenderType getLayers(String texture, int light) {( K% B; J$ Q( ~& a {. @" e
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 O: W& t$ A$ m9 z4 ~9 m% j - }
2 D4 B7 o4 ?- l - _2 u! D5 m, q# y; W+ ?: m( W
- private RenderType getLightTexture(ResourceLocation texture) {
7 T) @& [. i# b T5 K" F0 H - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# V: R; c% c4 p0 K - }+ D# N+ m0 F5 q& d7 u; Y
- 1 x6 e0 d) E4 h) O3 w
- private RenderType getTexture(ResourceLocation texture) {0 R5 w% b& Z1 R3 y7 E& S
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ a/ @6 N6 Y- ~- @. M: X - }7 A: ?$ m y" T& m' q( v
# [: H2 k6 ^8 N% L" s/ ^" ~ U- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; s- Y8 A; V# c2 ^ B+ y& m$ b - if (cache.containsKey(identifier)) {
6 d) {9 }0 }2 e1 ] - return cache.get(identifier);! o8 j& N5 K U/ q5 w6 W
- } else {
7 Z W/ r. Z/ m+ ]5 ]8 F - final RenderType renderLayer = supplier.get();3 j2 Z7 z" V3 ~7 A' W
- cache.put(identifier, renderLayer);7 r# \$ M: ]" y2 e7 Q2 a
- return renderLayer;( U X" I" d X" Z
- }
$ e8 ~4 }: j3 T; W - }4 k5 T% O4 z0 u7 P
- }
复制代码 |
|