|
|
. ~' j- `3 C% G6 L: n
行,这个怎么样! ^" ~5 J$ u, V. r( G3 e( l1 z
- package com.xhg78999.mtrfac.render;
1 \1 J( l8 m% S
% |/ a* f+ I3 C2 A, e- import com.mojang.blaze3d.vertex.PoseStack;0 b! |/ u. s5 T' u
- import com.mojang.blaze3d.vertex.VertexConsumer;
: X" x7 \9 k: o5 J# {* i% Y6 Z - import net.minecraft.client.renderer.RenderType;& {) K, F9 [! J7 J
- import net.minecraft.resources.ResourceLocation;
# Y: o8 I, B2 l - 1 s" {6 s# |6 @( b. U
- import java.util.*;- {7 | a7 X& `
- ( o1 ^; v5 O: y8 @* S7 I1 U6 b
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' x0 X; d. {8 L' w" m
& |7 N6 }- l; ~6 B% [' ^ l& H- public class LineRender{
+ \' ~, _8 q4 j& | }. C2 c - private final PoseStack pose; ?, X5 B2 j6 \0 f
- private final MultiBufferSource source;8 P& L" {+ R# L+ B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();. z' ]# N0 _: e6 l1 i2 K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 u. j) H# G0 S
; J0 @7 @, C0 F% @4 I, Y
. {) ~1 P6 A/ |- q+ k7 j- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- O; ]9 d9 L& A1 n | - if(x1 == x2 && y1 == y2 && z1 == z2){$ X5 w, V8 y+ Z' S# d% B3 {
- return;9 _# L0 ]% f T
- }
$ }6 K4 ?% J& ]5 h3 X0 t - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. T' Q* Q& V: P* O6 V* `+ x2 S% ~5 K
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% z1 l* r. B( Q, Z0 | - }- L! z3 y! I" o) C M9 {5 Q. }% c$ _
- pose.pushPose();6 R4 D. \: O! X" F4 G! \
- final int newLight = convertLight(6);
# o* R" [) {' _! d% h v - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
& Y/ U; d- E1 n3 E: V - final float lineHeightSmall = (y2 - y1);
' f( \1 k7 L' I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) m: {& j, E! H9 M - pose.popPose();! w+ z* ^6 U( `" ^0 z
- }% _' p' w3 |1 X
/ o' F6 j0 F$ u! o- M" K& X- private RenderType getLayers(String texture, int light) {1 h; _, p3 r4 S8 x Q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; m& }5 N0 Z5 o3 d - }
' }1 [9 o+ B8 c: R
6 @* b2 p' E) T9 F0 S( f- private RenderType getLightTexture(ResourceLocation texture) {
; H* Q: \6 ]2 J0 K - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! M7 R7 k2 C- B( s3 N, J3 `- ^ - }- C7 S! W+ I, F# l" k
- $ @5 W% L" D4 Q7 f
- private RenderType getTexture(ResourceLocation texture) {' d# W% C' D: q; R
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 P! b% |2 j+ i. e9 V* i3 v1 ?& J
- }
: _* _9 B6 V1 S6 o8 {4 C1 d - : k- L$ K& R' }: Y* k& W8 t; P
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ b' R# \* |; c+ x2 [* {% P - if (cache.containsKey(identifier)) {
( p9 U) D# u! C7 n- ]5 G - return cache.get(identifier);
2 r. [# e& |) p# Y% K - } else {
' L5 ~ A. H, X- u+ Q0 U- Z - final RenderType renderLayer = supplier.get();
{% h2 y, u2 ~' `2 _& `, u - cache.put(identifier, renderLayer);0 d9 }/ \, C8 p4 m8 P1 z
- return renderLayer;
3 e5 a; b% e- ~ - }
R' d7 q$ h& k( F7 c' x, g; r" L - } |* g1 G$ U* M+ }. Q
- }
复制代码 |
|