|
|
* N& R# e0 w/ ~+ L0 _( z, o
行,这个怎么样7 T: x6 d9 ~* v, S C8 s* S
- package com.xhg78999.mtrfac.render;
! W1 y* `' ~! t( U Q5 n% Y
9 A" V9 Z' y2 J* ~0 Y- import com.mojang.blaze3d.vertex.PoseStack;, ^) a4 z% ~0 }; a
- import com.mojang.blaze3d.vertex.VertexConsumer;; S5 G7 n" h2 e8 J3 T5 T
- import net.minecraft.client.renderer.RenderType;& v0 O4 b# ~, q" G
- import net.minecraft.resources.ResourceLocation;4 K0 g [( b! l5 ^/ E
- 6 _4 u9 H/ e( q0 J. P
- import java.util.*;
, P* d1 s+ ?" g
* x2 T% B2 f @- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(" u$ l4 m( e H. e9 }
3 q. o' w4 G5 x! G/ F. V- public class LineRender{; s# N5 q* F% ^/ t7 K
- private final PoseStack pose;
0 ]0 C8 R: \% k& V - private final MultiBufferSource source;
8 j' {% A3 x3 _) g* ^/ I# a! a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();' |" J5 t: w+ U( G6 S$ V: m
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: T0 f y8 z% L3 ~: g
4 w b7 y: r0 ^# G1 F- - S; n3 w& V, {# U. v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' P1 x4 _ R0 L9 c- T - if(x1 == x2 && y1 == y2 && z1 == z2){8 d' }0 j) {0 O( g3 G
- return;
" b% W$ S5 C0 F - }
7 k2 S* K# b+ C2 _% w' M( ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& N3 Q2 j- q3 C* `4 L) K, J9 s9 F - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. L3 G/ f8 q( ^# Z) Z - }1 |% f9 d+ K& \3 L) o1 Y
- pose.pushPose();
6 V. {/ Y; R/ U - final int newLight = convertLight(6);
3 I# [0 f D; f& y6 p% J8 K/ b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); r" h. C" F' G) q
- final float lineHeightSmall = (y2 - y1);: R" U- t7 n8 v' e/ \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
6 n- V. p9 c1 p" W# C3 E - pose.popPose();
. j2 I# A! ^3 { - }# n" e y. n! R* S( _, F' H5 O
; O% S% m, E% c+ \6 ^/ c& \6 z4 |5 g( j- private RenderType getLayers(String texture, int light) {8 O2 o9 w7 D3 ]+ x( e( e: s
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, N; X2 Z# V9 p: H/ u
- }
- P4 i N2 W( W" R# S
" D1 d- l/ `) f6 g$ _- private RenderType getLightTexture(ResourceLocation texture) {
, P4 j6 f: H4 V" K, m5 g8 Z# f2 f - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 Q s6 r( t% y- C" ^) m
- }8 ^$ u7 V Q* p
' Y- C8 B: x. I5 _- private RenderType getTexture(ResourceLocation texture) {
2 |0 T7 p. u5 d. _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ R. f! t+ h7 C1 J; a) Y - }
' G/ ^) R+ i5 _0 L - 4 V: {1 B) E/ |
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ v( ?& O- G- D# z9 }
- if (cache.containsKey(identifier)) {; p' X0 _9 J8 N `( p. i6 o
- return cache.get(identifier);
! I, ~& S- E } - } else {5 I6 D, J: \/ T, f
- final RenderType renderLayer = supplier.get();
) B* q; w% r/ l" o+ V& ` - cache.put(identifier, renderLayer);0 @* s0 s# r) e" o$ I: V" ]
- return renderLayer;
+ C; o) d2 K) s5 @9 C5 T - }* z1 n: h9 R# Z4 l$ X
- }
: Z& E' p! \5 S% S4 L) n* b - }
复制代码 |
|