|
|
# u N! a3 B! k行,这个怎么样
: ^! [& m( \' q. l; M- package com.xhg78999.mtrfac.render;! ~6 M- Q/ _. v5 B" h% T) C' N8 I
- " Y: t t. _" q c! l
- import com.mojang.blaze3d.vertex.PoseStack;
1 ~- | x2 q- D6 n - import com.mojang.blaze3d.vertex.VertexConsumer;
" Y: E( ], A! x# W. V - import net.minecraft.client.renderer.RenderType;4 ^1 l, \) B; i# C3 M7 a
- import net.minecraft.resources.ResourceLocation;0 q; B& @6 l! ? B; _0 B P" \
- + N: l k2 r3 _) x' i, U
- import java.util.*;2 L# h& C9 o' D' W; @
( m+ j0 i( h9 A o O3 z6 f- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) e( r w" l) Q4 P# _
* D" d* H3 X. p- public class LineRender{
% g+ a! ~+ ^% G8 x, V/ l - private final PoseStack pose;% A8 E: n/ ]# v9 h' D
- private final MultiBufferSource source;
0 o6 | Q. y; W - private static final Map<String, RenderType> CACHE_A = new HashMap<>();; I3 E+ h* A: c, S" w% m) U
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
7 z% Y$ m% F, d8 Z9 | s6 \6 {- @ - 6 s' w3 {0 D+ Q+ d" N
- + j) {% z1 _' @
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' W. s: b) o3 g2 I1 N
- if(x1 == x2 && y1 == y2 && z1 == z2){
H- w5 ]5 f: b+ T8 }7 d! h - return;
8 ?+ ]: ]) J1 w3 G- h" O9 R% C/ ^% W - }
w+ K& E) A8 q H9 F5 C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 K/ b3 X" Q p% l' O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. z, |+ ~/ N1 D3 Q2 i1 V3 f5 r - }
1 G6 g# ^( z8 x5 W - pose.pushPose();
4 h! C, m, e3 j4 G# G2 Z - final int newLight = convertLight(6);
- j5 c. b, Y8 j, a - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" y. Q; \3 s% X7 x - final float lineHeightSmall = (y2 - y1);
# X; y& t$ i% p& q7 R# @ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& x$ V1 X: m4 n! O3 Y$ z) D - pose.popPose();# S; F3 y6 J' j6 W
- }
/ | g& W) z2 s( @ - : M" e; A3 V/ ^2 p2 Z
- private RenderType getLayers(String texture, int light) {
" ^. p; E/ g7 E& S7 y% R - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% J, }0 q4 X2 k9 ^6 H9 P# T8 c9 J - }
! U4 @% P7 V& \ - 4 t% V- |5 \ J* N N
- private RenderType getLightTexture(ResourceLocation texture) {
! g7 p# Q0 |9 I, o1 V! O/ B* S1 w; j - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);# R, G9 o( [% x4 x0 [# W* X4 X& X
- }
0 a1 ]4 p1 L' ^ - & B7 G% S+ N/ p0 k% s- j
- private RenderType getTexture(ResourceLocation texture) {1 l4 K8 P! S$ c, D7 d8 N5 J
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# i- V5 Q B" i g5 h' ]
- }$ N! L+ w" N4 o) p
- ! o/ ] N1 T! E
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: l8 n" ~8 o6 Y! Q0 }, O
- if (cache.containsKey(identifier)) {
. l' Q& q/ n' W5 T# J/ X* K( D - return cache.get(identifier);
l4 Z- Y6 q' Q$ F5 u( | s - } else {
2 X p! O# h9 s) {5 y$ ~% v - final RenderType renderLayer = supplier.get();
2 ?, U( O1 Y6 r8 ~- s - cache.put(identifier, renderLayer);
, L K; I" [8 @( Y - return renderLayer;4 T. s3 S" G/ H' i+ `
- }# }; g$ A; @9 A- {5 y
- }
' W3 S. g# M! I, z- B. n0 J - }
复制代码 |
|