|
|
7 M' M' K# }4 _, K/ q. Z行,这个怎么样5 y2 w2 I6 K0 Q2 i+ K
- package com.xhg78999.mtrfac.render;( |* l+ O7 B" i" o+ _/ P( S: E7 M
- 5 w' W5 y3 L0 S+ k h/ I
- import com.mojang.blaze3d.vertex.PoseStack; Z" j; ]$ d4 F
- import com.mojang.blaze3d.vertex.VertexConsumer;! a3 _( a" I r) x" @% Z; R
- import net.minecraft.client.renderer.RenderType;9 @- b9 s4 p! G
- import net.minecraft.resources.ResourceLocation;
+ U& \! } F2 i' f" Y- o! \( q$ t2 R7 D
% [. i- ]- F' n, R; t- import java.util.*;8 A( E y9 F- i0 }8 N1 S$ `; c# {1 H
- - [. k H& ^& A
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ j5 X; x3 Y. h. F s/ Z3 { - * e* |/ q' ^: {2 B% |3 B
- public class LineRender{
" t: F+ v" z7 x1 a" h1 d- Q: G8 u - private final PoseStack pose;" `/ \3 h9 s3 K% V6 ] W
- private final MultiBufferSource source;; x) }7 v/ G% I1 h: A! B G2 ]
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 P" N4 X% B/ j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& B, R/ r2 v' I* a5 U( B, o6 j: \! W
/ W+ u& n3 I# ^! L* I- * n' C" W$ |; ~& T. _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& {# p) {" V2 F& V - if(x1 == x2 && y1 == y2 && z1 == z2){
0 M/ E/ k4 R" L& x - return;
' m( g) h8 `8 o1 o5 B- ~. W - }
6 x: ]7 [* W+ i/ L& d2 ^6 A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& k! P' J, y M: P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 ~! ?8 l# ^4 l! p! K - }
$ E; R, W7 Y3 E1 i- v2 e - pose.pushPose();7 A6 R9 \. h6 R" X8 Y
- final int newLight = convertLight(6);" i4 m1 U/ w6 c3 x8 [# H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 w% b2 z6 I" F) S0 c6 C4 N
- final float lineHeightSmall = (y2 - y1);) N" L; g4 K% T5 L* ]' O u
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 W1 |) s: y! j- W
- pose.popPose();
* v; q, z$ a! Q& H) G4 o v - }
; d i% U+ [) [0 B0 Y - $ N+ X- G+ o0 k" b% c( F; q
- private RenderType getLayers(String texture, int light) {
! d. v6 ?5 q$ I3 u - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% u. H: M; a6 R+ w
- } n" {( Y: i& W
- 1 ^- A; {7 a5 F% f4 R7 h) k
- private RenderType getLightTexture(ResourceLocation texture) {
$ R& C: [) ]+ R; X - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! R9 O# c* G( R - }, i: _. C. x" D
- # \2 j$ Q2 w8 X
- private RenderType getTexture(ResourceLocation texture) {
; f( K0 Z5 U3 J" J: ~8 ^; U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 |9 W. W6 L) G$ y3 p8 t - }
; D/ |: o. {4 }4 _8 B% ~$ G; m, V& n - 2 O4 A. V6 T# s s1 v( U
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 {: w4 P" y9 q2 d# b
- if (cache.containsKey(identifier)) {* S2 A: W( h7 ?2 u$ r% l$ P
- return cache.get(identifier);% \) V! r* r8 ]3 f' c& W" J" Y
- } else {
; f5 v: Y5 q' m6 g - final RenderType renderLayer = supplier.get();8 U0 f' ?) m* m$ w6 ~
- cache.put(identifier, renderLayer);
) l: J0 f( G* b: G1 F - return renderLayer;
/ B8 P, [8 j( c& b) @& J4 N$ p - }; E% j5 O, o+ \' [: ~
- }
2 P# c! C9 }% b - }
复制代码 |
|