|
|
U9 R* v2 G* j5 B, T
行,这个怎么样% ]' f+ W5 S i
- package com.xhg78999.mtrfac.render;
0 O! C; M' t. Z, ?2 V
y: Y/ ^: \6 U4 P5 v( {# {; N, K2 _) k- import com.mojang.blaze3d.vertex.PoseStack;
3 N1 `" Y5 r- y. X& K, t - import com.mojang.blaze3d.vertex.VertexConsumer;
* a6 d A' D% A9 M1 Y0 N# t3 n - import net.minecraft.client.renderer.RenderType;* x. E+ E; [) ]" ?/ o7 l! z
- import net.minecraft.resources.ResourceLocation;3 d4 Q6 u1 `% E8 V' v
, l/ V+ w5 h8 D5 ^- import java.util.*;$ j& N( x5 X- G% I- Y8 U1 v. |3 L- Y
- 2 u# W* b+ Z* i5 }& v& m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, ?3 A2 t9 C+ W$ B& B1 c" n4 V' a
0 w0 o: z5 q7 W8 e- public class LineRender{% R7 v) `0 H" e4 r+ L
- private final PoseStack pose;
( c; B2 e# b8 @5 }. i) H - private final MultiBufferSource source;
# N: X A4 e0 y% w - private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 n) q* Q; k2 @6 q0 d' U; _
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, T7 H- R0 D" {, G7 r" k; v - 4 u. E! V% P' q h# L) h
: O/ n( @: T( _* k8 }6 N. J7 o) }, _- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, ?+ O$ B8 d- `6 Y( M - if(x1 == x2 && y1 == y2 && z1 == z2){
8 g7 W% ~- D7 u! d. ~ - return;
& i: [) q2 |' h, t' D `% X - }4 O- i! y; V" @8 v
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 B2 Z: `7 \' I+ \' _9 N# L+ \ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 ^' }% v! }9 _$ S. N - }
& B) e' q, i0 Z - pose.pushPose();# v& @% J7 _) Z1 T: q
- final int newLight = convertLight(6);$ _! G' I( Y, u, b/ i- l
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% z( z; d' a2 \7 r - final float lineHeightSmall = (y2 - y1);
7 i& {& m. b. Q0 a - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* A& l c# \ H8 p/ ? - pose.popPose();
, j6 o" s9 x5 D# i7 n3 ^ - }& n+ W$ \, A/ C" r, W% G% t
+ ^. s m: r$ E1 ^, W- private RenderType getLayers(String texture, int light) {
+ o0 l ?% l: D4 D7 V( M. u - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# Q8 C% K/ @) X0 j5 L - }
) b8 J- X C; k( W# R+ x - ) | |) v' j' f
- private RenderType getLightTexture(ResourceLocation texture) {) B" l2 n; h. g3 r$ J5 N
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ K5 ~% v$ r7 x6 w6 I - }
3 t1 N% Z3 X+ z3 q% C3 A2 H
9 ]! B5 t8 `/ H# o- private RenderType getTexture(ResourceLocation texture) {! x6 W2 f& a, l$ t' J) ~- q, a
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 r1 a% _$ q+ ?3 K
- }
0 a2 e! Z: _1 K9 P
9 P6 [& V: s1 {& j9 V5 M" J- q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 K$ Y- k9 M% G& c" Z4 R; D, v - if (cache.containsKey(identifier)) {
5 k! r7 P. c4 F" N8 L - return cache.get(identifier);
# D$ y- V8 i. {9 f, [. K - } else { W1 v1 g$ u+ X, S! _4 ]
- final RenderType renderLayer = supplier.get();
! U* f& o& L) V H3 a1 T( c6 N/ J - cache.put(identifier, renderLayer);
4 T7 N; E9 V4 Q9 N6 z7 O - return renderLayer;8 ]# t; ~ e6 L% s% I, w
- }
( ?* Z3 X+ a, C% |' i - }
0 a6 n4 G1 A5 [1 n - }
复制代码 |
|