|
|
4 p/ y! v+ }9 ?: \5 C行,这个怎么样' L) `0 o% C/ }4 a( U2 W
- package com.xhg78999.mtrfac.render;0 F( @- a" A; P% j; z
9 T( c+ o4 h& s) K( }7 ^8 h- import com.mojang.blaze3d.vertex.PoseStack;
7 |5 L T2 W" |, b5 W% N - import com.mojang.blaze3d.vertex.VertexConsumer;7 t! w6 ?; I0 V* e7 C/ D
- import net.minecraft.client.renderer.RenderType;( A0 b* E- e6 c% m, J$ E
- import net.minecraft.resources.ResourceLocation;
) H- Q {' v( c& L8 ~ - % ]0 E. b% S& r
- import java.util.*;
, Y" \ a+ p V - 5 `) M" Y2 T( i9 T0 j
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 \) b& U2 n& W$ Q O! b
) h- N) r0 {0 M& b9 t# q4 ^! \- public class LineRender{
4 K5 C7 m+ F1 q( b. w - private final PoseStack pose;
" f N0 g( i# @1 U/ ]6 b6 y8 @' | - private final MultiBufferSource source;( z/ e* ^- ^* I$ T
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();; m+ L) s9 o k2 c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- q* h2 q1 O3 O - 6 B% N8 H; D# ]: d! d0 H; _* p
( {' a2 O( e. F4 L- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ j# z- S% F1 V; ^ - if(x1 == x2 && y1 == y2 && z1 == z2){
3 R' ]1 ^) M! U8 Y - return;
; W d1 `9 q" p7 L1 R+ N - }$ M4 H; L: R) y g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% x& o. C( g+ S! a0 [, U
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% [5 m& t J" K6 J. S6 y5 X! Z
- }
+ T; N. X$ M/ |% M! f% q - pose.pushPose(); {, X- W1 e- a1 }: h( u# E B O* n
- final int newLight = convertLight(6);. k0 Q# y% |6 B2 G7 J' ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 {0 o0 h! }9 k5 Z, h0 y# A' p - final float lineHeightSmall = (y2 - y1);2 r* B* {9 S0 L' G
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 X* T, ?( S# X' |" U1 I) N8 b
- pose.popPose();
r4 o& l; Y4 u - }
; Z8 M' t6 j$ x
% q, W& D* W& G- private RenderType getLayers(String texture, int light) {1 [( W! K; B/ [0 W7 \- }
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ C4 @; v- h) ~) g; X. x1 o - }1 T/ Y; @8 t( W: H9 y! D. ^* P, z" s) B
- 2 G1 u6 W @# A* N; `- ^
- private RenderType getLightTexture(ResourceLocation texture) {
8 ~% v \9 Q, I8 C/ r c - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);# [9 }- {6 s! N$ h
- }1 s3 \' H E* T1 X$ Y
- 4 t2 R" ]$ v7 F8 U# x* g
- private RenderType getTexture(ResourceLocation texture) {
: t0 n: r6 K+ D( ?3 n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);; M1 x1 |! o' ~8 u
- }& w" R+ Q9 R( s9 a' _$ f
: ]: S+ S8 Y' @: G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 H7 \3 j2 t7 G x - if (cache.containsKey(identifier)) {
4 _. @$ {5 W4 o" k! C' ?. j" S/ r - return cache.get(identifier);" W2 A# d" \9 l* X+ R
- } else {
( y% x6 A5 |6 d* l2 m- r, X - final RenderType renderLayer = supplier.get();9 k3 |: V; k6 [ Y( Z) `8 ?
- cache.put(identifier, renderLayer);
+ v( W0 m8 J. `7 I6 r - return renderLayer;
# m, D1 o7 o! y! {/ v/ V' i1 j R - }8 Z) _" ]; ^0 p# V0 b
- }
n% ^! ^3 q( A, }6 m8 B - }
复制代码 |
|