|
|
5 I- {1 F& c9 _; W
行,这个怎么样
+ @0 h+ n7 V; V1 g9 G4 c- package com.xhg78999.mtrfac.render; y! u0 B1 P2 n! l$ S& O4 n
# Y1 I4 J9 C$ V; O( |! {. E- import com.mojang.blaze3d.vertex.PoseStack;& x0 y. A+ [+ [3 Z5 L' {8 Y4 @
- import com.mojang.blaze3d.vertex.VertexConsumer;
, a1 _. Q" {+ v9 w( P - import net.minecraft.client.renderer.RenderType;
/ l5 w# F$ M7 N3 F: q: F3 S - import net.minecraft.resources.ResourceLocation;2 M. I& }' j, I* p; i' l; H
- ! i0 W- g& x) q \! x
- import java.util.*;
; q* Z+ B( g9 f3 [" W. a
% f8 a' k) ]7 W' p \8 R' s9 K8 x- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 b8 u1 n+ E' J' T' p% [' P7 N! f) c
& @9 }5 P) p9 w6 x w3 A0 S6 I- public class LineRender{. C) z' _5 E. Y) ^: A) m
- private final PoseStack pose;
& ?: `6 K! i. X+ O* o - private final MultiBufferSource source;
, K" [& L9 r/ f s- Z& p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();4 x* i4 v, W7 q* s( V! ~% a3 W: L
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* K9 `- Q! _) n& H - 4 }' C) B0 F/ g& @# t* @" K5 H1 N6 u
. d$ F+ s* j1 E! P. L9 r# t- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
t, S: g7 O7 o; h9 J- ` - if(x1 == x2 && y1 == y2 && z1 == z2){2 q; q8 l! _/ k8 h W8 d( [
- return;- r G/ w. i2 @2 C7 W6 \3 H/ L. _1 m
- }! x& B$ U: y% {! s4 \- A
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ E- l% E, v* n; s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
+ k! _/ b1 [1 v$ g, Y% u - }
- R) Z/ ~, y. K4 \' V1 B - pose.pushPose();* r: P Q1 R& N. }, {; P5 @+ P
- final int newLight = convertLight(6);7 M8 x6 B0 E. n! W# D" J
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- n% m9 W& s5 N' _0 ^) } - final float lineHeightSmall = (y2 - y1);
+ a1 K! f5 A. P3 D( B/ R/ U) s2 E - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* o& R; T4 d7 O4 B
- pose.popPose();" s; G: L& d9 h5 f* V) ~# {
- }7 l ]4 I5 Z0 H, v3 J2 b
5 v4 K& `* ?5 ~/ }7 r2 Q- private RenderType getLayers(String texture, int light) {
$ j: ~- z% L2 e - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( ^: X" Z6 A# v/ v: N - }
2 Y: F/ z4 V$ k, Q0 W$ q - * u' M, e) u# c: q1 a# i
- private RenderType getLightTexture(ResourceLocation texture) {
2 j# B z8 w1 N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& v1 `* ~( E& }9 w: i - }
9 [& j( P2 p# F7 v, g1 g: k - $ e: v& v( ~/ L- C5 F
- private RenderType getTexture(ResourceLocation texture) {
# q b5 D0 j% u+ o2 S0 \( E: E1 C - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, a- u1 r# @8 _: ~, W% a- t- b - }
' u# z% S% n. {# M2 h
6 J( H. W/ I0 m! v) i: j1 R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 {% A! f+ I) U+ O) r - if (cache.containsKey(identifier)) {' h M" ]" x5 w2 i8 c/ [* K
- return cache.get(identifier);
7 ? C) y: m: R% K5 `+ r - } else {% y: R$ f; ?( b" Q9 r0 L2 ?, [2 ]
- final RenderType renderLayer = supplier.get();
; d% [, W' i" U: } - cache.put(identifier, renderLayer);
x+ v) }. u6 W3 ? - return renderLayer;1 c* u6 U$ p# e5 Y2 p
- }
% n0 ?5 A; x) X - }
8 h: _6 K- M+ u - }
复制代码 |
|