|
|
! B/ v0 x. W) G4 G4 W5 v
行,这个怎么样
/ p# Q) {" x0 q- package com.xhg78999.mtrfac.render;* U5 [1 d" T) b& i
- 5 P) `$ o( C/ F) b0 u4 N
- import com.mojang.blaze3d.vertex.PoseStack;
* c5 A9 t! B* M6 G3 Z - import com.mojang.blaze3d.vertex.VertexConsumer;
( f$ \4 m7 H) U. J5 d - import net.minecraft.client.renderer.RenderType;9 {2 q/ A* Q6 F7 o/ l; B
- import net.minecraft.resources.ResourceLocation;& w' g2 N! i8 c& v% f$ c
- # T: s+ {% M+ g R- Z$ M' [6 O
- import java.util.*;
+ V1 [6 L/ ~, I( r
. Q! ~9 I- n: z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! Y7 r# c( g1 Q8 j! A: z$ T
. h9 q3 [/ j2 h! p8 |- d# @- public class LineRender{; P5 f6 \- u( R6 @5 K/ t
- private final PoseStack pose;" a# ~4 ?; Y) K. h6 g% s5 T/ f
- private final MultiBufferSource source;5 a1 \9 t. `0 c" F# s3 a5 R# j
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 B9 m" ~6 r* I; J/ Z) c6 A# R - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* J5 d$ R& B9 E" c9 t$ z - 2 d n- b! j/ F! D1 ?) j
: k% C: |: `1 I8 d% x$ ^! U- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) m/ u$ u$ U) t. J - if(x1 == x2 && y1 == y2 && z1 == z2){
. H. }! f7 m3 v. s8 F& A# Y - return;1 i# r% ] z; p, B
- }
$ n8 p+ z. _1 h3 f9 y0 ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 ?- ^' B# M. ~- P3 i7 [ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: u) p9 w3 G" H i - }# Q: T9 N$ n. W0 g
- pose.pushPose();% g2 N" t) n6 I$ L$ ~1 h
- final int newLight = convertLight(6);
( ~, j& w" u& L* s& z! t - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 S8 d3 |. N) V9 N% B/ L d' q3 G - final float lineHeightSmall = (y2 - y1);
* P, u! W' A. ]; o( H3 O! ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* [4 ?# c; @5 }; { - pose.popPose();
2 U3 k& t% {- J9 ~- b; A - }
' m: V1 n! n! w - , Z' s( K- Y$ \# X* C6 p9 l! x
- private RenderType getLayers(String texture, int light) {
$ F; B# e) r% ?5 W5 ^# ^. L - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; {/ \2 v* P' i% u, c8 L - }, F& s; y# F; K7 o7 _3 {% W
- 7 d% n; D9 {9 S$ Y; p* {, b
- private RenderType getLightTexture(ResourceLocation texture) {
# i9 N* s8 @$ L) P$ v* L - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" n% t1 p, ?, l' { - }7 F+ n0 S; E5 b2 ~& _$ e
- 1 u, T& j4 a, M; t7 f
- private RenderType getTexture(ResourceLocation texture) {- Q$ }! i( c1 P0 f
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' m- g$ z& A# }+ e$ P1 h - }4 z- ^; \0 t& a
- . i7 e6 \; E! m# \7 ]* t
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' ^8 v/ u" O7 H& ]& h' u - if (cache.containsKey(identifier)) {
* D( K2 o0 X9 ?, c2 x - return cache.get(identifier);
3 c6 f S' n1 u, H& s3 D B$ ]8 } - } else {# n, p8 T3 w8 C# o) {
- final RenderType renderLayer = supplier.get();0 U( ~. p+ b5 F; K* u
- cache.put(identifier, renderLayer);+ D! N! o! M i
- return renderLayer;5 k) Q% J8 G! c6 `' K, S: X
- }
0 k7 [6 O) t6 [; m' y7 v9 _ - }
6 L% u& ^) C% |' |" h' z+ C4 _( { f$ ~ - }
复制代码 |
|