|
|
" h. i' b& X6 e4 e8 v& B o8 @行,这个怎么样
' B0 o! |+ D& F! |+ C C5 A8 ]1 \& A- package com.xhg78999.mtrfac.render;
- g6 R8 T$ w; \- C0 q
' Z% n6 v6 _# T5 O* Z0 z- c- import com.mojang.blaze3d.vertex.PoseStack;
2 D. n$ t) y+ h$ }" e1 ^ - import com.mojang.blaze3d.vertex.VertexConsumer;
% Q7 L- a/ W8 v% |; B - import net.minecraft.client.renderer.RenderType;) C7 r. A; e9 ~. W" k
- import net.minecraft.resources.ResourceLocation;
& E9 E [; `* B3 B5 S* T8 u
! Z5 M5 s% `' z h+ g" V- import java.util.*;
- u$ s7 n4 {0 I& W - 8 u' G1 }, g: p E: v F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(5 Z+ b q4 @: r9 B
9 z5 E+ a; M7 p: _" p0 L9 q( y8 G- b- public class LineRender{$ I6 C t# V- o3 h( g% R9 l S
- private final PoseStack pose;) G# I- @, { N
- private final MultiBufferSource source;
7 M; J2 U1 \" N7 i5 q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! _9 M* A. W8 c }+ P. i b - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 j6 R5 E0 @# K6 y) d+ l5 }
8 L3 I# a J }- 4 ^- H8 Z# Z# R3 S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ k/ |$ j& q: l0 \2 D
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 C9 t0 L2 j8 h, Y: S - return;3 e% j& t4 p* t. _4 y; y7 u9 G- \. j
- }( m8 l& I& `/ }$ t' I3 {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- D! L2 f* d1 p# n: R8 f% n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 \9 e# ]; d& s- q
- }
9 _7 x) B9 _- `! i6 l% J: ` - pose.pushPose();7 \& l: w: B. [4 J7 o3 z
- final int newLight = convertLight(6);2 M# ^$ n, ~& l: P' Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: X' A' Y+ h4 G* w W* t
- final float lineHeightSmall = (y2 - y1);
) e" P" W) d4 \* J3 r, ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, C' ]0 F) m& U7 ]% |" E; l$ \
- pose.popPose(); l: A% z7 X1 M, I# t7 L/ o
- }
+ }5 l0 b' M" U, m$ ?) x: o - ( Z1 I- K6 Y+ H5 @) h5 [
- private RenderType getLayers(String texture, int light) {4 i7 }2 w1 ~- p9 B
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( B7 |2 Z" z3 ]% R- Q* H, M$ r - }2 n5 S9 i5 x8 l' ?- ~: x$ |
- . v! M. ?4 K2 ?" @" J' w
- private RenderType getLightTexture(ResourceLocation texture) {7 ^% H$ \# j q% \& v$ m* ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) P! r- R) d; g' a
- }$ X3 @# x/ I% u3 x* A
- + p4 ?* X; J& c$ {5 B
- private RenderType getTexture(ResourceLocation texture) {4 v: A/ ~/ Z P" x- P& C ]% p
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 \# o0 H2 Q$ a - }
6 n# W" B, C$ W' p) K4 S
, U. G1 R+ J3 z a- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 a/ v- C; \2 _/ r9 v; F
- if (cache.containsKey(identifier)) {
, H' i6 Z3 _6 s' o! }% I* ~ - return cache.get(identifier);
8 {6 O7 j* P: q0 X9 T& s4 {2 Y - } else {& {& z+ D! G( [+ r6 J: a
- final RenderType renderLayer = supplier.get();5 T0 ^) r8 ]# H }2 ?0 U1 r
- cache.put(identifier, renderLayer);; S+ w' D8 S* a" w X( K; U
- return renderLayer;: n1 g4 J0 p7 T( I
- }1 g) w% Z: p) D1 P$ ~0 r
- }: E6 L3 s6 F- N/ F3 ~% E
- }
复制代码 |
|