|
|
$ z: C0 U2 P1 {0 R' X5 r" m1 Z1 O
行,这个怎么样5 Q1 M" K; {# t* c3 J, c# v
- package com.xhg78999.mtrfac.render;
- P& O% d+ y, ]' o6 g
, a% a+ {9 I; S4 ~# g& Q- import com.mojang.blaze3d.vertex.PoseStack;8 T6 w- }, {$ r5 n- I& B
- import com.mojang.blaze3d.vertex.VertexConsumer;
! M7 h1 A6 { |$ V& d6 d4 J x - import net.minecraft.client.renderer.RenderType;
R1 w4 U( D+ S8 \% g - import net.minecraft.resources.ResourceLocation;9 \3 E1 [) b5 ?) C+ T
- * o# h* `: r8 g' R8 |8 m. C- J
- import java.util.*;
+ F. `5 k% `* E6 n" T+ c7 `1 l - 5 T% Y% N6 q5 o* w
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 k6 ]9 y1 e3 T6 |
3 l6 h! y8 w$ A7 F- public class LineRender{/ P+ D4 }6 |- t1 y5 _
- private final PoseStack pose;: O" D7 d/ }* C9 }3 h
- private final MultiBufferSource source;
1 D! s; O7 k/ e/ w - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 [+ P# ~8 r% P - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
7 v+ z& P0 `4 ~ - . c1 g0 [, a3 q) j) P: e5 k' \
- & d* e1 c6 f& n2 R2 `
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. ?& X1 u, `( h
- if(x1 == x2 && y1 == y2 && z1 == z2){: K7 Q8 [- s3 E. _5 r
- return;7 l6 M0 A8 U" t) m9 b# W! E V
- }3 |$ i S+ p5 g+ n$ f1 }
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# ~1 w0 ^' O8 t. I h' G, F7 [8 P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 Y! Y: X5 G- J7 I. e
- }
& `6 w" y7 P9 L. s6 q - pose.pushPose();
+ P8 E/ D5 d9 f/ A0 }* F' X Z - final int newLight = convertLight(6);4 x2 h9 Q" w; H, Q$ _! b9 {+ V4 |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; s: V1 j8 T0 S1 }/ _8 G: b6 K - final float lineHeightSmall = (y2 - y1);
' k) ^' a1 e4 ?% X - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ b$ i3 t3 Q7 P7 `; \/ n - pose.popPose();2 ]9 z! R( L7 J' w5 E7 r
- }
3 R. o% P4 S% D) ~* C - . g9 O- S# @' ?
- private RenderType getLayers(String texture, int light) {% g0 n9 _! h$ `- u8 m8 i4 ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& H O! C) p. W; O3 Z& w! l$ R
- }5 C* [$ w! P! w& d( l; X1 k
- w- t" f& Z# D1 [; f. C0 K* C- private RenderType getLightTexture(ResourceLocation texture) {
' x; W6 T, Q+ ^3 z& F- r - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) g/ M# g" ?+ `6 m$ j1 p( l - }
9 u" d0 J% L$ x, n! B4 I9 ` - \1 Y& p' l+ L8 [0 x
- private RenderType getTexture(ResourceLocation texture) {/ H) a+ }7 k: N1 a8 @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 A6 L0 H) I4 P - }3 z6 c* L) X, {: p
- + X- ]4 A+ Y& T7 K. Q1 m
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& x7 }6 F" V2 S a - if (cache.containsKey(identifier)) {* k6 }1 z1 B- S* b2 `
- return cache.get(identifier);7 f' g6 z# z) @+ [
- } else {+ B1 m; N$ G4 W/ n" z
- final RenderType renderLayer = supplier.get();0 J+ y! Q% u$ |* r, P8 D7 F
- cache.put(identifier, renderLayer);& u0 s, \+ Y* ]3 B' h2 s
- return renderLayer;
7 n! g& Q' O) g6 K- v% |5 } - }2 C: D( h: f4 z" ?. M: O4 `3 s) {
- }
( ?2 k0 l* s& ~. h - }
复制代码 |
|