|
|
1 w0 D5 g" q$ i( v) }$ x. {
行,这个怎么样" o0 s5 n$ E ]9 ?: T
- package com.xhg78999.mtrfac.render;
1 A' |6 O. l2 j" w
! }5 s: `. N8 ~6 N: a. `1 U- import com.mojang.blaze3d.vertex.PoseStack;
+ a+ H, N. k1 y, D - import com.mojang.blaze3d.vertex.VertexConsumer;
" p2 {+ T |% @$ M/ K4 g- ?' H - import net.minecraft.client.renderer.RenderType;
, k3 u! `, |! {& u - import net.minecraft.resources.ResourceLocation;
' ^1 u& T+ @" o7 Z. K - 7 b4 g/ F1 U$ Z6 T
- import java.util.*;
4 Z) H5 _6 T) w - & t. |% n2 U* c. p& c7 X' \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' c& ?& L6 K6 o g9 N/ J: O
! X6 m) S0 v! U7 q- public class LineRender{& i" F* J2 P: \- B6 e+ c
- private final PoseStack pose;; u; r" Y* N* k, {
- private final MultiBufferSource source;: S E# T2 P% C5 Q! Z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 O$ `2 h H5 ]- z' }6 V& X6 [8 p5 Y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" b! B2 W" n; W2 q7 t& K% _: } - : T* k5 z; N5 |3 L/ I
# Y4 {- n$ M/ q) z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
A. @! s" g: t! j- T7 h - if(x1 == x2 && y1 == y2 && z1 == z2){6 h1 n9 o! @0 h
- return;1 ~1 @- V& b/ i% t* g2 h1 B
- }
- U+ v* ]/ {3 g j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" u% J% r( Y5 R+ k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' [9 M; s" `+ D8 ]! `( e
- }
0 g0 s" V! d8 k: k - pose.pushPose();
+ V: b p" _. `$ h5 @; b5 m; n" v - final int newLight = convertLight(6);/ M0 t; z% _5 x8 `9 Z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 P$ R$ J& A6 A9 N7 n* P" N' F. _7 D, e
- final float lineHeightSmall = (y2 - y1);: X" e3 H4 }$ X6 U/ Z! B
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: X" c) N6 ^7 ^7 e, ` b c - pose.popPose();
9 W" w7 W4 ~+ N6 Y; |/ `* K - }' V9 u( w; V; C+ |- o
1 W7 A; X* b9 y# I! m4 @8 ?5 D- private RenderType getLayers(String texture, int light) {
. ]0 w; {1 C, d6 F6 A+ p - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 w6 f( _. ^# M$ G) F1 b( ?
- }; p% Q; G5 R# t4 |1 s2 I2 t! g
- , _0 f, u& @. d1 Z& Y, e
- private RenderType getLightTexture(ResourceLocation texture) {' _+ S x2 F. B# O' P
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ f( } d3 I1 N& K7 U6 m" T* K B - }
6 Z Q" _& W) ?* G$ U% E
# C1 y5 N0 ~' `2 X2 c$ K- t- private RenderType getTexture(ResourceLocation texture) {
. ] J# X+ i1 H6 D" e# N& }, _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" j F& u2 b+ p* p& G" i: e - }2 ]8 N! U% j: {4 m* b& h$ E
6 k7 m, Y* y% L7 r* f0 o3 s! K- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 |% W! H8 U3 e: X# q. p/ \
- if (cache.containsKey(identifier)) {$ c5 I; |3 {" q7 Q: I
- return cache.get(identifier);
# v4 L3 C# C/ j) y% p! h - } else {
' o4 Z+ g! H# r! I' a- L - final RenderType renderLayer = supplier.get();5 y$ r& F" v; l
- cache.put(identifier, renderLayer);
9 h; y# x% g$ a - return renderLayer;% k2 O0 E' q0 y [- ?/ u
- }; T: X, m2 q8 O3 l1 a* o
- }
! ^0 f( S9 h+ l/ H, s. W8 q) c - }
复制代码 |
|