|
|
( b i: Z9 Y: J" ^! ~/ V" u
行,这个怎么样( h0 T: e, M. u) x" b: e- I
- package com.xhg78999.mtrfac.render;/ s$ |* ^0 |) y1 M! ?
- B/ r+ a. t5 L0 L
- import com.mojang.blaze3d.vertex.PoseStack;
! i0 b; A/ Q }! [% y& M! A! n - import com.mojang.blaze3d.vertex.VertexConsumer;5 m$ c$ @. d+ T/ V
- import net.minecraft.client.renderer.RenderType;% ` e* q$ ?% R$ W8 _
- import net.minecraft.resources.ResourceLocation;
$ a3 e( [5 T/ c- a0 _8 m5 {
, {% ~3 N( [- I3 ?- import java.util.*;- x* S; D2 H+ f B# Y6 q
- $ ~2 }7 \6 s+ n, r4 ^8 D4 G% X# N9 c$ {
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" O; }) D% F5 M
+ ]/ W# r) H: L$ v3 V- public class LineRender{4 Q& J' ^) `4 Z" Z% Z
- private final PoseStack pose;. S) }: m$ `5 x
- private final MultiBufferSource source;
5 O6 y1 f, c0 p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; H, {6 G. t* y* ]7 z# W - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 S3 k }/ ]; E3 j
4 C' d& }3 [1 P/ E% ?9 S, D/ l
0 M- s5 S! C) i9 a6 i- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* O! R- y* G& D7 S s1 I6 O0 c4 C
- if(x1 == x2 && y1 == y2 && z1 == z2){
8 R/ r; p+ T, ^) q" _ {2 Z. Y5 ?6 x l - return;/ r( A+ j+ [ @
- }
, T* T9 G. n7 F2 b' p- p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){& z! T1 P8 d: [2 _" Y2 t# \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. u$ j; ^' x$ N: G5 k4 O" C' ]
- }
. ]# _ o) t8 r( k+ H% K - pose.pushPose();
+ {* f# V+ S$ W" g( D - final int newLight = convertLight(6);0 s- Q. ?; n+ e8 \! t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));! v7 A* }3 v5 |
- final float lineHeightSmall = (y2 - y1);9 G/ _1 G7 B$ _9 v5 R& n4 L
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' J! b( _& Y8 }& Q - pose.popPose();& k' j% n) L# U B$ D
- }+ r) q2 q7 Z5 l' f3 Q; U
/ w9 q7 I9 s/ w9 t6 j* Y5 e- private RenderType getLayers(String texture, int light) {9 o, p) E, r8 C- v' o8 z* ?
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% o( s6 y) _' E
- }
% V% |7 ]4 w( D8 z4 ~
4 b( ?$ i5 y" ]- r2 A; U0 p" |3 h- private RenderType getLightTexture(ResourceLocation texture) {
4 _5 i- x) R+ L& L( y+ f* [ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 n9 e7 p1 E$ p& m2 @
- }3 _3 H3 G7 T% B8 K0 U5 T
6 C$ X' b( g8 [% ~- private RenderType getTexture(ResourceLocation texture) {
* q; z1 Q7 b1 W( i% d. ^) S - return this.cache(texture, () -> entityCutout(texture), CACHE_B);' y! s# ]9 {+ n7 u. T
- }
. p# m9 }5 I: e - 4 x. ^% r# b! ]. I8 s' R; a
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ K F' x+ k3 D8 W: Y+ Y
- if (cache.containsKey(identifier)) {
& M3 C' {! N: N+ e - return cache.get(identifier);
! m5 O$ R+ g) t, q+ h; F4 \ - } else {, C. w- U1 [/ Y4 ?7 O8 G
- final RenderType renderLayer = supplier.get();
5 J! W: U4 V! H% ?4 ` - cache.put(identifier, renderLayer);
p$ ?! o7 s! _! X. c - return renderLayer;
3 U2 \7 j; f3 q - }
' S1 J0 O- P8 K- J& d - }
' I! Q- v/ l/ t, F4 n - }
复制代码 |
|