|
|
5 Y" {% a7 J% k+ P- l. R
行,这个怎么样 M0 g& q& `2 s2 a
- package com.xhg78999.mtrfac.render;8 M. G0 h4 G8 b+ d2 t0 ^
8 `5 N6 q* Q( e6 t+ L2 H2 s" r- import com.mojang.blaze3d.vertex.PoseStack;
- u" a ?( Q; M% ~1 t - import com.mojang.blaze3d.vertex.VertexConsumer;& @) K8 D: g, ?1 i
- import net.minecraft.client.renderer.RenderType;
4 V1 Z# c/ c& X1 H# h1 A - import net.minecraft.resources.ResourceLocation;
+ z- y/ J) B3 \* e' y& c
3 N% n4 S9 |4 p+ w3 F/ M3 P4 r8 Z- import java.util.*;" }& h' b/ V1 \+ w2 i0 k& C, F% s
- - T$ c2 i r G/ \. X" X
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" _7 n. ~, H6 \: r/ m7 z" l2 e
! p9 y4 }$ G3 f7 `- public class LineRender{, N# P. A7 b! P7 j7 \% y0 M
- private final PoseStack pose;
( e {( x* `5 t0 E - private final MultiBufferSource source;
2 Y) `7 j' `. H( b/ T3 e - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 B- `2 x1 q8 c$ p) b
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
2 _' H& n0 Q2 `: r& ~+ L - 7 c2 G) J1 _: N3 _! J1 [
- 4 e: U- h* |6 I) T4 e( T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ y1 _+ \; j1 I. U T
- if(x1 == x2 && y1 == y2 && z1 == z2){
: L4 v% h0 E+ r$ J& w/ ? - return;
1 a3 M' K6 ?" w# _ - }
: K- f4 o0 w# e2 B. P - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 l5 {( X, M6 j/ u4 P1 K
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 q+ c0 V- y7 T6 `7 W( N - }
$ F& x2 \4 F; s - pose.pushPose();
1 Y! A& w+ [$ D - final int newLight = convertLight(6);! T. J. G- K0 i$ ^0 T$ }: g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) Z/ {0 n! X7 E0 X0 ^& J( [ - final float lineHeightSmall = (y2 - y1);0 U7 \) F2 c& M- z! H+ B/ J
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);" o+ X0 J8 s) ^) |4 S
- pose.popPose();
; d/ s, g; q: o# q$ L7 l - }
4 M3 j9 W9 M% M7 G K& r4 e! s - 5 q) ~4 l( V+ b" G$ `
- private RenderType getLayers(String texture, int light) {
- m8 u6 N: D, _0 D) L6 Z4 |) \ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! y+ u$ H* h& R/ Y$ t; x
- }
, s% \. {$ s* n, D7 v8 h - H Y' R2 W, u x0 X3 D8 G& V' w
- private RenderType getLightTexture(ResourceLocation texture) {
. V/ U1 z3 s+ H - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. u6 J t; j& D0 }# b# [# `* Q$ I
- }
) F. H6 J7 h3 d1 r; Y0 f - - b' @ [9 t, f& c" y0 ]/ F
- private RenderType getTexture(ResourceLocation texture) {
8 F$ s" Q# b* G" }) ^2 k - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ l1 [" X9 f7 N* U4 f - }3 K. A. p2 {# b- |, q: g$ d( O9 [
4 o& Z! x0 K7 D8 t- s+ v3 j/ n- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 _0 v2 \6 ]/ H0 W# Q2 M( q" {+ |5 z - if (cache.containsKey(identifier)) {
8 V8 W2 `+ T8 d% S( ] - return cache.get(identifier);6 N& W& ?+ R6 S8 H
- } else {9 Q% I1 S4 K" R2 u. ]
- final RenderType renderLayer = supplier.get();1 \/ }- K+ }; [# J5 c
- cache.put(identifier, renderLayer);
1 X- q& c6 P: c0 T( {1 G9 s- } - return renderLayer;3 O8 T j: p6 Z6 A8 {
- }
- l3 i4 I0 D6 \+ Z9 E - }3 m; f6 T B, I, @3 G, z
- }
复制代码 |
|