|
|
! L0 j' Y' U" u! a
行,这个怎么样' F% A! K2 u. X5 } t/ g! \ e
- package com.xhg78999.mtrfac.render;
8 R) z9 f, G, d I3 z& L# i- g) ] - 9 z& e7 K/ v$ a0 u2 B) n
- import com.mojang.blaze3d.vertex.PoseStack;1 O0 j) i! I9 l# S
- import com.mojang.blaze3d.vertex.VertexConsumer;
/ n4 a' | r' v - import net.minecraft.client.renderer.RenderType;
5 r* u: u7 a1 b0 X. G - import net.minecraft.resources.ResourceLocation;7 z4 O# w/ y H
* w! F. S% G# G, p6 |- import java.util.*;
. Z, G, H0 I+ b
1 T0 ?; \2 v* y& t- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( q: M" {% s3 X! E# L
# v0 {! ?( K2 K1 N2 y7 h" U- public class LineRender{
) v0 C2 z9 U9 ~! V - private final PoseStack pose;- p" N) U( L4 o5 b$ C0 f( ^6 n
- private final MultiBufferSource source;
4 g. o6 \9 K& P - private static final Map<String, RenderType> CACHE_A = new HashMap<>();) M: ^: R3 g( }- \2 z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. _" V/ j& }- y- W/ d0 o) z2 z - 0 ]! P2 c1 I" F7 B; J [ q3 M
- ) V; v% f, E. Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* h6 ^4 J2 ]# Y/ ?. a2 ^7 i
- if(x1 == x2 && y1 == y2 && z1 == z2){
; v1 K& Z9 P2 B# B/ v# a3 k) i - return;1 O( q6 f" M3 J
- }$ G# q( A& G7 P, F8 z8 S/ S% ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! T+ }6 l* ]7 Y% I. |! y$ w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 i# j; J" | s - }. ~% }( N4 ]# h/ O9 e
- pose.pushPose();8 m+ z/ g" e! a' x/ y9 @
- final int newLight = convertLight(6);
6 c# c! a7 v w% g4 K( b1 m - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 v2 N& f! t! P3 M. @/ ? - final float lineHeightSmall = (y2 - y1);
& d: f; Q* f5 N7 z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; ~+ J8 q3 J* c - pose.popPose();
+ c! g8 @" H; q" I/ H: b - }
6 s4 D0 d( X* ^: f
+ e8 B3 U9 u: T- private RenderType getLayers(String texture, int light) {
/ d! w& p8 F) b0 Q# Q/ A - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" D+ ?# f7 s& ^ - }. Z/ h+ Z2 V$ H9 d/ s8 G
- . h9 N" d) |5 y7 F
- private RenderType getLightTexture(ResourceLocation texture) {! Q$ G+ D# `* p$ a
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* V3 J, E5 U4 F( Y: H
- }
: S4 o* D2 Q) ~" ]+ A0 r - 2 f: S8 v8 u2 Z) g: S+ Y1 e
- private RenderType getTexture(ResourceLocation texture) {% N N* ?5 l' C9 k- I4 |, @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! n3 l$ ]! f2 e2 a& V! e% V
- }: v1 H, i' N. J/ c( l1 E
- ) [0 U; P4 q3 V& W6 ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 ~8 O" w& p' N$ [: Q# c - if (cache.containsKey(identifier)) {& L; c, Y# N3 S
- return cache.get(identifier);
4 i: u# C( c6 I( j" `( d - } else {& |+ y ^9 s+ B0 G, r, e
- final RenderType renderLayer = supplier.get();
3 U9 n! |' S# B5 b: `: V - cache.put(identifier, renderLayer);
' m5 {4 U+ i8 z, C* H/ c7 J; R# o - return renderLayer;; g! d5 g- S" {
- }8 E( D; j8 X& D4 b F5 v4 _: ~
- }, B% [) u1 ~- k6 V. H/ D
- }
复制代码 |
|