|
|
+ Z& ~. U6 E% f( }+ j" o
行,这个怎么样
6 `1 o# ~7 T( {# Z. b: ]/ j. A- package com.xhg78999.mtrfac.render;4 X+ m0 X$ ^# ?' [
- , b7 [, F7 _; g4 y" `
- import com.mojang.blaze3d.vertex.PoseStack;
# [: m% J v, G' C5 k; R - import com.mojang.blaze3d.vertex.VertexConsumer;' c0 q! z1 s) R: O! @
- import net.minecraft.client.renderer.RenderType; a }9 o. [! q) b
- import net.minecraft.resources.ResourceLocation;
& a1 M; F+ x1 w9 x3 z
3 m+ u/ l1 I+ P, Y; F- import java.util.*;" H0 y3 Z" u+ k4 a1 P
- " W$ w4 f- t3 w0 {, }2 V
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. B2 S1 Y1 s' A# t4 h' v5 V0 e
- . ^! I% J& G" o8 K
- public class LineRender{
- {" D' P4 L9 Y7 D2 j - private final PoseStack pose;) M2 ^4 {2 V ?5 [
- private final MultiBufferSource source;
$ z) s& G& N6 f" {& O0 I$ j - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) o+ G I6 ?6 m; \1 e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ K" u+ T9 U8 J! D" ]% W1 ?) c. x4 A) y
- * \" |1 w( F, [$ E* [
- ( f8 Z: `. ]8 P+ D2 ~
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! _8 o; `( m3 ^4 Y5 M
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 T3 R8 s& H* S3 h" U - return;
# v1 r5 M# H! n( [ - }0 ?; B2 k0 z1 w! G8 ~0 d; F
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% ]- B: s5 p0 O9 Q( B
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. v' g5 v8 ^' O# V - }- Z8 S. Q, O3 f6 t; j9 ^
- pose.pushPose();
, e: _7 o5 B* ~" z' p/ w- w, b - final int newLight = convertLight(6);
" O8 `9 J! z8 M: D. S+ }9 C$ S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); Q2 X3 X/ c! v9 Y) y$ u& t" U) A0 I0 ^( p
- final float lineHeightSmall = (y2 - y1);
/ P5 w, c# r5 _2 w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 K3 s% e+ ]7 F9 Z7 V
- pose.popPose();) d$ F) E w0 |$ o: S, L% u
- }
! j3 c7 i- R$ G+ x - . |) y& p4 _: s5 O* ~/ T/ _
- private RenderType getLayers(String texture, int light) {/ f; a M& _. T. P" @7 b1 f
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));( j# |9 t+ V% k( M$ H* N3 B5 C
- } _- {& s# [9 X: C
- - w' J+ I) Y2 h' v
- private RenderType getLightTexture(ResourceLocation texture) {6 `6 P2 z9 j/ t3 i% `
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 s' G( M" T5 Y& ] - }
2 R. O% u( V# \4 M$ g - 8 K$ C, z4 s! e
- private RenderType getTexture(ResourceLocation texture) {
2 D" q+ O! i1 O/ f/ b7 a - return this.cache(texture, () -> entityCutout(texture), CACHE_B);' d& m5 i2 \: Y9 d. c+ }0 l
- }
( Q: A6 n4 M& c& a7 Q2 w# q% v - ` [5 T) w: K3 L' b
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 ^0 B4 }$ W+ M6 W! Z
- if (cache.containsKey(identifier)) {# `6 C' I" O7 k+ |
- return cache.get(identifier);
) O) D/ J7 V/ d. F% \* x - } else {) m/ d: m B. V2 b" R% j7 l. A
- final RenderType renderLayer = supplier.get();* `! O1 ]9 `8 }' m( l
- cache.put(identifier, renderLayer);
: z7 _& _0 t0 L8 |3 O# u; t( a - return renderLayer;! q' u/ d" X7 e2 ^ L/ _9 @4 ]: x
- }
5 x4 [+ N) Y6 i- H8 @' n - }. {' k. j$ F9 V M* m' M. x% Q
- }
复制代码 |
|