|
|
' N J; C6 O7 e w+ N行,这个怎么样
, F# e2 s4 W( R- package com.xhg78999.mtrfac.render;
3 v# i. r) L$ L3 Y. J/ B& f
2 b# I; u9 b& V# I8 v, e- import com.mojang.blaze3d.vertex.PoseStack;; L% \& {7 K; ^
- import com.mojang.blaze3d.vertex.VertexConsumer;
* e5 B4 `+ n$ K1 K4 h# _ c8 B. O - import net.minecraft.client.renderer.RenderType;
4 c# U d. D" g) P' a' V$ X - import net.minecraft.resources.ResourceLocation;
- y/ r% ]+ T' Q; |# X - + m: d8 [8 U6 i/ L: {
- import java.util.*;
3 Q, ]$ s; S$ [3 d. m8 O5 e
/ Q8 k8 h: }# I% |+ X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 t* c1 \! {9 O8 R# I+ }+ J - ; q( \7 O) a) X3 u
- public class LineRender{
6 X `0 w# A2 i5 M9 |* } - private final PoseStack pose;
" C, h9 W5 G5 c - private final MultiBufferSource source;# o1 q, m- Z" H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" H' s- P! G$ t$ u4 @" _2 Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" h- T, p' t. |0 }9 b
- 5 ~6 {5 g9 Y1 ^9 m& r3 T% g
- * x t( N7 j! X/ U; p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 v; Z+ k% Q- U6 p
- if(x1 == x2 && y1 == y2 && z1 == z2){& h* D) @6 H0 k' f3 p3 h
- return;; L I. N3 ?+ E: @' X% ^
- }
& ]' u$ I5 L6 Q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, @2 o) }* j# L9 u6 r% F( \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 b: R3 N8 J. h% s& e
- }
% e/ ?" w2 z( x5 p' u: w; k - pose.pushPose();
7 X2 k: D8 O; G: E. M - final int newLight = convertLight(6);1 m9 k9 l9 u' x. b4 \& V
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 D$ V$ S* ~! ?! T9 U2 K - final float lineHeightSmall = (y2 - y1);$ ^1 N5 B7 O; B- t* K$ G6 m% s- C
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: N$ h* R" e$ E" A/ [ - pose.popPose();( B/ M: a) [1 [# {" l3 ~8 b, F0 v
- }
) \4 m8 C) u$ W4 B9 O
( i9 K! d5 J& x2 ~, A1 _- private RenderType getLayers(String texture, int light) {
, |- r- T$ f% k3 A0 _. Q4 l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ y' Y/ Y- p: A' q+ D0 d - }
% g6 o+ a# I0 ~) L% B6 [5 C
' s; J! P6 E8 b. w- c: |1 A+ g- private RenderType getLightTexture(ResourceLocation texture) {+ j! v, J* ]' K0 H' x
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ E! v1 M- F h- V) }: w - }3 H$ ^* V) f4 x" g0 S
7 W! j# U* A2 |: C! Z& z- private RenderType getTexture(ResourceLocation texture) {5 H* H/ a) y7 K5 x( J) U- [6 I
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 ~% u4 s. [% a1 A$ S" r$ @2 A - }3 h/ `# h, C$ L+ @
- - a& o# `3 H$ Q3 w' s
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& \/ I! Q) E% c4 B; _. I - if (cache.containsKey(identifier)) {
- v* J! F" W ^7 V6 `8 ?! _6 d - return cache.get(identifier);
. G" b' {0 ~9 c4 a3 A - } else {
# p* e% j9 A' e* Y) g, A" w - final RenderType renderLayer = supplier.get();8 T$ p1 a9 n; R
- cache.put(identifier, renderLayer);
$ U o" F# v- h# q9 E; z( p - return renderLayer;0 x6 V3 f4 o, _! y- `9 P) d
- }9 s6 Q& g* Y! @5 j9 W& ?+ f
- }, m0 m, W+ D6 e+ f! M8 r
- }
复制代码 |
|