|
|
5 O2 Q. W1 O" j* K1 L% E行,这个怎么样
8 \2 O6 b5 B+ s9 s. q4 d- package com.xhg78999.mtrfac.render;
; U: Y0 r+ U) ~7 z5 Y5 U3 @( n
9 J0 F' K8 P) {+ Y: i) L! Z- import com.mojang.blaze3d.vertex.PoseStack;
* o; C/ z9 H( \: T. G2 h* C9 \' i, M - import com.mojang.blaze3d.vertex.VertexConsumer;
$ ]7 S( i* ]; m# h7 W5 r7 ]2 | - import net.minecraft.client.renderer.RenderType;: H) o- u& _* x; G+ ?* U* }* [+ f/ s) b
- import net.minecraft.resources.ResourceLocation;
j2 S- A! ?) U1 ?( |9 F+ \' ]
* Z8 F8 w! k" S, N( b- import java.util.*;# \$ d& h0 p2 H1 I' m; T( n
- {( N K" Y. c9 i7 E6 I- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( V! g: k% r& P! h1 M0 `% j8 }
- * A* Z h9 k7 M& q
- public class LineRender{
6 T% g4 D8 s4 p/ ^ - private final PoseStack pose;
3 N2 q4 |) w; O, z. V - private final MultiBufferSource source;
, V" H# ]* G3 J - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* v6 f$ R' s* S8 V# q" n
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% b, Y) T2 q$ ]1 ]' T! \
! l4 b. B3 B7 z( C- 2 M! ?: l. a$ V* A- `
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! b- W3 _( D# Y
- if(x1 == x2 && y1 == y2 && z1 == z2){2 d: g0 T! p Q
- return;
% J% k0 _6 c: p$ d/ V( ^; h - }- Z7 a! C; [; T0 x+ K7 R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){4 I Y- s( }+ R1 N7 r5 @
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 B2 a4 H4 e2 `8 q* f
- }/ T6 p' F6 C& X/ Y: R3 k! `9 c
- pose.pushPose();3 g, |6 {' _) V9 m3 L9 o. N& w
- final int newLight = convertLight(6);! ^ }# |* Z0 n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: }$ q( ?/ K: P; q1 f - final float lineHeightSmall = (y2 - y1);9 h. i3 R' T2 L2 s! s9 e5 R2 ^- j
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# \& J$ e4 _& A8 ~4 N
- pose.popPose();% y- d/ ?4 P9 O" F
- }
, t0 ?2 M( P! h3 \1 O" l8 l
, U) u# K: R2 b- private RenderType getLayers(String texture, int light) {
& ~9 u4 B7 V. P; q0 _7 n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# m E( L( d0 V" J' D - }) u/ {4 j) E5 R/ h
! u& c- {9 m5 V0 J; q- private RenderType getLightTexture(ResourceLocation texture) {
) q& L5 p/ Z! k6 [ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ h5 J# [0 {' }
- }# J; _! y- R1 G! b$ B2 @
- & x. z$ w, }* ?7 w" y9 L l' q
- private RenderType getTexture(ResourceLocation texture) {" |# [8 c3 J( ^" w
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 J! p5 D4 ^5 f3 ~2 s7 Q
- }$ G0 W+ L6 A# C# D9 V$ M5 l
/ v5 K; d% @" t/ R7 Q5 Y0 l0 X- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
9 @8 A4 ?9 a+ n g9 k, H7 J# \ - if (cache.containsKey(identifier)) {
' V+ |" }( U% M [, Z9 g: Y) o8 g - return cache.get(identifier);
! i0 H% p0 t: B* S$ j z' {! C - } else {& d$ W( T- Q; x3 w# h5 l
- final RenderType renderLayer = supplier.get();3 s. ?" | q$ ]" y9 B: T
- cache.put(identifier, renderLayer);& Z6 h, C( \' @
- return renderLayer;
7 `: ?6 |. d. r - }* K0 {; u! V0 h0 H0 l
- }! U5 O) E. A/ h3 J# E
- }
复制代码 |
|