|
|
6 q/ r: s+ c' z# I4 d行,这个怎么样
! O! ~6 [( H' j" p, i* J$ h- package com.xhg78999.mtrfac.render;
. ]) q I$ R7 {! g* j' b- F
7 m: |) }, y# R2 Y- import com.mojang.blaze3d.vertex.PoseStack;% q- `# b) T4 _3 h4 Y4 {0 r
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 O& K3 }! o8 u; t+ \ s - import net.minecraft.client.renderer.RenderType;# a- i7 B8 }* |6 @6 X
- import net.minecraft.resources.ResourceLocation;: C9 R8 @3 J a3 g* n6 d
- . v/ ^. {' A2 [$ p# Y
- import java.util.*;
0 _$ T. H9 B3 i- N' l p$ k - 3 x0 z( N; Z+ x+ f* W1 L
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ j6 M; F) _; w: x) M7 ^ - 0 J/ u/ N9 _/ l6 h8 N: C: P
- public class LineRender{( b, p) u5 s+ ^+ g, R! H* Z
- private final PoseStack pose;
% c+ Y4 u; N m* x - private final MultiBufferSource source; A$ ~9 p* @7 g! I6 M1 {
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* U, j8 @9 m9 ]. |3 u; F - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 m$ T6 K# Z$ x" T
# K# ], n, O5 q6 N. B" |. o- - v( ]0 N# |8 W6 H. p- p$ ]7 y7 _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 @- w) P7 [ a5 {. ~1 V - if(x1 == x2 && y1 == y2 && z1 == z2){
f& B; n0 T2 j# a( g; \ - return;* J3 N9 h9 F4 U3 L
- }) i O0 E* g( p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% Y" w+ f# V T& e( |* W$ C. w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' J- ~* d7 P% D' {) T0 g/ U
- }, z& ?! k$ ]# r$ w
- pose.pushPose();
( l* \" D1 _0 o6 b- W2 } - final int newLight = convertLight(6);: ^ j1 w) w% t& s
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 I6 O M! \' A) ?4 }
- final float lineHeightSmall = (y2 - y1);1 C, \ f2 W# |& c. W
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* z, ]- G8 H' I) A) t
- pose.popPose();; ^5 E& P( E+ c/ M. V! ]
- }, ^4 U5 d( ^. V& H, O+ R' Z" ^
- ) I! M( B: n; `9 L5 \* u
- private RenderType getLayers(String texture, int light) {
" j: x4 B" d4 V9 i( v) ~/ x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: _4 d9 L5 m4 z4 v - }
; c) |+ K A$ V
& \8 Q& X$ ^' g& @! Y- private RenderType getLightTexture(ResourceLocation texture) {2 Z0 U" ~+ _/ e. L% f8 h7 A0 W
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ o/ ~1 t+ T m1 m+ X& B l
- }
6 o7 I! ~; i1 V9 z - 1 Z& D* i6 H7 g- M2 C i+ e
- private RenderType getTexture(ResourceLocation texture) {
6 ^+ k8 b4 o# J- D' I, \ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- K+ `# D J8 W - }
4 U8 D6 I. _4 ]9 M6 i3 E
$ [% d$ c) I5 b$ [# y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( Q* x# ^5 H. e! m- w; v% g) ^
- if (cache.containsKey(identifier)) {+ g/ j; k* q% ^' E2 y/ D
- return cache.get(identifier); i" M% t$ r0 r* M; u$ f$ `& K, M
- } else {
2 h' S6 V7 p0 w - final RenderType renderLayer = supplier.get();1 G0 T: Z! P6 ?% i- N# h
- cache.put(identifier, renderLayer);+ U1 T9 J' J" o
- return renderLayer;( P) a: y0 K! ~) k4 n! y
- }
" y+ Z" f- K! I; _4 Y7 t - }& {0 i& j, h: f0 }3 O, M# Y# h
- }
复制代码 |
|