|
|
, x8 n: L; i: K" s
行,这个怎么样
4 {" x" o4 i- v$ V7 n- package com.xhg78999.mtrfac.render;
- m- O/ h4 `) |! @, l - ) l! L" z7 v# v7 D, B* ~' h9 K4 m
- import com.mojang.blaze3d.vertex.PoseStack;
$ L5 K+ \8 q, M% ~8 X3 X) Y - import com.mojang.blaze3d.vertex.VertexConsumer;
1 C. v% o- S3 e h6 I - import net.minecraft.client.renderer.RenderType;
' J' D" s+ T" k5 O. i2 B - import net.minecraft.resources.ResourceLocation;, ^ k. v& k5 n5 Y' x
5 S8 w7 m4 c) K* h* l: c; n9 R$ j) G! ]- import java.util.*;
- H& r/ D: l% B5 [5 B5 @, R - : h5 F) [! R( ^) j+ l" N
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; v; e$ L4 T9 C/ L) e: Y3 R% X3 v$ [
) ?# _) x4 U% b- A3 T, u- _- public class LineRender{- g# }# i- Q8 X5 a/ U. ]: m' S! G0 F
- private final PoseStack pose;! e6 j: e2 _9 s% i
- private final MultiBufferSource source;
2 j; a, z' p$ g& Q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) r) f3 Y1 o0 G: |, J+ ~: I$ q* O2 N - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ I4 z; [* m" j& b% W: o# X& X( `
1 y/ j* P2 K) ^% z- 8 v: p% B @; c# X! W* M
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; w/ w5 o4 z9 U( [# s+ ?7 N
- if(x1 == x2 && y1 == y2 && z1 == z2){
2 Q! _" f1 E: e. Y3 r - return;
" a0 R2 ?' @9 j! w8 t" E - }
' U. \2 W( I% `" z+ t" J - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! X) b [! c0 E7 Q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, S9 q. D4 X- j0 q3 y" n, a - }
# N8 s/ c' ^7 ^/ l; S* u0 H, \* k - pose.pushPose();+ g3 [0 P9 O# D2 b
- final int newLight = convertLight(6);
3 j, Q5 I ]9 [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( ]; H# [# c* a9 c' E, s( G
- final float lineHeightSmall = (y2 - y1);! ]. l5 S: W! d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 H& G) C: B. H3 A
- pose.popPose();( L Z$ Q( z+ j' K2 z! h0 x
- }% ^* d' R l% H
- ! O% b' ~5 U, O5 J% F, S
- private RenderType getLayers(String texture, int light) {
& L, x( U, u$ } J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- t3 q, U, v. T- ] - }3 G0 H, W! ?& e, p! r# w$ S4 v
- " E! p' |) J% {2 @' x- S: P
- private RenderType getLightTexture(ResourceLocation texture) {
6 b+ K! P, n# O% E8 G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! y( Y7 g' T) l4 z
- }+ [: k, ?" }% |/ F3 Y: ~
& T& v4 L" `3 s6 D3 l- private RenderType getTexture(ResourceLocation texture) {
. [& d# I: N) Z3 S - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 ]$ w; A* b$ R" S8 n4 _7 d
- }
6 u+ l. f1 l4 _0 ?# ^& h$ M - 2 n' r J& C% x2 l* w9 G2 m1 y
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 w4 `8 t' A& I+ _7 p - if (cache.containsKey(identifier)) {
6 X5 I- {9 [- S0 _) x - return cache.get(identifier);
$ C& m# a# ?& I* U4 V9 ? - } else {
$ V2 @! s% a" O4 |) ^" U - final RenderType renderLayer = supplier.get();
2 V) v- [7 }7 H8 A4 `7 a - cache.put(identifier, renderLayer);# b1 r) N$ h2 Y" Q7 O
- return renderLayer;6 s' ?5 S( @, q/ D
- }$ f' f9 b3 P. g9 h; Z% u
- }
$ {4 @% |$ [9 e9 d' h# { - }
复制代码 |
|