|
|
0 c: s- `. K9 \) \. o6 ~) W行,这个怎么样
$ r2 P( W- P8 t3 S$ n2 P# k- package com.xhg78999.mtrfac.render;
- Z: W7 p2 i5 \: x2 u0 z/ J
, y4 {8 H2 a5 M$ p9 u1 ~8 V6 |- import com.mojang.blaze3d.vertex.PoseStack;
: ]3 D4 I( A' W. w' } - import com.mojang.blaze3d.vertex.VertexConsumer;3 I% f0 ~& N$ w4 y' e
- import net.minecraft.client.renderer.RenderType;
* [9 z% I0 h; j4 X4 F$ J, O- d - import net.minecraft.resources.ResourceLocation;
& z" w3 X9 S% v: { - 2 H+ x/ L8 x; T; Y( z& v
- import java.util.*;
1 ]. ], ~* x; @3 s3 r+ E2 B- }6 Z - % c7 U3 Y! p& k
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* D0 @, _( z/ w7 \; i) O
9 t& g; \, R2 N8 O6 X- public class LineRender{
H% o. j3 H1 F/ s6 {6 ~ - private final PoseStack pose;
: I+ A) o5 q3 f; P$ ^7 z - private final MultiBufferSource source;0 C' w- K. ]' z7 ~7 F
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% M& R$ p. _# B0 k0 W
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, e% U5 Z) C4 b, d5 O7 O/ A: d0 d4 ^
3 B% z _0 I# x! s# }0 N U- - T; f* V4 g/ p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ Q: l% b9 Y' o2 e7 j9 u6 f - if(x1 == x2 && y1 == y2 && z1 == z2){7 C0 F8 T1 Q: E: b) }3 @
- return;
& q1 t1 k% j" y N& B7 M - }
% } `6 b5 F9 O& K) d* e- T - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 f2 n0 ~* a, v, [" Y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 u" Z! i! v, U! U; N6 s( ] H$ M
- }$ ?7 ]/ F& }; {6 a4 I
- pose.pushPose();
0 i( ? d( ^9 d1 ? - final int newLight = convertLight(6);7 w9 X6 e9 d' S7 L1 y4 y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- X8 p8 |2 s' f6 a - final float lineHeightSmall = (y2 - y1);
& T( B+ G9 a: C& f1 Q! f E - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. V1 b/ }4 g. D: ` B - pose.popPose();+ \/ {1 d$ a# G
- }
2 M% M; a3 }2 e/ k
8 l/ N* F6 Z( k5 D+ U7 W$ \$ h- private RenderType getLayers(String texture, int light) {" G" W6 _* d" `+ N7 D8 T; Y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! b, h; R- v8 i - }. \1 _1 I' t6 x7 R* ?
- % ?2 f# L/ E, e5 H6 i
- private RenderType getLightTexture(ResourceLocation texture) {2 _; l8 L2 V7 r l$ U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; H5 u! U/ @7 ]% o$ a( W& U1 B" h" w5 V - }
" n$ t c, P% D6 Z i - ) \( c1 U/ L; P. K% ?2 t) X
- private RenderType getTexture(ResourceLocation texture) {* _, E$ r1 t- R" P2 E
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);. z W6 F# ~9 C0 y" {: ?
- }$ J( J2 Z9 ]" X E
- 1 y G: T4 I5 u! R2 p2 M! n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' j5 H9 f1 C1 G4 e' ], }
- if (cache.containsKey(identifier)) {& t; F" l4 s! S3 L* ~
- return cache.get(identifier);
. ^ O. K% S2 c+ E! d0 f - } else {8 B' ^& J" p5 M/ `& g3 v
- final RenderType renderLayer = supplier.get();
( z4 n$ Y' M4 e& E i d6 o, F- b - cache.put(identifier, renderLayer);3 i+ Y# |9 d9 ?- k. d# t2 C @7 G$ v
- return renderLayer;$ q# d, {5 O% ]
- }
- d, A: p3 W# h3 d' I$ V - }
( B3 S* ]5 I: ~: a# ~! k - }
复制代码 |
|