|
|
# \$ Q; |# E, z& w5 _行,这个怎么样7 e3 Z. _5 B& B0 D0 Y: {" e
- package com.xhg78999.mtrfac.render;. X3 t: H. [' ]/ p
) I1 V5 P, B- E0 V# I7 G3 |- import com.mojang.blaze3d.vertex.PoseStack;# l' F: ]' s2 z- ^5 p4 s
- import com.mojang.blaze3d.vertex.VertexConsumer;* }' |3 I, V% r! ~8 g
- import net.minecraft.client.renderer.RenderType; {/ Z4 D" f! c, q2 j4 X& e
- import net.minecraft.resources.ResourceLocation;9 \) s, y0 t4 ]3 l
- 9 v5 x- W. E- n% T* E- r2 D6 b
- import java.util.*;
+ W+ l3 V! c# ^! k - 5 N5 l5 l! f: y L4 H2 R
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 T/ S1 `1 }1 ]* j n
- : |3 V2 ]0 `' [6 O6 a* \
- public class LineRender{
! E# t( G; n" t6 o* e - private final PoseStack pose;
; J0 Z" I( P$ R7 _ - private final MultiBufferSource source;
" x/ x+ ?- s, q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 u5 J% Y# | j0 o3 A; s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& e, H: l+ L9 n8 W, Q
7 r8 I R, f( f/ z4 A% c5 |$ y3 m- ( V9 Q- V& k# `6 P: m# B
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 [& m8 `# \# f- m9 H+ ]& z - if(x1 == x2 && y1 == y2 && z1 == z2){" l6 Q4 O0 F1 T) u( X P* F m
- return;4 N4 p2 ]) `/ A- u8 C
- }
3 j) t" \* A$ C! K% c - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){5 [( ]/ ^1 X# ?0 q2 p
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% a+ r! _2 _- Y0 e
- }
. A$ k- _! ]! A- `* x$ B$ R' ] - pose.pushPose();8 N+ Q q/ z9 q' @3 a
- final int newLight = convertLight(6);
9 y W% f& \# R } L+ x7 x7 g - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 X0 q5 p0 }! K - final float lineHeightSmall = (y2 - y1);
; A" M* w9 X% Y7 U - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- x, X4 D+ D7 u) K - pose.popPose();1 P0 `/ y6 y; n
- }
8 f7 [: {2 i* X% M7 N
w+ k+ B/ W }" T$ E( G) b5 H- private RenderType getLayers(String texture, int light) {
Y5 M y; K' V* Z% e - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 }: o& s, D$ Y9 b& t$ P9 G - }' c- U4 B% z9 A5 t
. ]# `1 L( _+ K u$ a4 R. w- private RenderType getLightTexture(ResourceLocation texture) {: W5 x, u. _( P: k/ M! B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 N9 M2 L( ]' j( U2 i0 ` - }
) [+ W& J+ P$ ^) p& g3 H* H% y - & x& `* R2 |+ I
- private RenderType getTexture(ResourceLocation texture) {, \8 D+ [; \1 g$ ]2 ^$ G7 t( o$ e
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, D9 Z9 ?- e) v6 k- A- F* ^ - }
* O9 x# M, f `; l( o) U$ D4 Q - , ?+ W% D9 y+ X
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, B( y6 v6 U, S, p: u - if (cache.containsKey(identifier)) {8 S$ ~1 I% N! S- C
- return cache.get(identifier);$ k1 R; {: Y8 d" j" g
- } else {
+ b! Q* o. w7 x5 `# p - final RenderType renderLayer = supplier.get();
( }4 T8 E. b$ f' p& Y - cache.put(identifier, renderLayer);
: C1 B. V, I: T2 G" B$ O S; c6 ? - return renderLayer;
" c/ x/ u3 p( D, `% y - }
, S5 o5 o) N8 |, W# G; K0 A - }
* D9 {8 y3 c9 r6 E) [6 l - }
复制代码 |
|