|
|
! U% @. _& f1 Y+ C( B* p
行,这个怎么样0 q6 i- x* H+ p _, k1 T4 ]
- package com.xhg78999.mtrfac.render;- K5 H7 `6 [2 ~& d) M
- ! c0 p; |& t8 e( Q! S, t: ^7 V
- import com.mojang.blaze3d.vertex.PoseStack;3 i& G+ J! ?8 R1 L7 @6 |( p5 |# a
- import com.mojang.blaze3d.vertex.VertexConsumer;: e) F; ~' C7 \* l# M
- import net.minecraft.client.renderer.RenderType;
% z& _( Q- D, G5 ?8 S - import net.minecraft.resources.ResourceLocation;+ M. V! ?+ J* N* D
8 Q% ~: n; }/ X7 Z5 r- import java.util.*;
6 W! T6 Y/ I1 q! ~5 d - ( E6 C9 @2 b& J- f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ q% K8 N x+ }+ K% \7 V' h
8 Z7 R: z) v9 O7 M- public class LineRender{: G) R0 S7 R! `9 [! h# l: {
- private final PoseStack pose;3 ^& `8 e7 m0 a" t0 ~% q
- private final MultiBufferSource source;2 X$ Z: y4 g0 u! t6 ^8 _# x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 O. O% d' Y2 s k# f* u4 g- `' o - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 F$ `2 K' M- F2 z9 c% [
; q, o: r+ w: d" X' {* f( |' w
8 n3 i- d" y4 N, w- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){) ^8 m" @* O, _3 i* d
- if(x1 == x2 && y1 == y2 && z1 == z2){( A9 X0 z# M/ z" [
- return;
2 [, E6 u! a, _8 k4 M6 w - } Y) a9 s, B t/ n2 R: ~6 W7 z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 K# u3 z! u) O
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- M6 N/ I5 E" n% _" V0 X3 ~ - }# B, v9 m" f- \$ P# r% a7 H ^9 M
- pose.pushPose();
( ?5 G. X# x8 l% v8 L0 ] - final int newLight = convertLight(6);
2 q% j9 U- o0 q5 ~. u) O - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ l* t( \6 p6 d
- final float lineHeightSmall = (y2 - y1);/ ]& }. @1 V. v g
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);" H# V8 y$ i. M i- g
- pose.popPose();
; n- O' @: v$ N- U( e0 O! W4 D. J" j - }& [/ i+ j0 O! D, ~! D, X
2 q' a3 G2 M, G1 [# o7 g# P/ _- u* l- private RenderType getLayers(String texture, int light) {
5 ~! q$ Z3 E! A/ B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 X$ r" u* e5 ~# K) @
- }
% {4 c6 y0 _* K K, g9 C
9 H3 S8 D7 p! c! j2 |! h: o: o- private RenderType getLightTexture(ResourceLocation texture) {
; t3 B% [$ l0 [. Y' m% C - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ ]7 N8 T9 X) P1 F - }8 ?# [1 y6 i; z& q1 ` K
# G& @* _: \3 W& P W7 B$ E+ e- private RenderType getTexture(ResourceLocation texture) {6 k; W, D8 `: z- t- F4 }8 @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, A* O6 K+ K9 y4 u6 d - }
9 v# P5 v' V( D% G7 c
- s- T6 j( v+ e9 w' w. p# o% ~3 D5 s- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" R/ g# z0 k" v
- if (cache.containsKey(identifier)) {
, ]& N9 U7 }9 w - return cache.get(identifier);
9 ]# t1 L3 }( U# W# | - } else {" P5 B! a( n6 m$ h8 V
- final RenderType renderLayer = supplier.get();
( L; g n2 P9 ^ k2 q, N! X/ o - cache.put(identifier, renderLayer);
' M1 C8 l: T9 r' X @ p4 V9 o! R# ? - return renderLayer;
% }1 y0 r" D3 y! Z/ ? p8 X! V1 h0 d - }) N0 u- d9 H. C4 K
- }
! `1 e \ t) C h - }
复制代码 |
|