|
|
! [0 R8 K" Q8 v: ~行,这个怎么样
Y; Y8 E* x7 O, B" Q- package com.xhg78999.mtrfac.render; n& C1 K1 g' E8 M- _# \2 E5 e
- . D9 b0 Y# S* ]( \0 y* T! W
- import com.mojang.blaze3d.vertex.PoseStack;% _1 e) B0 M1 z D, C6 i
- import com.mojang.blaze3d.vertex.VertexConsumer;
6 s7 p8 `4 ^3 t6 a- C: Z - import net.minecraft.client.renderer.RenderType;8 X7 M- H6 E6 l2 k' x2 M
- import net.minecraft.resources.ResourceLocation;
2 {. d; G8 D* W3 _+ E7 [9 r - & {% s, q! a: X7 `/ D+ J6 q
- import java.util.*;! M$ R# T% S* I
2 Z: u7 W- B' v) B( s: M' Z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 w& a* K) l9 \% b; d6 B
7 ^9 B, D, j! z" P" e& X6 H- public class LineRender{ `; [8 a# C$ _9 F$ i3 ^6 X
- private final PoseStack pose;" }' h1 p9 C! [ m
- private final MultiBufferSource source;8 {5 Q2 U1 d* U/ ]( w; A3 T" c3 d' [+ D
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 E" e, t6 l" ` - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ w; @: K6 k- ^# `+ l5 Z9 n! A$ ~ - 0 [2 W; g$ L( B# C0 j
! l8 d, l- ^$ {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, u+ f0 ~% |2 g7 G) j0 a - if(x1 == x2 && y1 == y2 && z1 == z2){* S3 s, U( b0 I5 v
- return; p" I7 | I0 Z! c6 z
- }3 b* L( b4 O' p& ` E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 i1 o+ o* {0 ?/ a - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# I* l3 {8 g- c/ X2 {; L+ x y - }
# W5 `! o2 Z4 z - pose.pushPose();
& Z2 F, Y8 M9 q) @1 m - final int newLight = convertLight(6);
8 |. H2 n0 K3 x( `5 @ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. I4 H I+ n4 {/ Y- s# ^
- final float lineHeightSmall = (y2 - y1);
8 l- t- c4 u7 U7 |5 O9 |. K* u - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% F) a; W$ ]% }1 p
- pose.popPose();+ [8 K# [2 F) i$ z) w# p0 v
- }
. A$ a+ |: w, S
$ d& o4 ]# q9 u# M! _6 r- private RenderType getLayers(String texture, int light) { l1 k E7 G" d. u8 k
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. d$ l- @9 m4 b) I5 D - }+ ~6 i4 K8 O3 _" i
- . {+ Q& J/ C. o' W- W
- private RenderType getLightTexture(ResourceLocation texture) {
9 z# t' Y0 ^& V: g$ r- P - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 C/ p$ d2 F9 H, l. R
- }" \7 f4 [: O1 u
7 O" _8 e" q* c- K( j8 k# y- private RenderType getTexture(ResourceLocation texture) { k: X) z3 l/ T0 k3 ^$ q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);/ y0 y# c: z; F
- }. Q! G8 }' } n
7 z) ^# i8 @- v- X3 u9 w* _- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ U$ r% A8 Q4 y! n- I9 l4 g
- if (cache.containsKey(identifier)) {+ N0 i! T' q8 I
- return cache.get(identifier);
. i: T6 j+ j) D8 N! j! e - } else {+ Z2 x6 J% n3 d$ O' f
- final RenderType renderLayer = supplier.get();( \( }! `' B- I( @- ]' w, [
- cache.put(identifier, renderLayer);: o# b8 R; P' s9 t. N" x
- return renderLayer;& Y8 Z5 q7 h$ I/ o' x9 \- y
- }% Q2 O$ H5 I F' H9 ?5 [( s- ]
- }
* P1 f/ _8 M/ R; ] - }
复制代码 |
|