|
|
* i$ ~' o9 N% M: @( K行,这个怎么样/ s; n4 H+ |& O& o' Y7 S' v# _0 [2 O. ?
- package com.xhg78999.mtrfac.render;
" d& R5 u1 E s: n1 u - ( H& i4 K3 y% t) Y3 |
- import com.mojang.blaze3d.vertex.PoseStack;) P- r' l; w2 }! y' M
- import com.mojang.blaze3d.vertex.VertexConsumer;' N- C8 x) }6 H+ D
- import net.minecraft.client.renderer.RenderType;
9 _# w( U* ?# R. x: z - import net.minecraft.resources.ResourceLocation;
4 G6 F- z: F. l" s4 K5 H' E
* W- V. \# H$ N" C& f' e- n- g. B- import java.util.*;5 ^( M; t3 z; U7 S2 D* }
; L: Y% O8 _- P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 [; ~4 m) U, j
- _( x# D! v% J ~, _% H- public class LineRender{ S0 _3 W0 b1 ?5 U7 ?+ |* _
- private final PoseStack pose;
9 [, |2 Z# `' {' q# R; t - private final MultiBufferSource source;& f3 F8 f1 I% N9 O- B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% h! `* O3 n# A z! N0 ^ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();7 t4 M+ c1 _% o: {8 z+ P3 I/ S0 F0 W
4 q1 v% T3 l; p1 l$ x
: m7 ]9 C7 E1 m/ `, n- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% P/ E1 t& r! G, w
- if(x1 == x2 && y1 == y2 && z1 == z2){
$ W7 ?4 c. ?6 K6 i2 \ K7 S" U - return;
9 I7 n" Y8 s- {, [5 J - }2 V7 K$ I. N1 w% |. v# D5 z7 e
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" T) ~+ ^6 J! ? - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 [ C5 W5 M6 S: J( R
- }$ ] _$ G0 r' r/ _5 F* N
- pose.pushPose();% E- k) R) m! T o( p9 h8 O
- final int newLight = convertLight(6);
, T" `: Z+ {0 p4 w) N - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# ]3 M) c' s% G2 D( S% l7 _
- final float lineHeightSmall = (y2 - y1);
3 ]& j) q9 U! U; L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- \. K h- N5 y3 z
- pose.popPose();
. V, P$ V& q. X$ H7 o - }
0 c" [. D! Y. q+ J
2 c; {8 P( q% T- private RenderType getLayers(String texture, int light) {
+ G' Y1 y: x* {% b$ I, X2 V5 H! M - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, E, o8 T* \7 n+ h; _ - }) \9 h2 @3 V3 L
8 K! K- w! ?- x- private RenderType getLightTexture(ResourceLocation texture) {" k2 l# c" t, V# G2 W' r8 ]
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: n/ p; ?& A6 b - }6 D# c6 e7 f) [# ?. \
: ?( L0 c3 @% L5 I- private RenderType getTexture(ResourceLocation texture) {
S. N9 s/ R0 D7 g8 j - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' y/ d/ c) _0 C% a2 m - }, ?. \5 f, E) A
! W* c" I* A& v; p1 Q: `- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. {# x7 `- R4 l; D0 Y - if (cache.containsKey(identifier)) {$ V4 e. C4 I% o/ Y3 k) Y" b
- return cache.get(identifier);
3 n/ e* u+ @9 D3 p0 x - } else {
. X: C1 f x: _2 p, ]* O - final RenderType renderLayer = supplier.get();
4 d; R! I. V( |7 m. e2 j/ | - cache.put(identifier, renderLayer);- y+ m0 N' S7 W2 r( h
- return renderLayer;
Z+ v- Q- e: P - }( d. f0 R7 r% a- V2 T$ Y$ o m( l
- }" s, k3 F2 S D: m1 r# u% p
- }
复制代码 |
|