|
|
1 b6 k B3 Q7 p, H9 [
行,这个怎么样
3 O, [3 }$ p" D" G! M- package com.xhg78999.mtrfac.render;
' z, ]0 I4 c$ ?- q - 2 A9 @: ?) W% M
- import com.mojang.blaze3d.vertex.PoseStack;
7 m( M+ m# J" R F# Q - import com.mojang.blaze3d.vertex.VertexConsumer;
* y% w9 u' ^6 c) P7 A9 E" }. U - import net.minecraft.client.renderer.RenderType;1 \3 E$ X3 |7 M1 n5 k
- import net.minecraft.resources.ResourceLocation;% N- Y, m( X3 x+ n7 V: Y. n
- 2 S: q9 c& \% G: ^& s% S
- import java.util.*;
/ F; {& I. s. u$ s" G: L - : i* p3 k! o( ~! e
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
- R9 K/ P+ |6 j) s
+ x' o" o0 H! d. A8 M- public class LineRender{9 m; R, j( j! U* G+ M5 R$ [
- private final PoseStack pose;
* t6 j9 V3 b4 q( C - private final MultiBufferSource source;
/ U6 m1 f+ a) w. x, P* l - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, `7 ^. R/ u; Q, ^4 {+ C4 ^ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ t# Q: r9 I w! c5 o. @& p/ f
- % K# n7 F6 Y/ `. o, d* @
5 u5 N$ A0 o4 z9 O- `0 d- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- `' f% p- A8 k/ h - if(x1 == x2 && y1 == y2 && z1 == z2){
! e& v! E, k5 [, c& u - return;1 k! C0 b/ [" z" Z5 z" W- u
- }
" Z7 l7 F+ C0 }( O9 V8 B: P - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
) N3 ]( A7 k* t. F- x( S: B - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 _% s l/ P, P: M - }1 G0 j8 _+ _) ~8 P1 \2 E
- pose.pushPose();- e1 f0 g9 q& X2 M
- final int newLight = convertLight(6);# o3 r3 B. N# D( e. n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, P2 Q( [; w4 d, q% P - final float lineHeightSmall = (y2 - y1);
0 k; a0 g# M9 s" H7 y0 E - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 ~- ?7 O' \1 [1 V! Y( F9 Y0 t: c
- pose.popPose();
3 `2 X7 |7 L: S$ V1 D5 I" X - }. S9 u' c" q, H0 G3 h0 {
- * a( W6 W( N7 P/ Q% g% x
- private RenderType getLayers(String texture, int light) {% m0 W e/ @ {; C9 L0 W9 B8 L1 x
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ I/ k! _7 l9 Z& ?
- }9 r; Y3 D5 |2 q5 t/ ^
- ( b! h% {! a! q6 B0 G8 V. ~+ t
- private RenderType getLightTexture(ResourceLocation texture) {' ^1 v) w" H8 a- J
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" ]4 a; Y h% W9 i( V1 M
- }* f! ` G) O, U$ [
9 X1 a8 I W( ^5 {- private RenderType getTexture(ResourceLocation texture) {
6 h: S% D) `6 G8 C - return this.cache(texture, () -> entityCutout(texture), CACHE_B); V0 _* i6 [# Q' `: f+ A
- }
: m2 D# ~0 M: s X. h- L" N
" {8 w; R: F9 H8 p9 d5 T- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' f) t; F: `% D5 }7 z' q3 Q - if (cache.containsKey(identifier)) {. G8 `, o3 s- s8 G7 f- k8 \/ `
- return cache.get(identifier);& j1 ^2 ]. m& c) m" e2 t" o
- } else {
' e) j/ ^8 o' W) `! u$ p - final RenderType renderLayer = supplier.get();
" m. L3 l( E% _. ]# P. j; B. b8 Q) `: H - cache.put(identifier, renderLayer);
1 [; E6 s2 M$ ^+ H - return renderLayer;, n$ L, \- I0 y1 l0 N
- }
# G0 e6 w' h: d [% ? M4 i3 _ - }* ` @& D4 K. B! o6 a( G/ m
- }
复制代码 |
|