|
|
8 h1 A! s0 [$ \' @$ S; R; E
行,这个怎么样7 L8 k9 S+ X& Y, x$ `
- package com.xhg78999.mtrfac.render;+ }% q6 A% Q. @0 Q8 t- W4 ?
2 b/ ~! U+ y) i8 h! @2 C- import com.mojang.blaze3d.vertex.PoseStack;
: P+ V5 F/ T$ ^, p( S* ? - import com.mojang.blaze3d.vertex.VertexConsumer;
- H2 N1 [" z8 c% Y2 E: E! Q% T - import net.minecraft.client.renderer.RenderType;, _/ O; q8 h+ J6 n8 {, A; p
- import net.minecraft.resources.ResourceLocation;$ p1 Q9 w8 A0 `, v5 [
9 n7 k- i: v( A- import java.util.*; _; v/ k3 K0 Q i2 T9 X
- + j( B4 V. v" _9 J9 s, X
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" D* K- j& ]9 `; g6 Y& D8 n
$ h, M6 ]8 E) _- public class LineRender{; ]- m, S. D, S) R1 c. V+ V
- private final PoseStack pose;
. c3 z$ r* ?6 T7 H { - private final MultiBufferSource source;
5 D7 ^% e1 }' R7 o' S' s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
( u, S T+ n" L* H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 D1 i$ ?0 h5 c2 w - # m. \. p! f: Q& l w; X9 A
" v- X4 G5 t* [$ Z% @. R% {/ j- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 ^) ]3 P5 g& M% D7 r4 L; [
- if(x1 == x2 && y1 == y2 && z1 == z2){; U8 n( p: ?. b* F' [
- return;
% r! ?. \) [ o% N: s- x5 Z - }% K' i7 t. R* J# f; ~+ {5 x
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' i8 Y( d3 b4 B* n/ ~! n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");# U" j- V% x5 r2 L8 c1 s; o1 ?
- }2 R, z) J. m2 c: z8 g
- pose.pushPose(); L4 w3 i ?% a ~( L) c( W
- final int newLight = convertLight(6);0 t. Q# l6 p2 w$ B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 {6 W/ C! f3 O6 c; f
- final float lineHeightSmall = (y2 - y1);% `6 W' J! X- n/ P) d9 y- c
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 a1 j/ ~" b+ E( E - pose.popPose();' |# z- v4 G }3 A+ a8 P2 g, j5 q
- }, a1 g) ]( @/ m3 Q C/ S. C
# Y/ e" @3 Q$ r0 c8 ?- private RenderType getLayers(String texture, int light) {
$ s6 b& z, \+ m) }. |8 o& c" X9 r - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
]5 n1 S |* t - }2 @4 W9 I/ V, C$ L5 s2 F. N6 B
- , G6 ^: Z" V7 i) p# c5 B
- private RenderType getLightTexture(ResourceLocation texture) {- }9 U9 b }$ t% Z/ Q. |
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 f7 p1 P; \& |, Y8 x - }. f: C$ M, O6 O, f) H* {+ E
# S. b# P) {/ V. o+ J+ a8 O- private RenderType getTexture(ResourceLocation texture) {
) \# c% r+ ?" G3 c" m d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 X" p& G, q' |) P3 F$ O4 w" ` - }% P1 L. X* D @9 |+ v2 g
9 ^, Q) U3 t1 x3 E7 C; I# W- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ F/ E" b0 p4 ^. k - if (cache.containsKey(identifier)) {
- l1 `5 T- I# g+ n - return cache.get(identifier);; s& ]8 f) W# _' ]8 s: _: C4 D
- } else {
3 X7 `: ?/ P+ t - final RenderType renderLayer = supplier.get();
% L6 H& v- k+ W# w - cache.put(identifier, renderLayer);5 {1 Q* K J7 _
- return renderLayer;
! {4 h4 {3 }5 c, [$ f. p! l5 D7 F - }
5 U m* t# P* k W o, Y1 T' ? - }# `; I! I/ g, e e& s+ d- ^7 j
- }
复制代码 |
|