|
|
/ W8 U2 a; Y# B7 e" g. ? W6 c K
行,这个怎么样
* x/ e: X" u, { V7 p7 P! B- package com.xhg78999.mtrfac.render;
5 Y0 K6 E% B d+ h# z, x+ s
9 g- \3 }6 g- d: u& V1 c k0 r! n% k- import com.mojang.blaze3d.vertex.PoseStack;! @3 \: p% Q' p4 N. Y
- import com.mojang.blaze3d.vertex.VertexConsumer;
) H6 ^6 p) ?, ]9 D8 _ - import net.minecraft.client.renderer.RenderType; C7 H7 W1 P# W& r
- import net.minecraft.resources.ResourceLocation;" r# e( v/ ^+ H
- 6 o! u. r# S' F! `8 P" c
- import java.util.*;
5 g! U( H, j4 ~7 Y) }8 F$ o
- k! U2 L2 ~2 y* q; o8 H- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* c( @- W: F5 `* c# {
. }' ]: v3 S8 D- public class LineRender{
3 W7 B! _: r$ h8 O6 Q' B - private final PoseStack pose;1 ~/ [. ?( `6 p/ L* L* N9 F
- private final MultiBufferSource source;
( N3 i# [2 n1 C0 E - private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 C* b$ D: ?. Z( r' p( I( {
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( \7 p3 h5 c0 x2 `. B5 b$ x7 s8 {
3 c- ]/ A5 L4 w; t7 P) ^; _" S
0 ^7 ^# e+ T( A, [- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){) G( p1 @* I ?4 `( ]4 V
- if(x1 == x2 && y1 == y2 && z1 == z2){/ G' a7 l; F! ~ { y. S
- return;
0 o$ R; g( ~- i% C! f - }
7 Q3 r4 E+ Q. ~9 l' \% [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
P/ `9 q; R9 @; U! G5 V5 j - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 @% r( g% F* M. G+ [# e6 Y( I
- }
' ]9 l, } v/ Q3 M - pose.pushPose();. N$ i- Q! Q4 q. e+ j% c& }' t
- final int newLight = convertLight(6);
* g/ |" e9 `' ]9 Q* E5 [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* L, D$ \& G* w8 L - final float lineHeightSmall = (y2 - y1);
; m9 k& y. H* o. C! G# |& {5 D \ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ c# `* o6 A [7 i5 I - pose.popPose();& _" h0 O2 ]! C% x! m
- }
# w$ [: a) D$ W$ s' O2 q' u3 k - ' B; v6 ^+ d8 O1 H9 O
- private RenderType getLayers(String texture, int light) {/ `1 J; x& {3 _6 d% |1 i
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- I- [9 l/ K$ E' Y5 j4 Y2 S% U% u - }
/ B7 P% E/ Z" q0 i! }. {) y: S/ h6 z
4 s2 S" ~; g! ^, P# T4 A6 m% M- private RenderType getLightTexture(ResourceLocation texture) {
9 J0 ]' D: P! n% u) A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( h6 p, `! z% j) r* I - }+ Z s! Y( L( n7 b) H
; v+ r" A; b1 {: X- private RenderType getTexture(ResourceLocation texture) {
9 }) j# [9 a: A - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. W- s& C4 |. X: \ - }. _! B" S) q: C- b
- 4 B3 w( @% W, `% V# o7 w- u$ \
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( q4 g( C; ^/ W1 ^" R% o8 O% t o& _1 d
- if (cache.containsKey(identifier)) {
5 o/ j8 G0 Y B5 s; E - return cache.get(identifier);
@4 o, }0 M* K - } else {: {4 p' w% O' @ W
- final RenderType renderLayer = supplier.get();/ n3 B( T$ p0 P; W( l; @0 _
- cache.put(identifier, renderLayer);
# G! P; \1 K. y/ D1 E; Q - return renderLayer;
3 M+ d. Y# { m8 e - }
. b x& e$ \& I, _7 R& d - }
8 a, Z5 J9 m" O) G: ?5 z - }
复制代码 |
|