|
|
% y& a3 {- E4 g9 ?& I
行,这个怎么样- j6 @9 _" n) v9 x: i! ]2 P
- package com.xhg78999.mtrfac.render;
4 J# c0 v8 b- x+ B" x3 \ - 0 t4 x0 r' r% Q, K# {# [, J" y
- import com.mojang.blaze3d.vertex.PoseStack;* X$ Z5 R! V0 o* y4 l% C4 y
- import com.mojang.blaze3d.vertex.VertexConsumer;/ `- A- }- g- n6 W: g
- import net.minecraft.client.renderer.RenderType;
$ u7 |6 o4 @2 Z$ Q5 \ - import net.minecraft.resources.ResourceLocation;& Z1 n2 f& h, G) U6 c# B0 U
; V) z; d5 n5 y* S- import java.util.*;. | o% U! ] O6 x1 m) i
8 q; o( O1 A6 X" ~( |- {8 a- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( f! |; F+ c. k5 r1 G
3 _% v) N) K& \4 t7 W- public class LineRender{8 V0 k* s! l2 g) Q7 ?$ r" e2 J0 l0 a
- private final PoseStack pose;: R# G- n: `4 b* {$ J' X
- private final MultiBufferSource source;7 K$ b5 v P6 u b* W" P% m
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 V5 x! O+ m5 m* E - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();0 _6 A. l x7 _! P) L% Y
; x, z2 r$ a( S3 u) Q, m2 z
# z ?4 {9 y! ~- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 ]0 I) e9 a4 P
- if(x1 == x2 && y1 == y2 && z1 == z2){
2 G) {, D h T9 n! u - return;, Y9 w0 J* f! B: I9 o9 M+ v% d
- }1 J! |8 W+ }9 ^5 q) y8 |6 ^) ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 C F2 c/ ~3 t, K' o0 ~ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ R, t) G- J2 _- Y9 Z! v) }4 g! ~( U
- }
9 Z6 d9 s2 @6 [+ x% F - pose.pushPose();! s% p4 v+ ~* K" J. U) q
- final int newLight = convertLight(6);
/ W! g) a- x, `; a: \2 h( Z% \- \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));! {) ~0 ?5 X( k. Y; R4 ]" y" z+ e
- final float lineHeightSmall = (y2 - y1);
. V9 A) J% J) e - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 u! s3 u# o2 |* Y8 g
- pose.popPose();% M3 B8 o& h3 P" k
- }
c* T* T- G0 e, K - & E. N4 ^, a. ]+ Z
- private RenderType getLayers(String texture, int light) {
/ K; _; I, A, ?8 h - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 k K0 x8 r* Y0 e" V+ P' c
- }7 c3 Q! o! x, ~
1 l" R. e6 {9 p# Q2 Q6 c$ n- private RenderType getLightTexture(ResourceLocation texture) {7 S$ L. y9 w9 V9 k
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 w9 [, o7 @ l# w" Y* z" T
- }( d4 X% S; C U4 Q$ K
- : u* s ~- S! h: V6 V
- private RenderType getTexture(ResourceLocation texture) {+ J' {& O0 K0 p( g3 y7 Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! i2 {* ~0 ~5 M- i) J" S( r: }
- }
4 Z6 s+ F3 b! o3 c" s* s6 B
6 G. ~ N) `' C5 W5 L7 p) Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) q5 X) o# p4 {* j* ]/ z6 H - if (cache.containsKey(identifier)) {
3 V) W+ d& k/ T - return cache.get(identifier);3 r" Z2 n. p) j2 H( l1 E& X$ w
- } else {
1 e6 D% L+ }" p& U$ A+ V1 d - final RenderType renderLayer = supplier.get();: R/ N; c( w9 D. o
- cache.put(identifier, renderLayer);
, M o5 S4 z/ O" s: u) O - return renderLayer;
- g0 E# N' j. z, U! v! B+ Y- I( _' ~ - }: z4 s2 D G% x0 W" X! V
- }
. g. V# |& ^; s8 T - }
复制代码 |
|