|
|
& X! _# ^0 j1 l/ }行,这个怎么样
* }' Q( g% P! \- package com.xhg78999.mtrfac.render;
8 t) W% S/ R) p: l' i
1 d5 C5 Q2 _# F; j& r4 o5 i- import com.mojang.blaze3d.vertex.PoseStack;
$ v3 m% o) ]2 v. K4 }) @ - import com.mojang.blaze3d.vertex.VertexConsumer;
' V: X! c( @, d2 e" }2 j, M7 G - import net.minecraft.client.renderer.RenderType;
0 s5 ?9 i: }* t, S6 N - import net.minecraft.resources.ResourceLocation;
; K+ Y7 B- C+ m0 P, V1 [% e( |
" a( U3 ?. J% u- import java.util.*;
2 }6 x! q% M: n- ~% O1 c9 y4 B" I - 4 Q' Z4 L0 j& j. u9 x" }
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() I8 U0 \. @2 V1 u6 _# l4 W- A
- ' f' R$ G- u* H$ l" z1 t
- public class LineRender{8 H- B/ Z, a- q3 K+ j7 U5 k5 a( [
- private final PoseStack pose;5 S" a6 x; B' S* s' q" M
- private final MultiBufferSource source;
7 P4 n, D: \/ R- M" V) O. G: S) @ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 d% N3 b: U& G& z: Y, n4 e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 y0 |( x) v1 I+ R
, F7 i8 K2 ^( P' \6 h- ' _4 y3 g6 W- B: d4 E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! e+ Q" ~7 H6 |/ _' y" M - if(x1 == x2 && y1 == y2 && z1 == z2){
e4 |1 d! j3 m& v - return;
) O0 L' V% s$ y+ H; i7 [6 e - }( G+ O. l4 Y% @% T. B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# [# C4 }9 w3 a: Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- ?6 s% B5 ?6 u
- }+ t% W( N% T2 ~- F* N7 g% W
- pose.pushPose();- l+ V* X& B: R4 f0 ]$ I% U1 w
- final int newLight = convertLight(6);# B; o. e/ a8 r6 g( t& K2 q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 M! b( g" F+ n5 |0 q) b2 A2 I
- final float lineHeightSmall = (y2 - y1);
: x* W/ X. p1 _6 T8 Q& r - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( q# \! n/ I9 b6 ?' ~4 k$ }9 h; q+ K - pose.popPose();
& T( @8 y+ P% Y6 e - }/ l9 z5 `5 g! v: N/ \9 \
- . Q. y9 @5 K/ t. K4 X/ ^2 e9 ]' a' P
- private RenderType getLayers(String texture, int light) {
0 Q+ a' q3 [$ I - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) G# \3 M9 Z. n( b8 o Q! h" `
- }
7 Z! _4 r) Q0 p: S5 `: a' z( R
f8 j3 S" f6 l* f- private RenderType getLightTexture(ResourceLocation texture) {
4 X5 e# x W/ L& ]' y J+ M - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& b; v3 P( f: n8 e! A7 k# {
- }: H5 L$ f0 N5 z- Q% [9 s
- l% z3 g4 Q9 Y- private RenderType getTexture(ResourceLocation texture) {
) p; h. h& m- E; ?5 ?) T. z3 | - return this.cache(texture, () -> entityCutout(texture), CACHE_B);" w p* B2 c3 R" `
- }
& F9 N" P0 `8 k" w7 g! h- Z - 4 Z! ^0 P2 Y$ B2 Y5 \" Q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
q, L4 y2 Z2 E9 B' K$ g- S, Q - if (cache.containsKey(identifier)) {7 J z1 X& z' @' M5 E0 P1 d
- return cache.get(identifier);6 L2 A: W& \8 }# `) ^5 x# ?$ Y
- } else {# h8 N; i$ b$ H( o
- final RenderType renderLayer = supplier.get();5 y7 w1 M6 d& n, j
- cache.put(identifier, renderLayer);) Z- j. \4 G+ l9 a+ P
- return renderLayer;+ J7 }% F) [) l+ s3 V
- }
% u z6 c) E L) ]3 w - }
8 ?' G$ O7 D8 N4 } - }
复制代码 |
|