|
|
# n9 F1 d; s. \' f3 z% w1 ?) L
行,这个怎么样
. i: O# t6 l+ U- v$ n# j& D- package com.xhg78999.mtrfac.render;# v) H/ f4 n* }% L
- $ y& ^% t- a+ p0 B9 Y
- import com.mojang.blaze3d.vertex.PoseStack;
7 L1 A4 L3 L; @& ^! j# d2 O - import com.mojang.blaze3d.vertex.VertexConsumer;1 u4 w# r+ \2 b
- import net.minecraft.client.renderer.RenderType;
7 u8 |2 K) h& C2 |/ v" d - import net.minecraft.resources.ResourceLocation;
, u' ?3 b5 |3 W - : n9 t( h9 Y1 D- g* j& u
- import java.util.*;
6 [% H9 @: ^. n+ e1 ?) j - ( S* M; I7 H; U. x+ w U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 V) y1 P* D/ U4 d - # t" S+ e" w/ f! w1 n
- public class LineRender{3 F. c. O( z; u. C0 {7 J5 T
- private final PoseStack pose;2 s8 b! |8 B# T# \ n2 G' _: b
- private final MultiBufferSource source;/ ~5 @4 p5 W/ Y' T. g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 l- V* l2 F- F& s6 F9 U8 e3 J - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();: t8 A; \# @" T5 ?0 {
- 5 b ?& r6 K& W
- 7 J. P- L) j( R& o' x0 T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 {2 a! b W; T" ]. ]5 d6 x- k - if(x1 == x2 && y1 == y2 && z1 == z2){
8 [* n! F: p* w& F, B A - return;
& @6 }: o% P l/ h% ~( O - }
$ u5 }% b2 u( ^: K5 y8 F! f9 ?$ j' [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 u% c7 i$ d. v% K) p - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 O2 J6 ?9 E: R$ `" m - }1 V* c4 k) S: g# Y4 ?
- pose.pushPose();& N" h4 F7 p2 U: }" ~" F
- final int newLight = convertLight(6);+ X! `/ B% v" g8 q& v9 ?
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 E. }: F$ D! {# B; v6 @: h - final float lineHeightSmall = (y2 - y1);
/ Q F1 `* {/ G* G x {+ @8 h' j - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);4 V- ~0 p' D9 _& R* }0 A6 P8 P, u
- pose.popPose();
% b$ W2 L' N- j H R: o% x3 E% l - }
, R% s8 y, F' G, x. A+ `* s - + _# Y" p6 h, q* h& l0 L" }
- private RenderType getLayers(String texture, int light) {: P" j$ V( D- s* v$ Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 _" K* P K1 o) y6 B% I - }4 Y9 _+ ?2 P+ c) g: e3 I" v
, y. c E/ D- D; T- private RenderType getLightTexture(ResourceLocation texture) {$ ?0 X2 k* {4 h4 @! t, x* u
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ m, C T! u- C% q6 [0 a - }- ?* D2 M6 w7 A
' B* J/ P0 z1 {- private RenderType getTexture(ResourceLocation texture) {
8 W, y1 W! r& c/ \1 d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 l7 d, ^" k c; {" c: O
- }2 Q: D3 ?) ]) @1 V
( J3 a4 @2 K9 }9 W- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 s+ F4 Z* K7 }% C
- if (cache.containsKey(identifier)) {8 q5 ~$ R/ p" _% J
- return cache.get(identifier);* d; D3 N: E+ Q: H: ^- f3 @5 j
- } else {
0 [" {0 P/ H) O' R# _- ^ - final RenderType renderLayer = supplier.get();( T' ^# a5 F' Y
- cache.put(identifier, renderLayer);
+ D7 a$ D e& G/ V |7 B - return renderLayer;
# O! \4 @, }: G8 O - }, e$ l2 d) M0 [1 |/ v
- }
, o' O9 ?" Y+ G( k' j9 R. m8 v - }
复制代码 |
|