|
|
* v0 W5 ^ c3 T2 [9 s3 V行,这个怎么样
4 R" G( _$ {3 c- a8 D4 y: G- package com.xhg78999.mtrfac.render;) t2 P- W+ V Y; B0 O ^
- ) g/ V* g8 m+ W1 _
- import com.mojang.blaze3d.vertex.PoseStack;
$ ^8 N! J0 B) g, e/ t: p - import com.mojang.blaze3d.vertex.VertexConsumer;& v' a1 T+ }8 E
- import net.minecraft.client.renderer.RenderType;& o+ u1 w" q( r, t( E3 j. p( W
- import net.minecraft.resources.ResourceLocation;
6 o* Q$ R' `) V8 n7 D
9 j4 X+ k" D8 O0 D6 f& h- import java.util.*;
3 m0 x% y2 ]9 L& d! d: [% S
! [8 p8 c- g v O4 b1 M, D- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
- C+ u" N. V7 V& U+ I& A - . B* ?6 ~6 }& X" t0 r( |
- public class LineRender{+ n+ m3 k& [0 u$ U+ N
- private final PoseStack pose;
6 k2 X) C4 |2 a" ^) J9 k% B - private final MultiBufferSource source;
; Q& E( C- U8 F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! x* n0 @" I7 x3 C1 s) q" f - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! _$ y, V5 ~) d8 U7 a! J9 l
, z% y9 s/ L& P R+ Q, G8 J/ n- ( _+ ~- S0 Z! ]/ K1 {- s8 G) H
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 O; w' |4 q8 v4 R& G( c
- if(x1 == x2 && y1 == y2 && z1 == z2){
* {9 k8 j% f- A1 } - return;
9 f: p3 o+ s8 J7 f' s - }% x9 g, d ]" a
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ }# Z, b% ?( B5 J% d: i - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 D/ d( R5 U+ C; w# L" ~ - }
- c* F5 D( J. Z; Z1 Q1 Z - pose.pushPose();
1 D5 o _! ~# c! L9 h3 Q - final int newLight = convertLight(6);3 i; ^: ?4 V& f; l' ^& o) f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 z: \ [$ w' @& Q4 K. Q - final float lineHeightSmall = (y2 - y1);
& I7 l& G- F* n" O# K - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' I: x. F6 ^. Z, Q - pose.popPose();* f4 L+ r+ s+ N1 X
- }$ O' M5 J5 b5 _- e- G
- ; q _, D2 u8 p. ?; ? \0 Y
- private RenderType getLayers(String texture, int light) {
/ M, G3 f ^( H8 t- k* S1 Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' Q6 x% m$ I: G2 v( o, E - }
) Z0 N- {9 {# O% G, @ - : t/ E) y, M# C& n4 ~+ d7 {" I+ M/ G
- private RenderType getLightTexture(ResourceLocation texture) {9 Y+ ]: Y+ {, i8 y# Q ]0 | B; h
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 `4 u" [, j& m! y; d+ e2 Q+ K! [
- }
$ D5 E; C; J8 G G* Q$ G
6 K8 z- X" o2 W- ]% }6 V- private RenderType getTexture(ResourceLocation texture) {
1 Y7 t8 @+ C4 c; ?6 J7 ]! { - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: c/ b0 ^5 R' g4 O5 {) L - }
: y; ?. U0 _/ k% m - # L5 [3 V9 }- @
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: {9 b+ o2 y$ m - if (cache.containsKey(identifier)) {4 x G; U2 p9 M0 \, L
- return cache.get(identifier);/ H+ x8 |0 b/ c+ a- H4 i+ ]
- } else {
' `# b2 i/ M/ _+ n) Y$ F9 [ - final RenderType renderLayer = supplier.get();
/ ?+ F0 G% y: w/ S - cache.put(identifier, renderLayer);6 a% V" s8 i4 C+ g& r: _# U
- return renderLayer;
+ \8 f; C: X8 e D+ N# x - }
: a) M: k5 ^6 x2 B - }; r2 r# P2 ^$ P+ { j: y
- }
复制代码 |
|