|
|
( ^2 r, C8 ], c$ t7 Y7 p
行,这个怎么样
0 l7 w9 |, D3 z4 g- package com.xhg78999.mtrfac.render;6 J( b6 u/ o. b: M4 L7 p
: T& f& i' T( `: j) u- import com.mojang.blaze3d.vertex.PoseStack;) s5 u) s; }( e4 h% @! S5 p+ t
- import com.mojang.blaze3d.vertex.VertexConsumer;
# _, \2 K/ T* l0 S* E* f - import net.minecraft.client.renderer.RenderType;5 T6 B9 P4 O& I/ B1 [
- import net.minecraft.resources.ResourceLocation;* [+ ~# Q+ L6 u- _
- / V+ w1 J# r, J$ Q, f" l: {
- import java.util.*;# ]0 Z, e" }) I k7 H: _7 i
- 8 n6 Z+ z; N6 X1 g! ?! u' Q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
Y$ g. O: c, m [5 E Q - # R. B& l/ _3 p/ j
- public class LineRender{ T" W; R n% A2 b/ E
- private final PoseStack pose;
( s3 v6 n3 ?; `# Z3 H/ u3 K, ?+ U) P - private final MultiBufferSource source;
$ p: i8 Y, D: s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ \9 Y% L. E& P/ G - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) r& D# q0 y1 M- {/ j- k
- 0 d; F) `! m- n! O. O
- 6 \. S% x, N. B% U+ B. _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){" f# d$ {: X, ~" w5 W* z( n
- if(x1 == x2 && y1 == y2 && z1 == z2){/ }8 q" v/ N, }3 n; p
- return;
) ~9 s8 y! W+ b! E) Y. ` - }/ c% ^2 K! r) S
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
[" B: e% K$ _1 g8 N) D; V - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 P% M3 P' [; ]: \! ^2 c - }8 M8 \( c& s: ?; J8 Y
- pose.pushPose();
- S; {% L: A! w; H - final int newLight = convertLight(6);
9 ?3 T- O# |% G' r! ?2 e7 v2 } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 u$ ~, |7 i) y& e" _ - final float lineHeightSmall = (y2 - y1);) z+ l4 \( _5 o5 e4 ]. N
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 E* s" c. F6 F: R( l - pose.popPose();: [; F {, q8 k6 B! h7 [
- }
9 v$ V, {2 @: V* W6 f - * B2 I) {2 C, Z: D: c5 E
- private RenderType getLayers(String texture, int light) {) g2 P" \. s7 `2 K, X( t( S: U
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));$ f3 i( C7 \9 m( [$ A9 ? d& K
- }( X; `2 ^" ] n- U
- ' i$ I) P1 ?; P: C! u2 Q- g* ]
- private RenderType getLightTexture(ResourceLocation texture) {
# m% s0 d" |. c& x6 G2 ^3 G# y4 P( y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 f* v, w3 w$ h
- }
7 r# Y+ Y8 @ e7 r/ Y2 J3 }; u
$ z( e; b- r7 E; h: H- private RenderType getTexture(ResourceLocation texture) {
- y/ X$ r/ J7 e& j. \# Z) M) l" J - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. |: ~7 U9 V7 _/ c w; I1 a - }
- g9 k2 C. m- a4 ?' \8 D ] - % D* P$ K1 n0 b- E
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: t0 B: f3 o9 V; U) } - if (cache.containsKey(identifier)) {: w2 }% M( u# E8 F
- return cache.get(identifier);! N) k( R# W/ e' S- F c9 c
- } else {5 \# f+ W: R: y$ a% d# S" F- K _
- final RenderType renderLayer = supplier.get();
' L2 X' f& A% M9 z1 Z" A - cache.put(identifier, renderLayer);
, o% v/ Q9 Q; c - return renderLayer;
4 X q- r) z" ^' P$ n/ i - }
# L% n5 g5 e9 z8 t$ \ - }
8 ~2 x8 t" C& k+ o7 ?" N2 h - }
复制代码 |
|