|
|
4 R0 B3 Q: @! \, U/ j行,这个怎么样* \- j4 G: w- x
- package com.xhg78999.mtrfac.render;
" ~0 o, P5 y0 P/ x; Z8 `9 w, ^ m - 7 I4 ^$ x# l5 C* V4 n% m7 `5 ]( W
- import com.mojang.blaze3d.vertex.PoseStack;) c$ I' \/ N, U8 N& W A
- import com.mojang.blaze3d.vertex.VertexConsumer;
+ ^+ L8 f& J, J; i& n - import net.minecraft.client.renderer.RenderType;0 W! c ~% f0 Q4 Q! }( E# z0 @
- import net.minecraft.resources.ResourceLocation;
2 X u$ O% L/ s6 Q0 S: L) Q - 5 y" s& }( M) t1 l
- import java.util.*;) n+ g, A$ j+ d# m- v" }: L# L
- ' M3 P/ p5 @+ _( M3 q. `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( C3 M; W/ d0 |$ \ e
$ Y; _- v% V# M8 @; m) Y% }- public class LineRender{
, b6 X+ U. m- A& p7 v- `& r - private final PoseStack pose;6 w" [% G1 B. F" N0 O3 t
- private final MultiBufferSource source;
5 e7 M0 q" O6 o3 A# Q) G - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 o1 N9 j% F! _. W T2 W - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 X3 r$ w8 P: M - - Z. r, l, D A$ v9 }% u
" p; P+ Y2 ~/ y) g$ F% [* @- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 l4 R! ~# ~4 f; w9 z
- if(x1 == x2 && y1 == y2 && z1 == z2){
, r2 Z/ D$ ~- b1 j - return; E# H3 ], _1 E8 |; \3 l( L' q
- }
9 o$ c3 ]- S) l! Z4 @3 g% z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 U6 L7 f! [" ^% g$ N
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ x+ h9 J7 i8 \2 O$ Q! }0 b6 o
- }
2 b( Y; w4 n6 M1 R - pose.pushPose();
% G) b* d1 N* a4 T& H - final int newLight = convertLight(6);
" u% Q& F* b8 r8 ?& _! n - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' X3 Y0 o" r3 Z; ?9 K - final float lineHeightSmall = (y2 - y1);" c1 }# Q/ O. Z. F
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 \2 `: w" Z5 B0 F+ L) L* \
- pose.popPose();4 ^- Y4 w% }7 z. ?4 d
- }+ J2 B% D# G( U* L* U
- " A0 U& `) }6 v9 R1 T$ X9 ^/ l
- private RenderType getLayers(String texture, int light) {8 d4 P7 \! U8 I3 t& X+ i
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% n1 d$ G* g. S8 L! B
- }
' h& z, b3 H. e - 3 h( H# o4 P( C9 k2 U
- private RenderType getLightTexture(ResourceLocation texture) { Q0 Y" `) _: I- }( }1 g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 T& M$ y+ S/ i8 [) z
- }0 [3 S$ `7 J8 H* Q: ~0 D: m; n: N
- ( I% ^6 H4 q8 q5 Z1 D, U6 ~9 x3 q
- private RenderType getTexture(ResourceLocation texture) {2 @; }! g0 Y& B( t# n$ M
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" [6 i8 p; @3 K) L5 X) d - }
4 G( m. N* C2 C - ( A/ V6 W% Z% F% g Y( _
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ I3 q( x: M1 z; x S- m) \$ | - if (cache.containsKey(identifier)) {
5 I8 {- X, e6 p! f - return cache.get(identifier);
: U" W" O& E7 r; X0 l - } else {
5 @7 |) C7 d3 l4 J4 v - final RenderType renderLayer = supplier.get();) q1 u" j( g: M( V" h6 G# g2 [( Q1 x4 o
- cache.put(identifier, renderLayer);3 y ~& C3 R5 H! K: W% C
- return renderLayer;. i- y# P' m: O# l6 q
- }3 y: x2 o/ x: d4 ]& {, Q
- }
9 @( x! S& a2 ^/ l9 t - }
复制代码 |
|