|
|
7 O. _, C$ w9 \* K5 B, @行,这个怎么样
$ K. X! u- S' I: p- package com.xhg78999.mtrfac.render;
2 r9 T& p( ~% s W' m/ R - - D& b. y7 V% @
- import com.mojang.blaze3d.vertex.PoseStack;7 j* A/ w' i A9 F6 l
- import com.mojang.blaze3d.vertex.VertexConsumer;
9 O& M. c/ x: | - import net.minecraft.client.renderer.RenderType;
6 u, r; _+ H7 t7 q, _6 B+ r2 |+ O - import net.minecraft.resources.ResourceLocation;
/ }1 _& @5 H3 j1 f
6 L# v9 L: z/ [8 o- S f- import java.util.*;
' q3 D/ q4 o8 i+ A9 v8 F/ T) z: @4 M
- e" f7 u6 n" z5 u2 t7 _% o. B+ V- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. i3 C- \( h) L) q/ A
- $ G/ w: W/ D: O" o, ~, @8 [+ T; W4 ]
- public class LineRender{
0 H/ |1 ~8 P9 l8 A) f- M: c - private final PoseStack pose;
' s# r/ F8 A: @0 l5 O - private final MultiBufferSource source;$ d9 `( q. x0 {/ T* y% X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" t) M, G7 I) j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" e6 f: e8 O0 b4 @" M3 o3 C
- + \, M& h5 k* [. `. e+ E0 B
1 x+ J: z0 a! e/ ? ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){" B' J2 c' @6 r! f! F
- if(x1 == x2 && y1 == y2 && z1 == z2){" b; m7 Q' k+ i% u+ N" h, k) B
- return;- N% l# K! H+ z! [; R
- }
1 b4 m5 s5 G2 j9 ^0 L0 B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ j5 Y' N1 {& X& G
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, L& u/ s+ m6 d7 V - }
0 V+ j# n5 S( ?4 h4 A' ~: D9 m+ l - pose.pushPose();0 u& S2 \8 \" K
- final int newLight = convertLight(6);$ c$ d: J Q4 z( ~" k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 b+ `- ]* W6 E3 L1 p# q; n3 ~ - final float lineHeightSmall = (y2 - y1);
! b6 G T$ H, X5 f5 F4 u - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 v* _% @$ R) p' Z
- pose.popPose();
5 n+ ]& {. H8 E [ - }
( h5 q% s! M( g7 e* ^5 ~) g
: M6 ^% ^! H8 p8 ~& ?( E; g* Z- private RenderType getLayers(String texture, int light) {
1 V; z0 e' a) n3 E% O! z4 L - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! P9 P# A; {3 \' e- o9 p% J5 T - }
" e9 d6 Y: T1 ?& E% `) P8 e
! X! ?9 h/ ~4 i- E- private RenderType getLightTexture(ResourceLocation texture) { ~( _$ ]/ o, M
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 f$ s6 M! s- h9 H2 F9 H; `
- }# I: B+ {6 S s) D( ]( f
" S# P8 v* J; u- private RenderType getTexture(ResourceLocation texture) {( Y( g3 v0 k [+ G$ d) |
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* O/ P; Y4 T7 ]! S - } q! |$ R) M4 \9 M' q
- + o) v5 ~+ i, r- G* ?
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# X' `$ ?+ f1 a7 y
- if (cache.containsKey(identifier)) {# c; x/ R. A- y
- return cache.get(identifier);, j7 M: o, @; n* _- ^
- } else {" M; |' G/ I; o6 L
- final RenderType renderLayer = supplier.get();. h8 H& E, \+ o& J" z* }
- cache.put(identifier, renderLayer);* J. z+ Q4 x" Y' M
- return renderLayer;
& b) a* Q' V* X1 j" Z% {3 t - }1 d+ n& W( `) V2 H: X, P$ K9 K% O5 \
- }; F3 M& H4 q6 [8 m5 t, ]
- }
复制代码 |
|