|
|
3 ~) Y4 R/ P, O; B/ ]3 H% V行,这个怎么样
, I2 S' k, _3 Z2 X! H$ P0 C9 ]- package com.xhg78999.mtrfac.render;
# X+ a6 L6 v) r4 _& t% R( b5 p
3 E, p, F2 F0 x" z- import com.mojang.blaze3d.vertex.PoseStack;5 g, |2 v+ b' I4 w5 l* g
- import com.mojang.blaze3d.vertex.VertexConsumer;5 G) e" ]& s7 V. {5 R
- import net.minecraft.client.renderer.RenderType;2 _& |0 F- s- J: P5 [
- import net.minecraft.resources.ResourceLocation;
r3 q" j* z/ j; |" Q3 r& I
9 Y7 Z8 L, m9 I* e4 c* {" \, \0 X- import java.util.*;1 ^5 \1 P) a3 Z8 F- m3 u
" d, O E' P! s7 T$ H/ v( M- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
l- T) t* Y0 P) f5 N& [2 a3 y3 w - / ?: s2 Z' }" I0 a6 v k8 Z/ `
- public class LineRender{5 l, [$ p, ]+ A2 O+ V+ U% b- s: K
- private final PoseStack pose;
# {& F5 I3 S1 }$ \+ ^" H - private final MultiBufferSource source;
; M g% B0 l* ^, R9 g7 r - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, b' c9 X1 v- {, V - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" @" k2 c! T: k- `6 H3 C; v - , D1 Y+ E1 \0 G, S( {" r
0 ^% l2 Q) h. B# }/ r- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 p# C2 E1 f' v3 T" F
- if(x1 == x2 && y1 == y2 && z1 == z2){% S4 O0 Z' }6 ]
- return;
3 s* ^" |5 R h0 {/ K - }
3 t' c- G6 t5 U/ U1 ]# G" t% U - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- Y$ T7 h, U2 o1 A/ ~* H - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, V( _: Y& I/ [) z" {0 U! x - }
+ _( J M* D9 a* N( |/ G+ t) P - pose.pushPose();
2 n! X. I$ r& [- e2 s6 q0 G - final int newLight = convertLight(6);
7 C, M5 Z7 I1 Q2 J, u1 l! i - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 C. g, l' B4 G6 S% l
- final float lineHeightSmall = (y2 - y1);' t6 y/ q* b" D/ @: {2 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 F% T5 D& P3 Z1 |" j' t+ q- e - pose.popPose();5 o. H- a1 [7 ]# z
- }
$ |, \$ k% \; E% k1 a/ f, L7 c2 G - / ]( I$ X& m% \7 R
- private RenderType getLayers(String texture, int light) {' _) U7 H* S. Q- T( G) P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 x6 r' d8 m. S( L1 i
- }
: A I/ g! q5 M- R1 B& R1 \+ W - % [- y' B. r) w) ~# W
- private RenderType getLightTexture(ResourceLocation texture) {
0 h! p, E0 I' j - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
[" d( a% |, k4 `. n - }1 ]& S( i+ R* i3 |" V1 X) F7 d! F$ w
7 u5 U ]# ]4 N ?4 f* r6 Y `0 `- private RenderType getTexture(ResourceLocation texture) {' T; Y; |. {1 X
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# j5 w1 W6 u# w - }- M- g) K3 v) ^( W0 @" ]6 J( D; S
7 Z8 K4 ?7 S S- [$ N- P- |+ @- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 ?1 {: \( W& r
- if (cache.containsKey(identifier)) {
$ v- A- _; H0 q# g. n& c- \ - return cache.get(identifier);
7 L, s2 @2 U& y7 I) z - } else {4 |6 }0 X6 C% m5 v
- final RenderType renderLayer = supplier.get();
; T* M ]1 L7 I8 T! o - cache.put(identifier, renderLayer);
& x3 O% ^+ z" p0 Q- H$ n - return renderLayer;, w U2 l S: ?3 r
- }$ P% M) k7 C1 h
- }" n- t7 t! ~4 e$ D8 n( E
- }
复制代码 |
|