|
|
r$ `, z4 D: T3 k/ d$ V/ u5 d行,这个怎么样$ i7 Y; [* M$ r& h/ J; y, |
- package com.xhg78999.mtrfac.render;
2 p+ L. E* R7 k, t7 f& J2 X! z
0 g/ i6 P2 c8 p( s4 f- import com.mojang.blaze3d.vertex.PoseStack;
( N6 w+ O1 C* {+ P: r1 V - import com.mojang.blaze3d.vertex.VertexConsumer;
/ P/ S @3 w+ Y - import net.minecraft.client.renderer.RenderType;
6 R* `: P6 o- } - import net.minecraft.resources.ResourceLocation;
$ G$ w1 E& A* A; S( U# j5 o- T8 B
8 L0 N# j; J _9 B8 S- import java.util.*;
3 f% d/ n( u7 A1 x8 o9 V - + P8 X3 ?( K+ H
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! s* Y7 Q% K/ }% A; e - $ Q, b! y4 Z5 ~+ {/ X
- public class LineRender{4 R/ }9 i L3 y9 x# C# i
- private final PoseStack pose;
" s6 ~- j7 X& x1 D: u - private final MultiBufferSource source;
& R, Y+ E) z8 F' Z9 ^$ b - private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ x3 e; R% T$ N, ?; z& U" Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, d8 Z; |* y- m5 [
4 u8 P& x) Y5 R7 Y2 p! R
5 W0 j, W" Y$ j- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 k) ]' P+ D' ^3 H6 [/ e: D- U& t
- if(x1 == x2 && y1 == y2 && z1 == z2){9 S: R0 P! }. P# j3 I
- return;
' g8 u1 O5 I4 Z L L - }
9 G7 X7 c4 }4 I( H4 Z$ r( ~ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. p3 z& ?# P3 k5 O0 V1 V" B - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 i/ E: a8 r& Y - }3 d" r! d, h) p! s
- pose.pushPose();7 b' x( ~& m' g2 h8 K
- final int newLight = convertLight(6); p5 x: @7 l' N, ^# p/ w1 @
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) [ S# f2 Y* Y& e: t2 S" z8 e
- final float lineHeightSmall = (y2 - y1);/ j. M# r8 i/ k! B9 C9 b. O( Q8 \4 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 [6 ^9 H3 T2 U - pose.popPose();! a; z9 Z% K0 _( i3 V& p- F8 ~4 Z
- }# d6 i: L- d- r1 e
- s! ]% h5 Z- ~8 {7 W/ G( `* C$ D$ S- private RenderType getLayers(String texture, int light) {( \9 b7 d1 x8 `1 X/ B
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 N' O; m% k4 R* H/ h3 S - }
1 V& @+ G5 z0 F7 R- R - * O- a4 J' ~1 {0 |* Y3 O; s
- private RenderType getLightTexture(ResourceLocation texture) {
+ ? ~" R# x- V4 f' S' h9 d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: A0 M/ t5 P# g9 b; t - }; I0 {5 P3 s: O4 E# W
9 u% k4 b9 {/ s' g/ g* E" P9 p- private RenderType getTexture(ResourceLocation texture) {
. k7 I5 l4 s* `& s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- K: ]2 B2 i/ p# U7 f4 h9 w - }
" S; u# p! G) I
( u, N- t& b& V3 i1 ?7 }- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; ^! E L; q( _$ `1 j# ] - if (cache.containsKey(identifier)) {1 [6 U2 M3 s+ F o
- return cache.get(identifier);. n! Z# w" r# B6 L6 o: v( y
- } else {' O/ @8 i& G; c9 `
- final RenderType renderLayer = supplier.get();' j) g% C. L3 Y$ e! W* b
- cache.put(identifier, renderLayer);
# S6 B* [2 a9 @: M- { - return renderLayer;6 ~+ d+ n- W- E- R2 b4 C
- }
3 P1 i8 v8 s& F* H - }4 Q& l; R; m' I6 K8 H
- }
复制代码 |
|