|
|
% a/ |! ~ f9 P- i9 i行,这个怎么样
3 F$ U+ N. D: Z1 }/ X5 a7 T$ _- package com.xhg78999.mtrfac.render;
+ s5 y" ?; ~5 [3 Y) V7 E - . L/ I( \$ T8 F, y4 d. E
- import com.mojang.blaze3d.vertex.PoseStack;
$ r1 ]! [6 H4 _, T% P. ^6 C4 m: R - import com.mojang.blaze3d.vertex.VertexConsumer;% R/ d i# U6 r! W- z, e" l
- import net.minecraft.client.renderer.RenderType;
6 P% A7 }* @9 T; M8 U - import net.minecraft.resources.ResourceLocation;+ ~# a# R2 Y+ t
% r f4 d2 i3 I9 i% r! `- import java.util.*;
. @, W. ~6 q( J" _0 O( h - 8 D! j, V" t9 B# m# y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 `2 ~; R0 d f. D - & E2 b9 ? m4 ]; M5 c' P9 j7 `
- public class LineRender{
! p$ q b* Z% v1 W - private final PoseStack pose;
. t9 a5 b) p/ V! m6 ` - private final MultiBufferSource source;3 z4 }( t' c( r1 ~, z: `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
" t% f$ ~! T0 u) V Y# b - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 ~% }2 Q( }& [$ \% f - 2 |1 T, s) E" D! a8 b
/ M+ e, m0 `! O! c, s O9 i- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; K5 _% C5 @6 w, k- ? - if(x1 == x2 && y1 == y2 && z1 == z2){. `9 l0 V' i$ K$ N Y, D5 _
- return;4 a) Q" B& Y( H0 P
- }' ^7 t5 Q; N' ?8 Y: T
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: Q/ y+ g% O" C9 C2 W. Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 M. v V/ `& k# p8 v# i
- }
' ^1 Q' I* U4 Y( H6 V - pose.pushPose();
) \1 V6 l8 P& C8 K - final int newLight = convertLight(6);( {8 M% r4 w4 S7 J: U- L- l* t: A
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));- h/ S$ j3 D3 B) \: c. b( N' Y! k
- final float lineHeightSmall = (y2 - y1);
6 ]* J1 l( Q! g+ M: u2 |$ { - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! r' E1 h4 y2 ~! K
- pose.popPose();
" q- |% _# m0 r - }
6 S' X' y# y' P* Z. q
) Z- `3 V2 I G6 W. @/ I- private RenderType getLayers(String texture, int light) {
/ W' F" N" o9 b0 D& A2 l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# _: `0 `2 G: V$ O+ j' a
- }- V1 E" f) J0 `9 z0 g4 g
- ! }/ d: C! f4 V3 w5 ^( c3 C8 E
- private RenderType getLightTexture(ResourceLocation texture) {
6 O) ~. D+ ~9 a/ e - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 N2 i# u7 P( i" x9 A. Y - }
+ m1 L2 V; o7 e& f' u; u# }! j/ Z1 R
) G' X; f6 u) g- private RenderType getTexture(ResourceLocation texture) {& P& p& c5 }( i9 C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( v3 i& V! |' @ - }
/ Q0 e% L/ V8 c1 I! E! d, z
$ a5 Y9 n3 o: m$ b, I: {# i7 L; y4 f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) @* _; M4 Z" C( O - if (cache.containsKey(identifier)) {0 E" j7 o; P! n5 s5 T. G
- return cache.get(identifier);
% ]$ I( @* U8 \ - } else {8 `# z' g% ?7 q( ~2 M
- final RenderType renderLayer = supplier.get();
- p4 d4 |( x: M) e" A - cache.put(identifier, renderLayer);) Y! M% D* M+ l) q' {8 m. [
- return renderLayer;1 J& C6 j& a6 d8 h( k0 W
- }
0 l3 ~: @% L# l9 d6 I3 d - }0 ?5 Z9 A. C7 I/ B: v) O
- }
复制代码 |
|