|
|
. K! \: {' \# v8 Y
行,这个怎么样
6 B0 }0 U3 ?! x& A- package com.xhg78999.mtrfac.render;
- p# j4 ~( n5 r* e - 3 a8 i# N% {/ v. @# V2 T
- import com.mojang.blaze3d.vertex.PoseStack;
5 z, d* }9 S) \& W# c) P8 F - import com.mojang.blaze3d.vertex.VertexConsumer;+ P: y6 b$ g* }7 O, n- m/ D6 J
- import net.minecraft.client.renderer.RenderType;
# ?9 y- F' s; h/ ?! @, `5 a* s - import net.minecraft.resources.ResourceLocation;+ e0 D/ I& O" w0 R9 N
- 8 o% p2 }% c4 j: X/ i. d
- import java.util.*;
5 | k U0 I2 C5 _5 v7 `
/ [4 X v! c& m: q4 T- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ v, F6 w+ M8 K. n7 E4 m - 4 H5 m+ i0 t, p/ d+ j" i# S
- public class LineRender{
4 p7 ?" b, G% w: b - private final PoseStack pose;, Q' ~ g8 \% E
- private final MultiBufferSource source;3 P6 @- q' u5 @6 w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 v' a+ O5 X9 J) Z; N1 T; M
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ Y6 Q# R7 ?# R8 F8 t6 p( o
! L: a4 i# s. P5 O( M( n& Z
0 v# l5 z% R. L, J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 x, Z2 P C& n* M' ]5 @: m
- if(x1 == x2 && y1 == y2 && z1 == z2){+ t2 @# g* `. {% n
- return;
/ X. s$ G. ]3 [. @% j8 Q5 a2 Y - }
3 S! ^8 w7 b5 X9 @+ G) _6 j7 ] - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% E/ S, W2 S, w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% M K7 Z% j" b, J, \% p+ q - }( i5 v" H- E) p- b8 V5 U' j: C
- pose.pushPose();; I) H4 [/ ]4 W* z+ x) O
- final int newLight = convertLight(6);
" p; X9 K6 Z+ o/ X. N* m; F7 @8 I - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 X' x0 A+ I5 _
- final float lineHeightSmall = (y2 - y1);2 f4 V1 g) L4 V5 _
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- ?. h1 \( ]5 ]% u
- pose.popPose();
* } W$ ]" j ^1 Z - }
8 g0 J) X2 _' ]0 i- x9 y3 ^
% ]4 O, X- e0 C+ \; w8 d- private RenderType getLayers(String texture, int light) {
" |7 U" h C$ H( J# X4 @% ~ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; v' |' Z! n. b% c
- }. ~7 C4 ^9 f; l0 e5 X4 ^7 Q
( {% G& }& a& R" j2 K- private RenderType getLightTexture(ResourceLocation texture) {4 b/ C; S2 I; u0 v" Z0 y/ O5 F
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 }* ?% P, W8 ~ - }
* R5 Y6 _! ?( b: x' [, _ - ' l9 E" @& X) A* a" j' l; J% s
- private RenderType getTexture(ResourceLocation texture) {
8 D+ j0 V& T- ^0 H* w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 z9 F+ ]0 z7 w& [
- }. o2 n; r5 H. Q* e
& d* {& h% t* p( j* K, @' k% y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- T1 t2 i2 C) w- L6 _' {
- if (cache.containsKey(identifier)) {
Y1 J- A$ f; b' A3 P5 L% _! L - return cache.get(identifier);
/ Q. o; Z A! h$ j - } else {8 K, Y& n' P6 m$ X8 Y7 M
- final RenderType renderLayer = supplier.get();
5 C7 V E5 Z5 B4 _$ o# Z - cache.put(identifier, renderLayer);
1 p3 R: N, v7 i - return renderLayer;
" V0 q H, f: O# v9 m - }
! A) F8 X2 r: h, T - }6 W" R+ B% J( x3 V2 _+ g
- }
复制代码 |
|