|
|
8 |2 A8 ^% U3 Z! R# w
行,这个怎么样& X+ p0 ^! s, i4 R
- package com.xhg78999.mtrfac.render;
( o# ] _" O8 B9 Y2 _4 k4 O' G
) l& {% V, L9 e7 n% e2 P- import com.mojang.blaze3d.vertex.PoseStack;; j+ K9 B5 M' O7 B! S! ?' j
- import com.mojang.blaze3d.vertex.VertexConsumer;4 Y8 t( r$ B$ C' a( E( i7 s
- import net.minecraft.client.renderer.RenderType;
$ m/ S: Z T6 s$ ?! ?0 w - import net.minecraft.resources.ResourceLocation;
Z; c8 Z. R: S - * b9 m3 y3 r$ n" d, b8 n5 |0 e- c
- import java.util.*;* F+ {# N5 K. w# a
: @: x8 `) Z. }- Q. i; J& y: C- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* H6 V; |5 I$ J6 a3 u7 |
' H2 W/ I9 h7 O7 }& z- public class LineRender{
) C& |# U+ ^* Z4 N0 U - private final PoseStack pose;
' d( \ Y- \* h; \ - private final MultiBufferSource source;& C3 Y+ i3 K2 d( X& s8 c: H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 n' c l- i. K1 ~; U6 h' ] - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( x% p; E/ R. [
- ( a' U4 M0 F3 i; ~5 d% Z8 H4 {" `
# ~4 U, E6 d6 ]: a3 R- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: A% W8 b- C5 g* {9 V, N - if(x1 == x2 && y1 == y2 && z1 == z2){. @( b% x. z) ?% X. u! N" G
- return;8 p" d) ?0 Y9 V* u9 B9 Y. n( c- \
- }
1 a5 K- P3 K4 s* P2 K - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( [0 z. F6 d9 h7 K: P; K
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 X1 @2 \, ^& L& ^ \$ Q7 @, ?
- }4 _1 Q3 t2 h C! U/ W" x! X
- pose.pushPose();
4 a% n5 H6 l" `; U - final int newLight = convertLight(6);
( M0 V! f& o& P. G4 Z2 R8 J( d - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 i. k6 m. A! Z$ s* [' }9 S! i - final float lineHeightSmall = (y2 - y1);# o# _( A% v* l$ `3 F
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 m% `- T6 ^# q/ i/ n7 l( S. _; s
- pose.popPose();/ R9 k. x/ ]& u: {. y
- }
+ q% Y6 \& z( `# P+ M8 X H
7 g) ]8 y+ P i6 `1 n# S/ m- private RenderType getLayers(String texture, int light) {" H' @+ n& x, Q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) I# O" s6 H1 {% k% |9 v
- }
2 f5 M" Z# ]7 y; o+ \9 Q/ w0 E - ! [2 r! L/ C) z8 ~: {* ~
- private RenderType getLightTexture(ResourceLocation texture) {
/ @* f' k+ O. P. @& J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 a% B- X1 n1 r9 j. P& n
- }
1 I+ c8 E# h. s. E E+ W
! q6 C+ x1 l5 n m. f) g, V. L6 Y( T8 F- private RenderType getTexture(ResourceLocation texture) {
; P0 [0 s$ `. v3 |& L - return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 N1 x" R. l9 q5 A4 _
- }- K; J! h$ s& y; B) `9 c
% N$ x- c) t) U- `- ?0 G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 R! I4 @) Y3 ]8 J" V - if (cache.containsKey(identifier)) {
( `# a3 B4 R1 Z( s7 A - return cache.get(identifier);
& q! O; n* Y, ?( ` N3 y - } else {! t" |, t, g, v$ X
- final RenderType renderLayer = supplier.get();
7 O" F" s. u, V) X W& _ - cache.put(identifier, renderLayer);
# r5 A6 _$ d+ V3 M7 }$ U - return renderLayer;
% K0 a0 r# n: M: U O4 q - }
6 _8 e4 Y6 e* R! o. ~# [- ? - }
) U7 w0 F8 Q3 S2 U% z" d) g3 c: n - }
复制代码 |
|