|
|
1 j9 j0 Y- n7 s( B3 S行,这个怎么样( C/ w9 u p N& E2 a4 Q, B. E
- package com.xhg78999.mtrfac.render;
1 x/ ~) _) R% E - ' B" c( B& J: U! [; w1 ~
- import com.mojang.blaze3d.vertex.PoseStack;
7 p1 H# L# |3 d f- X! | - import com.mojang.blaze3d.vertex.VertexConsumer;: d; q4 `+ t K8 m7 v g
- import net.minecraft.client.renderer.RenderType;3 J9 [! x, _& f
- import net.minecraft.resources.ResourceLocation;
5 z! d' v2 Y; q: A& i2 i/ x0 {
# n& u Z* h5 H1 B0 X: \3 i- import java.util.*;
E3 @2 \. _9 T$ o - % G$ z \4 b% @& m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 Z3 x6 F/ j6 `; b$ e4 _, J% {
5 D9 T; e* V3 u- public class LineRender{7 }1 w& }" N2 H9 A; `
- private final PoseStack pose;
( K, y A% K: k% a! I. {+ d1 | - private final MultiBufferSource source;) w/ k, U. ^5 P6 Z0 n1 u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 @7 \# f6 L) w - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 L' _" u2 J/ X8 N9 x% G
# `: n! k$ O9 D7 ~; K
0 B6 a- w9 A( ~- J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; k, e* c4 [0 ^) r
- if(x1 == x2 && y1 == y2 && z1 == z2){: \! R Z( L5 D: ` v
- return;
6 ]% }2 ^: X* ^. A. C0 x% ? - }2 l) F7 z7 `$ o# E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 t& u4 y% T6 z) ^2 |9 E - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ Q" Q, X( ~1 @; E# u2 p - }
% I( ?% i6 z& g) U3 A - pose.pushPose();
* D* p' }+ V" t$ N - final int newLight = convertLight(6);# p0 q0 e8 S o* v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 l% d, u% D3 b: E. T9 d1 M
- final float lineHeightSmall = (y2 - y1);/ D# k* r9 `& `9 f! a- i3 e: G: [
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ M y# V) k. C: _ - pose.popPose();
/ B" w( d8 H# ]) | - }( P: I( ^0 ~; ?3 T2 _% N, S
. A& Z. \2 i( }: n- private RenderType getLayers(String texture, int light) {
& @9 G# ~2 o4 t3 j4 f( L. B! C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 o& D; R, }# i: R) P5 R0 u
- }
* U& m3 }3 F7 F/ }: b" Q
# Q1 ~& ^' o3 W- private RenderType getLightTexture(ResourceLocation texture) { R& {5 P0 w a- `* g% ~/ H
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
a) E/ P7 G9 r& ?3 x5 Z - }
9 @0 k$ i, u- ]0 N% L - # B; T: Q U" S5 B- z7 w! D
- private RenderType getTexture(ResourceLocation texture) {
8 i( x p# t' s8 a3 n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
7 |2 v- e# `8 F6 P7 B2 @ - }
+ y$ V& K u+ w0 m; n1 s
2 @1 |- H, y$ {; y' }; k8 {- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" B8 ^9 A( R" @9 N/ \
- if (cache.containsKey(identifier)) {
& Y; u* v9 T5 ~5 u8 k - return cache.get(identifier);
( j% R) h; l9 k: G7 n- g - } else {
: G9 T8 B3 a. s, t9 {8 g/ _ - final RenderType renderLayer = supplier.get();6 i- e2 ~: M4 M! G7 Z
- cache.put(identifier, renderLayer);% _7 S8 O9 X+ I1 g! Q$ o
- return renderLayer;
5 w4 F( ^$ _; R1 g5 z9 E: Q) L: [* ?6 ` - }
+ k! i( y K& j& a9 j5 o - }
- u, [9 N+ I* F# z2 F6 C% x - }
复制代码 |
|