|
|
& g! N9 Y) i: ]行,这个怎么样& k! U- q, ]; M% z; m) h5 m7 C
- package com.xhg78999.mtrfac.render;2 C! Q% H5 ]: z5 c' M' D
- K9 I, ?* W' l$ B0 C- import com.mojang.blaze3d.vertex.PoseStack;
: I5 _) p8 G0 ? k: ` - import com.mojang.blaze3d.vertex.VertexConsumer;# s+ Y& ^ Z9 S8 s( i
- import net.minecraft.client.renderer.RenderType;
" f" R8 `" p' @, E' r6 I* T - import net.minecraft.resources.ResourceLocation;
4 I5 c: P5 L- I6 n! B% } - 8 t7 g: r! y! f9 e$ e, m
- import java.util.*;; k# \6 s; B+ X! u' d* s
- % ^, s6 ]; B8 O! s1 Y0 y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" F# N+ b) C+ @" e% w# ?( d
: b' d3 ~* H/ Q- Q# i% K1 T2 b- public class LineRender{! b# K# P& S- c
- private final PoseStack pose;+ C: k. u4 V; @) J
- private final MultiBufferSource source;
9 J# N( \0 w8 Y* [. y4 O - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: L4 M6 R! Y9 \4 O( H5 I - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 c7 X2 k1 _6 }8 Q
h& ]- L2 Z2 ^% D- & ?( K! E3 X! Y0 U
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; n0 J' x! J, Z; X: @9 s% S" L& P
- if(x1 == x2 && y1 == y2 && z1 == z2){" U7 X( {6 `1 u
- return;. b3 B% U9 j' q- }( L0 e
- }
/ |$ k% P. X0 r - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( f' m) P, H2 a5 o) Z0 Z7 t! D. D0 T" l
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 v! y. C2 e' O9 t. x6 S
- }0 E' C2 \3 `/ {- P4 A# f" _' \
- pose.pushPose();! Y% l/ }. H9 {' E4 r( s, r( \
- final int newLight = convertLight(6);
0 A O8 w1 b, r& p S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; q4 C2 q' l# o$ F
- final float lineHeightSmall = (y2 - y1);
# }0 e0 l7 G" o. o0 C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. V0 o! q/ J% {- h( O - pose.popPose();6 w# u( M- l& j+ h! E6 {
- }1 X5 n+ I, a/ a
- ! F8 S! d1 R6 A& _- D, h/ }. M
- private RenderType getLayers(String texture, int light) {
( Z& p3 E6 L4 @8 w$ s - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, ?4 ^. n; Y5 P9 O- ~ - }
8 U7 ?' W/ P1 e" ]" ~ - [& J+ g* |0 U( U3 d( O! d# m
- private RenderType getLightTexture(ResourceLocation texture) {1 N; L, V% ?% p$ x+ }4 T
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ k6 K2 r% r5 ` - }5 Z* I3 v a" s: Z% J
- * P( ?" c `6 x6 a8 y8 n
- private RenderType getTexture(ResourceLocation texture) {& g' p- z5 [! e' D- Z$ M4 w
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) _9 {# R6 a7 v8 |1 j4 E! N - }
) y2 N& y- t: \- p
2 s* e' `7 S' o' x# N5 ?- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* f7 i/ C/ M3 l& b. G+ t
- if (cache.containsKey(identifier)) {
s6 P% P) Y' h9 e5 @9 _3 \; h - return cache.get(identifier);1 A0 s, w6 C; E. E9 U8 T6 {) B4 e
- } else {
2 [1 R" Z7 v W4 m8 I6 I - final RenderType renderLayer = supplier.get();9 G6 a7 W: s5 h8 }/ u% m# a: f
- cache.put(identifier, renderLayer);$ O8 \% ~9 D" k! ]
- return renderLayer;. S7 q# I3 W* Y* V, E! }) ~
- }
( `" S6 n" a9 k) z$ Y( m/ \) P - }
6 R2 r: X- L. V6 E1 V - }
复制代码 |
|