|
|
9 W; f4 B* @! _6 o0 e! r$ r, E
行,这个怎么样
7 h) i3 O; j% x' H, D: C6 A6 \- package com.xhg78999.mtrfac.render;1 B. L/ g1 C( |9 p" U
+ [1 b/ ~+ H1 b0 _. G9 D; W& H9 ~- import com.mojang.blaze3d.vertex.PoseStack;, W% H. R8 l& U p
- import com.mojang.blaze3d.vertex.VertexConsumer;' F" J' ?% f9 A/ `
- import net.minecraft.client.renderer.RenderType;: i4 Y; l* R. a9 D0 ]- l
- import net.minecraft.resources.ResourceLocation;+ h I7 h) z f
( n1 a) M* f$ {9 T- import java.util.*;
5 p2 D+ P. I/ U2 } - ) W7 T2 |5 {& P4 j# ?* r6 H% n
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( U( `& T3 s% {( Y( x8 W9 D1 `
z0 W9 B( f3 M3 x0 v- public class LineRender{
' A J- f0 {/ Y4 E; b& Z4 T. e - private final PoseStack pose;
! P* c# x5 c9 I7 A/ B+ G) c - private final MultiBufferSource source;3 E/ s7 x* S! ?" ?7 C: u, u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 A r, L; T8 m- L4 i ]( D5 J
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 W# I7 [" a7 |2 V8 S- S3 ~
8 U3 ^9 Y5 \+ F; [+ ?/ [- ' l! H& B: v! O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 N- Y# P8 e5 k) r/ L! o - if(x1 == x2 && y1 == y2 && z1 == z2){
7 w7 ], V, A6 W. c5 h1 b - return;
6 q" y: ^; q0 X4 p8 ?9 S9 P - }# Y5 h3 P7 l7 {0 W4 J$ ?
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* U8 @/ ?0 j d5 S6 N) I" N - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 g' Y! f' u4 p" e) s3 u8 } - }0 j0 `& j2 l1 g
- pose.pushPose();
7 y% e, G; P+ ~ - final int newLight = convertLight(6);
: y0 H6 _* d" _2 p j1 `. V& F1 T - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! W( _& k- R" m# n - final float lineHeightSmall = (y2 - y1);
$ h; f2 u; A6 C: ^2 p9 s* ` Z1 y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- a; E( @& E$ j! H - pose.popPose();3 {" x/ m! e' ?/ J' m8 ?) d$ l
- }
1 b5 i! R) G* Q5 f# L( A0 t2 Z
- Z7 ?% T/ ]8 o8 t, N- private RenderType getLayers(String texture, int light) {; ~# Z( t Y+ i, c
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 M% s: t2 O: p8 @0 X# F3 ]
- }0 Q F' e" k9 y8 H; Z: t0 z5 s
1 G9 k# z- E# a* C9 C- ]7 ?# d- private RenderType getLightTexture(ResourceLocation texture) {
5 A# j, a, [) v/ Y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 {2 e) E4 P7 }4 y8 _6 N - }- w5 ?! L. f' H- y% [) C+ b }7 C
- 1 `3 f* R( \* U
- private RenderType getTexture(ResourceLocation texture) {. a S7 z7 I& G& C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' X- s& m9 L/ Y8 \* w - }
8 W$ x2 D6 O! ^; d - ; [! ~ {" z' o
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' F/ q1 B' R1 [9 S* F& i1 M$ x' U
- if (cache.containsKey(identifier)) {* [" ^* [9 h6 v8 Q% y/ V! O, T
- return cache.get(identifier);
' o- v. S0 T4 g! R- v7 B - } else {4 |& g Q! D- H: {6 j. [
- final RenderType renderLayer = supplier.get();! U0 T1 y2 f k: d
- cache.put(identifier, renderLayer);, w d* ?3 C3 S
- return renderLayer;
7 L! j" ~. R0 W N - }
8 U3 x7 a' B% [, r" V - }: C4 U5 |- D9 D4 V9 j# }
- }
复制代码 |
|