|
|
# e& L6 x' k- Z. ~: [: M- Y' m
行,这个怎么样
- b+ b1 o6 w0 ~# _- package com.xhg78999.mtrfac.render;
8 J* \2 G& |1 G! P/ d H6 _6 n1 E - 6 A7 F. C8 U6 v+ Y
- import com.mojang.blaze3d.vertex.PoseStack;
7 h7 o. |/ l: }$ K - import com.mojang.blaze3d.vertex.VertexConsumer;
% f- B* a- Q3 q0 c- ~+ T - import net.minecraft.client.renderer.RenderType;
6 i; X" H' d5 y% I( |6 K+ F! J5 |3 y - import net.minecraft.resources.ResourceLocation;# ]5 l0 w2 u3 o; I
4 C6 q; n6 q% {* O5 E7 k- import java.util.*;
7 Y! _: k4 v" g/ w - , H6 F( h% p5 {; n
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 Q5 j6 y3 `2 `- g+ x
1 p: h4 C4 ~: @3 R2 D, [- U9 y1 `- public class LineRender{
8 X3 G* E4 r+ `) v( ?4 H% N - private final PoseStack pose;* |7 c7 e) {! y: z$ a# _" M
- private final MultiBufferSource source;
1 O: J* Y! e+ A ^, ` - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 g4 d7 M+ S$ L! u - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ _3 B* x( J% U+ y+ ~6 e" u - ' Q( z, [0 e ~. f. D0 B, C! Y% Y
- 1 Z5 ?. z2 G; g3 F( V1 ~
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; w8 s, q7 e$ M9 \* e. c* q& A/ b - if(x1 == x2 && y1 == y2 && z1 == z2){( o( X- l; u* z( x: d0 f) [/ S
- return;8 R' Y( q; R; N4 z+ y
- }& I/ W$ i( s! L( W5 \( d. O9 w
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; M3 m) J6 f& I0 ?1 h% x - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ ?2 e* v- _' q; S/ i8 ~' t' V
- }
1 V, S% ?- j( t; s6 _7 P - pose.pushPose();" P, d; _% B& b
- final int newLight = convertLight(6);
0 O4 S; P- `. i. l2 Q: r4 q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ ?& M1 R3 T1 ~* w - final float lineHeightSmall = (y2 - y1);7 r4 E* w% b4 B! c' ?) e8 p
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( n5 i9 _& D& X$ y# M; g - pose.popPose();/ G* [$ z( I3 e8 N; R$ @
- }4 {& z* f. r( }$ q
: v/ P' T8 L$ Z6 L% S1 W- private RenderType getLayers(String texture, int light) {
- m. E8 @% v4 c7 ?$ x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ u) _. z1 _; T+ V4 h4 L- R
- }7 }; m; @1 E$ _
; Z9 m/ I" J+ d! f- private RenderType getLightTexture(ResourceLocation texture) {3 |% D D8 h7 C4 g# n
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 m8 X7 N9 \+ m& G - }/ p o' \! c$ R ^9 Z0 ~
* J9 q. {: S' ?! R8 S8 ?. {( U- private RenderType getTexture(ResourceLocation texture) {9 K" i# w _. \2 O: j# y- ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' O& o2 \5 z6 [
- }' r* ]4 F8 O/ v$ U, `' L5 x' X- c
/ W3 t5 k- C: c4 j0 S- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& c8 j$ E! f) b# w1 v n - if (cache.containsKey(identifier)) {' X$ C/ z0 \( i& u
- return cache.get(identifier);; g1 s0 S. ~3 f( I! P
- } else {: @0 b* A( O: V7 \7 T2 v0 c$ p# w
- final RenderType renderLayer = supplier.get();7 k7 n+ I; T) K0 D
- cache.put(identifier, renderLayer);
: ~% r0 C# _- Q5 T/ o: u+ `& X - return renderLayer;0 W2 n" C1 ] g" B# w# F, r
- }
3 q# Y! p& M$ F7 E* S - }
0 @/ B2 O- |9 n/ j! e+ W% e) t - }
复制代码 |
|