|
|
L% ?& V" s" t9 k6 R行,这个怎么样
G) ?( f- R( G; z# I. ^3 h& d( j- package com.xhg78999.mtrfac.render;
7 q# h. h9 ~4 X: g" @9 F8 Z
% J- p- \2 X' E3 X- import com.mojang.blaze3d.vertex.PoseStack;
; p% _) b, q& j5 Z% L' c. Y - import com.mojang.blaze3d.vertex.VertexConsumer;/ D* N0 M9 m: e$ s
- import net.minecraft.client.renderer.RenderType;/ N2 T) z9 M0 O
- import net.minecraft.resources.ResourceLocation;' g. c! X( b# V* Y2 w" c
- {7 @2 U o6 F+ T* h3 n- import java.util.*;$ s G( a* t+ g# `6 n3 G
- . Q e: a6 D( K X
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% U3 ~) }4 b4 H
- * d( l9 N. Z7 _
- public class LineRender{1 [/ k6 ~; g/ S! ]0 v- N
- private final PoseStack pose;0 l3 ~, s, _) ^# W) Z- `/ H
- private final MultiBufferSource source;
8 z0 s/ }7 P1 _' }; C1 R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 T9 b# e* c8 Z& [4 U9 o - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 [1 f0 h; d# s: s0 z* M0 v
0 R) k( U& W. B, R% I: i- " u- N: a$ i" e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' B1 a# g5 g6 m- j$ j4 S
- if(x1 == x2 && y1 == y2 && z1 == z2){; c! K9 S! L# I$ W) }* h( j9 F% l
- return;( v+ p. w, g/ E" m7 w
- }
6 S! N. ]( q& K% r* L - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! O3 \4 P$ d o; `
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");# _' I! L1 Q- v/ j6 b
- }
* H* x: X0 ~5 @4 Z: S- T - pose.pushPose();
% J, l5 i2 e! t3 j ^( O+ | - final int newLight = convertLight(6);
4 ^; X/ F) }% S! \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 |7 ?) \7 V) a: x1 ` - final float lineHeightSmall = (y2 - y1);1 d5 U& @* x7 S: w! C# B
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 q+ Y8 V7 f" v6 }3 A X: m
- pose.popPose();! O- S& }7 h! L
- }
+ q& i7 k+ {$ F, M - . X# w) M1 z2 B8 y4 v9 j2 I0 o, |
- private RenderType getLayers(String texture, int light) {# C6 ^$ ], ^4 i7 e8 V; Z) Y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) G, F7 c, v- X* C
- }
. V# \. {: `1 b: Y S u
9 B( o$ J9 J z% C" g- private RenderType getLightTexture(ResourceLocation texture) {; R* I: E3 H5 r% _! N( ]. [
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 d$ r/ b' M4 e z# Z4 D
- }( W D3 K. b' K
- 4 B+ I4 X$ c& \& |' r+ U! z3 F2 ~
- private RenderType getTexture(ResourceLocation texture) {! M, R+ M0 p; S* B& @& Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- _) n1 j, A. F* n. d1 q7 \ - }/ `$ Y0 j: e5 H' ^5 f8 j
9 L5 z0 A; j5 N8 d" l1 b- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {& h$ u& K8 J/ b2 H0 C _2 D7 e
- if (cache.containsKey(identifier)) {
; b X$ s: \3 R$ F/ {$ I0 v: y4 J - return cache.get(identifier);
& y$ _& l# a# z& s U# [ - } else {3 D8 s( _1 U, ^1 [5 F& B
- final RenderType renderLayer = supplier.get();' y# w$ `1 Y/ p C7 [, }: t! m
- cache.put(identifier, renderLayer);: P$ P, m, @4 V a
- return renderLayer;
9 f3 x9 d: T$ |- W$ H - }% f" [" [9 y# F" K* b! r0 p
- }
2 P2 |# h% K0 u5 M! C( N - }
复制代码 |
|