|
|
; D5 A% i$ u; M* L" ?! m7 F' Y: `行,这个怎么样
/ D, W4 l! f5 l- package com.xhg78999.mtrfac.render;& L) B) y+ a; g, D7 k
- 1 k, `5 d2 e/ |; y' S# z' F! I
- import com.mojang.blaze3d.vertex.PoseStack;
1 Q; ?" [$ l- I - import com.mojang.blaze3d.vertex.VertexConsumer;
# i( q9 M: u5 y0 _' \ s- A% p: \ - import net.minecraft.client.renderer.RenderType;* X5 e) r! f. c1 [ p
- import net.minecraft.resources.ResourceLocation;
8 O, e7 U( g, @: o% U - b" y# s1 I6 Y9 s: H
- import java.util.*;. V" k7 e2 k1 e7 Y4 t
- * T/ y, c& H* K- E, l& E& |
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 E% ~6 s, |# h! I5 n' E
8 A/ w. O) B$ g, T/ \- public class LineRender{, K1 I1 I, k6 G. |6 @
- private final PoseStack pose;
- c# ^) h; p z9 L - private final MultiBufferSource source;% r5 Y/ O9 i9 g9 U
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* O0 N- k4 T) g% G$ M - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' b# N: L5 x# M; L+ ^ - $ o; O# D7 V8 [
7 S+ v3 v7 g) p" A* c5 R* B, v- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! H9 ]' j) C* e0 } - if(x1 == x2 && y1 == y2 && z1 == z2){* ?1 p) m2 X+ h
- return;
$ O2 y* o, i: S - }9 R$ _: l, l0 a0 Y1 p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% ^$ k" U7 b, J8 O# X# x+ k' g - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 y# B+ ^0 _3 A, ]/ C- p: R' c - }' J, A5 V" M+ ]0 d% c1 Q0 g
- pose.pushPose();5 {, g! S) r9 H5 w4 c2 @4 l# b
- final int newLight = convertLight(6);
% X7 r, j$ v7 g# q9 @3 k+ a; ^ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. X) T S* C: _ P8 n; o: D6 X
- final float lineHeightSmall = (y2 - y1);
1 |$ f: i0 l S) R2 w" A/ J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& x; L$ c4 s, b: ]; ?/ n - pose.popPose();8 P! c& O) j( P7 v) D4 C) P4 s
- }
8 z i! D/ f1 N% P! @
$ t7 c5 d6 i7 r+ L- private RenderType getLayers(String texture, int light) {# t% O. s! i7 Q$ L9 S
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 E$ t( E( L) e/ h' | - }
5 Q0 A( `3 s9 k7 [9 q - 5 t" L: K# T8 k' Z" o' K
- private RenderType getLightTexture(ResourceLocation texture) {& ?& W0 q. U( _" g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. s' d- l! x% o* q1 j
- }2 Y9 M* ]0 V K8 g3 P+ b/ Z; t
- g9 E5 R- l [/ g
- private RenderType getTexture(ResourceLocation texture) {* {1 X6 J& D$ k# n9 T! G
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! s) \$ r7 N) Z; |+ Y+ S
- }; U1 o# B2 c# a6 ]
- ' R5 [. W' z9 h4 H
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' T$ B8 B1 y" i% R5 [
- if (cache.containsKey(identifier)) {' E; t% J& S( S: Z! p- I
- return cache.get(identifier);( A( t) E6 m" T
- } else {
( {, v' n: N8 r - final RenderType renderLayer = supplier.get();
9 W" q: s) f5 Y Q# w - cache.put(identifier, renderLayer);
4 @, S6 A2 J% j4 z% r - return renderLayer;
# D7 X/ I7 [! l- W& } - }+ ^" e! e- B; S6 z8 I
- }
! p' z; ^; E/ J2 w, B1 U - }
复制代码 |
|