|
|
) T5 M; K6 }' E8 m2 D; K
行,这个怎么样
+ P T( S- L- ~6 R- Z- package com.xhg78999.mtrfac.render;
( Y# O9 ~$ J$ i9 M2 K& k1 C - 8 [' R1 u" V/ J% V7 @& {
- import com.mojang.blaze3d.vertex.PoseStack;! b+ R2 q" r2 E( u* l! o0 P# l
- import com.mojang.blaze3d.vertex.VertexConsumer;
( O9 H3 W% h" U1 w& x - import net.minecraft.client.renderer.RenderType;
+ g/ \9 z+ e$ V( z4 r - import net.minecraft.resources.ResourceLocation;
: f% z' Y$ h5 ^ - 5 E; h+ v5 Y0 e; x$ o# d m* J
- import java.util.*;$ K+ D7 ~& [% N+ I E
- ) ?2 M/ W; J- i9 i: ]0 D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. I8 {' M, I, z( a6 I; F
- # y, [" {3 F6 g/ }4 S
- public class LineRender{0 T1 o+ e8 L9 r7 K/ w0 K' E
- private final PoseStack pose;
2 X! G- l% W! d e4 t* }$ k - private final MultiBufferSource source;
1 K! g. R- k* y% d! e* I) G - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# f8 y! S% d! j - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 \2 W( d$ g# V# \
! Y! q5 @3 |7 P" M- w7 D! q. R
' h9 ~+ ^* v" E4 Y g- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( A: Q' t0 e5 K+ d! y8 X4 p3 B
- if(x1 == x2 && y1 == y2 && z1 == z2){1 ? g0 f, [3 C! d. v8 k
- return;" [0 Q4 j: G# D. n$ O1 g
- }( o- T( K2 `1 M" k$ I
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) d4 u. g& [( A# U- n' Z$ v' F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. j) C* U/ Z5 n. q
- }
+ }! D6 Q7 R% n - pose.pushPose();
5 i* h# Z9 e* H/ ^! q @/ h - final int newLight = convertLight(6);
5 u* S& z3 \6 v5 `! X$ H) @ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 a0 p) O5 Y7 b2 l, _) {" l5 h
- final float lineHeightSmall = (y2 - y1);. M, w+ N' C' f8 Q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);. q8 \6 T- ] S; v
- pose.popPose();
6 O+ L; o6 X% T( R- y+ x7 F - }
3 M1 @+ m- B- @" [/ M {8 H - * e y6 L9 z! n5 v& a* ^9 a
- private RenderType getLayers(String texture, int light) {
5 N2 r9 Q7 D: T# `1 r - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" l) r A, t* `& o5 R1 M - }
& l6 S$ z! T7 f - 2 l* v$ C) H. ]* K* e
- private RenderType getLightTexture(ResourceLocation texture) {: l8 S* n; T* V% W0 x" {
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& V- K7 P" h o3 a8 W7 U
- }5 X4 \' q" K! V0 P' Z% k/ \, E, T
5 y* y7 `/ ?+ ?. ^1 t- private RenderType getTexture(ResourceLocation texture) {' }9 ~ i1 e# t
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 e) R# N+ X$ z: o - }
1 g) L& k/ i; @. ~
/ t8 _! Q0 U' S' m$ u2 B% @- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: |5 I' e9 [' I0 E" f - if (cache.containsKey(identifier)) {8 I- X8 P( _( w+ E8 m
- return cache.get(identifier);
0 R5 A) x( t5 H/ J, v. D. f - } else {
# S+ X: y: _/ U7 P! y- U [ - final RenderType renderLayer = supplier.get();/ N0 T% Y6 {7 E: [. {
- cache.put(identifier, renderLayer);
. z$ w; Y- Z' _9 g% D' f - return renderLayer;
/ P4 ^7 P' p; O& A6 k; _" u - }
' t6 w" a; d3 r$ o' H - }
' e g$ t/ B, } - }
复制代码 |
|