|
|
& ?4 Y7 ?5 O* P. d7 D' n/ y, r行,这个怎么样
' B) ~; o* F `) b6 y( q: Z# w/ Q- package com.xhg78999.mtrfac.render;
7 g" `( X' y* U. K" V8 d) }
% C+ H r# c7 W5 b. n- import com.mojang.blaze3d.vertex.PoseStack; \2 K) S5 T5 h3 v6 X
- import com.mojang.blaze3d.vertex.VertexConsumer;9 U3 Z8 d" y0 m
- import net.minecraft.client.renderer.RenderType;
- X2 i Q* q9 Y8 K) y& C - import net.minecraft.resources.ResourceLocation;) \3 `# \0 {" k* C+ E0 F N0 o! m
4 F; L, y6 D2 }& I, W; P/ @- import java.util.*;! u% g5 h+ u* A! f
% C, n1 b; S/ x! _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. z3 L( p3 k/ A! ]6 C - 7 Y3 h3 C6 r. g% N& K: d# J
- public class LineRender{& } h+ u) A/ k* e- A g
- private final PoseStack pose;1 `$ g% V `: p1 E! ?& e
- private final MultiBufferSource source;# {( t: ]# V0 s, r- H5 q; o
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- a' s8 b! H3 | - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& b6 t: p* ^) I P: ?6 _" M; Y1 E+ ^) @ - 8 T2 l8 ^, T& m7 U( v2 @
# t, d/ M* n. G& N- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; ^9 e* _' }9 M7 {' \ - if(x1 == x2 && y1 == y2 && z1 == z2){
. G5 y0 a4 w" B$ c - return;: F; s- V8 B/ M! g1 t7 N0 Z9 ?( _$ u
- }
* k8 ~$ p: t6 G M2 N# W$ K - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" B5 c8 _6 V+ y# }. y' D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) A' F3 ~) i. |3 Q2 Q
- }) }/ j6 R; H2 g( ?& X: n" d% i
- pose.pushPose();8 }1 D0 T# N' ?5 h. A
- final int newLight = convertLight(6);' ?9 V3 p: r5 E& g: D/ I7 \
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 u& t3 a0 c/ H' S - final float lineHeightSmall = (y2 - y1);
' Y5 ~- t2 t9 [# b7 K$ ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 u/ e* q7 E f2 k
- pose.popPose();
a, L* g! ^4 B0 |0 H+ V - }
! q: U6 ~7 y w+ }' T$ u Y7 i% { - - F8 w9 }) |8 E1 r O8 i* p
- private RenderType getLayers(String texture, int light) {
) q7 V& z* Y# T- c6 @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 ?- y& w! c, b5 K' s: m& A5 o) V
- }
9 O5 `2 |( j. p# ^) V6 K3 j. y. u% j1 D
! {7 q9 t- b8 D+ D% c8 d; S: H- private RenderType getLightTexture(ResourceLocation texture) {
Y0 _ b# r* c - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 B" n4 ~& P: k3 f$ v1 ? - }/ U* i# }; @! }
/ [% s# n- P! }- private RenderType getTexture(ResourceLocation texture) {
' L8 v. e1 f. a4 L4 u" f - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 S4 R6 u7 _" f' X' ? - }
$ V, R; Z. i+ ^ Z, _ - - p8 n! [0 T2 m, l" R: O
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) G0 E3 y& Q5 ]( s4 | [/ ~" Q5 U - if (cache.containsKey(identifier)) {
2 j7 B+ ~/ m5 W* x) \9 b- D5 g, t& ] H - return cache.get(identifier);
/ x7 o, L( b5 X. @! v* R3 e' P - } else {
+ c6 W0 u! r& \" H! F# S! U# R - final RenderType renderLayer = supplier.get();9 c, k3 {: K R; b' b9 U+ k
- cache.put(identifier, renderLayer);
/ t& v7 u3 d% g# e8 V9 r- r - return renderLayer;
k# U% q+ J) E s* L2 f - }, Y$ A' I3 ?$ i' @
- }6 L+ u7 R- P* e
- }
复制代码 |
|