|
|
' Z5 \8 x" B+ t+ V% M" {4 O( k行,这个怎么样
/ m0 ]& ^, _( E- package com.xhg78999.mtrfac.render;& m% C& e+ k) t. h8 l. k
- 9 C8 Q0 m" }3 K8 \& s) [0 B
- import com.mojang.blaze3d.vertex.PoseStack;8 ], Q' J f2 K1 `& Q
- import com.mojang.blaze3d.vertex.VertexConsumer;
" ]% z8 y. m. ?6 N6 n - import net.minecraft.client.renderer.RenderType;
5 O6 T. D2 P; R, h* y ~ - import net.minecraft.resources.ResourceLocation;. H: r; x+ W: I
- 8 J! J6 S" ^! s- I7 J$ `
- import java.util.*;. A6 l; D/ L d0 K( |
, N* ` Z8 b! }5 D$ f# o- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 c) V0 u, M5 d8 h, \' \
' ~3 `* t( T5 J- public class LineRender{5 n/ N, }3 p+ W
- private final PoseStack pose;7 E: O4 F& C8 ]9 k* R
- private final MultiBufferSource source;
% X/ z9 n8 d8 }, o& S! b% p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; ?7 k. W( M9 t! x - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, z' l1 [9 w/ o+ q: o' X& \
) E6 J! q( z/ B' q0 v
: w8 s& w0 N" u2 [- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 n* S3 z# {; V% h9 r
- if(x1 == x2 && y1 == y2 && z1 == z2){) a0 ~# T" u7 A" B- y
- return;
0 l' e! I4 e' L# U* t) l8 O - }
3 K- O2 }2 r7 H+ A: u2 A# p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) J& F# |+ x8 D# Y# N: ^4 M; n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 @4 [& M4 H/ U
- }/ u! C" U8 e! I9 Q7 {' ^
- pose.pushPose();
7 L; A' t$ A% }9 a2 n+ d$ o - final int newLight = convertLight(6);8 W" g, M- Z! Z8 \) x
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));3 L( P6 w) r$ L' [/ w
- final float lineHeightSmall = (y2 - y1);
" |+ g8 I& @; G' G% U' k( [ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( t7 d6 ~1 [: O. Z$ } - pose.popPose();6 w2 y; z j: T
- }0 M' u4 r7 v) j, O, M" O7 q. g
- ! k+ X1 h& ]- |7 o) `6 r; n
- private RenderType getLayers(String texture, int light) {
& ^7 p- ~5 D5 V' [ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* U/ F5 Y2 G8 ~$ P$ B" e7 V0 @
- }/ `: X! r+ N& }; P
# e" ^% ~5 s' E, b- private RenderType getLightTexture(ResourceLocation texture) {
' P8 g1 }; e5 m$ h - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; L }* X5 I& `% X. ], i0 r - }
+ w: Z' {& U" b; B6 ?) ~/ o& H; g - 2 |. T% P) Y/ U: H# k
- private RenderType getTexture(ResourceLocation texture) {
0 D" D) A# ?' h2 \ a1 m - return this.cache(texture, () -> entityCutout(texture), CACHE_B);! `4 u- Y' B" \! t" v
- }1 r) k/ M- o+ t' t
2 a7 [; l$ X5 \: z @3 E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 u% C$ \; z9 J3 [& U - if (cache.containsKey(identifier)) {/ N F6 h7 @8 J: p$ V% _+ m: i! `
- return cache.get(identifier);% K& Z I6 T& K1 n4 c: ?% N% i8 Y
- } else {) n0 U5 C* }9 k* \( F: r4 g
- final RenderType renderLayer = supplier.get();
1 `+ I/ y8 m l" A& e - cache.put(identifier, renderLayer);
0 I' ^+ Y' r$ K2 M - return renderLayer;! ]6 f y- j$ }+ f8 l
- }
6 o6 w) y* n7 `' a7 ?/ X% @ - }' w8 g5 _: p: G4 S! L
- }
复制代码 |
|