|
|
) L8 d. y7 ^/ v/ P( V$ y" s& W
行,这个怎么样) Q) Z! D8 m" T; A
- package com.xhg78999.mtrfac.render;- `: Q/ \0 o. v- S
! D$ P; z4 Z5 s# w0 E( M5 S- import com.mojang.blaze3d.vertex.PoseStack;
( f5 C2 E) Q3 \7 ?( @% V& i - import com.mojang.blaze3d.vertex.VertexConsumer;4 h1 B/ c7 F+ c# u$ ]
- import net.minecraft.client.renderer.RenderType;
2 v8 l/ s3 j. J0 t k1 E - import net.minecraft.resources.ResourceLocation;
1 _/ l9 i- n3 V" L- S
5 {. b% X) a6 z2 {* \- import java.util.*;
( {9 W! T' o% F( W - 0 J% P$ R1 @+ S7 g; Q/ L
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: p m+ y5 P# `6 Q- t( g0 Z
$ H8 f: O% e& }6 n9 J/ }6 j- public class LineRender{
: C2 z, O; f9 x - private final PoseStack pose;
1 |4 r4 ~. o& s - private final MultiBufferSource source;! d3 O/ b. f5 d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 S; {' R4 j4 q6 p' c - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ b& j% g9 ]. w0 m# b. L
3 U+ V: d: k# D3 v( {$ e4 ]
6 @& s4 _6 v) l4 Y2 T. D1 `1 N$ E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' s9 Y5 k' H" |+ I
- if(x1 == x2 && y1 == y2 && z1 == z2){
& E7 @5 D9 L& H - return;! {+ u8 ?; k9 F+ Q% r2 G, F
- }- V, b6 d. |, I% w* {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- m5 T( e$ L4 I8 c! _+ w% B
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- s: p, x8 f3 O. i+ d; Q8 G' o - }# I. `% Z; E8 `/ U8 M+ d+ z
- pose.pushPose();) t, Y! _- ], b$ ^0 C( [; n
- final int newLight = convertLight(6);; b0 r, I, u6 u. Q u* E
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' I# T# \% z/ j/ d) l1 _ i - final float lineHeightSmall = (y2 - y1);
4 c' n0 G; L$ D3 s" _4 U - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 b0 |1 ] D' i" v8 P" t
- pose.popPose();+ e9 A5 l& c6 f( K. x' x- C' [
- }+ t3 E: H" o; J9 f1 s/ h
+ }! I( o% M: y8 f, _- private RenderType getLayers(String texture, int light) {
7 T! a8 o6 W/ j) w - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; B/ F3 t! C' N
- }" C$ h9 @, r6 r3 ^ V% I
! h; _! r! b( W" |4 D- private RenderType getLightTexture(ResourceLocation texture) {3 f' @3 Y/ z% h5 ~9 k$ X
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& K* A& M" ?! \% f( P) ?, w6 i - }0 c) [- A4 V l v
- 0 H, W2 k$ T" A' h, D5 E% M
- private RenderType getTexture(ResourceLocation texture) {/ e% e u% G I1 I5 T
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 a/ D' F/ I# L1 H9 |
- }
# w1 v: ~9 K. A) p2 z
+ k9 I7 o; f7 I7 ?- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! y- c! P& C- {# w, {& X - if (cache.containsKey(identifier)) {1 {( T2 _- @$ U, b2 X
- return cache.get(identifier);
& e% v; z. V7 [( X; O - } else {
8 N7 o0 e5 i' q) i* C - final RenderType renderLayer = supplier.get();
4 n8 ~$ n2 [" w2 ^8 V5 D/ I3 ` - cache.put(identifier, renderLayer);
& @$ _ c, ?) p; p" x5 ^* r/ O - return renderLayer;- d: [4 X- S2 {5 D4 J
- }+ i4 [; ]5 V5 P' ?) M5 ^$ u; H( d. @0 P2 S
- }
* h8 q6 t7 ^( H3 S - }
复制代码 |
|