|
|
# q! d" X+ H9 v, f+ s
行,这个怎么样8 i1 C4 p5 T$ [8 O
- package com.xhg78999.mtrfac.render;
7 b f( {! \! w5 ]9 i; J; _' V
} q6 |4 W. a- import com.mojang.blaze3d.vertex.PoseStack;
) ?/ k; j2 t% e% B7 M- j' A) e" U - import com.mojang.blaze3d.vertex.VertexConsumer;
& K' ]6 }; }4 L - import net.minecraft.client.renderer.RenderType;
5 ]# n+ c& Y6 A) P: o+ \ - import net.minecraft.resources.ResourceLocation;1 t2 q8 H6 B, b' f
- * K' M+ v+ O0 }! c9 u% r
- import java.util.*;
- I, a5 L5 A+ ]. L
* C( f j8 x6 B' O9 u T- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 U/ s, _ X9 L5 a: S. T7 X
& [, ^ ]5 C% h7 z- public class LineRender{% k* ?( e6 ^# M( T
- private final PoseStack pose;
/ F2 c j6 g2 }" R9 ?. E - private final MultiBufferSource source;/ Y7 \' j* g' j& V3 d% s* M( y5 G3 B
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 _3 u' D1 P' X" J - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& E9 l7 R( O1 U& g% v2 U - 7 f+ c. ]; k$ H% e
- / T, Y! D& k& p) @4 e& b- B
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, n7 y6 y% [, w6 v( J4 p - if(x1 == x2 && y1 == y2 && z1 == z2){
8 ]$ z( z% A' I0 w. y - return;: W) ]6 a0 w' V. m
- }* W9 r4 O4 ~" @- D9 D
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 \6 ]: L# s" `4 q7 S' t - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 G0 q. m6 U: q) H - }* i3 m7 X1 ~3 A# C+ H
- pose.pushPose();
# f9 y$ O9 {* Y) J8 | - final int newLight = convertLight(6);
* Y6 U: ?8 f; h0 X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ h/ L4 L7 s. V3 d% N
- final float lineHeightSmall = (y2 - y1);; z: g1 h; h2 D: T$ c n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; ]& e- g0 d6 Y- D+ g- K2 ^/ `6 _: k - pose.popPose();
' b7 Z8 M4 \! i4 @' ^9 G - }9 e2 E" h& }+ f0 H- c: }1 I' X
- 7 O8 ?' ~9 O) I& I, M+ w0 h: i
- private RenderType getLayers(String texture, int light) {
# u& F1 ^- u; }+ [4 l8 w* Y Q9 ?% V - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, Q9 j8 X: A6 ? N" t - }: o Q v2 h# x; `" o9 F' ?/ ^9 _
- : V5 r) {# |# `# w9 T; ~* i
- private RenderType getLightTexture(ResourceLocation texture) {
+ F$ R- M' u! D - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 b% k% Y: [% V9 y
- }
) Z, }3 N5 @' j+ C - + u J+ I5 R# s$ @; R
- private RenderType getTexture(ResourceLocation texture) {$ q1 z9 t x" C( T$ A7 u; F0 @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& Q0 x! i5 A! ]6 p - }
/ F) b3 a' r: U J0 |2 @4 N: n
/ Z- h1 ]( z9 J- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 x2 ]# ~# a; w o/ `" u+ |: p% | - if (cache.containsKey(identifier)) {3 v; U" ^* |) g/ V6 O8 Y8 W4 y
- return cache.get(identifier);
% s6 g- @, w8 E) f3 D& g; W - } else {% U' ^' p- L2 X% K& T& ~
- final RenderType renderLayer = supplier.get();/ H0 c7 I1 I" M1 p9 I
- cache.put(identifier, renderLayer);
) y6 }5 U$ U2 L: p! W' Q; w - return renderLayer;+ _3 w5 B% ^. g1 {) U
- }
. q7 \8 ]* R2 r2 K9 ] - }0 Q$ ~2 r+ E5 x) }0 S% }
- }
复制代码 |
|