|
|
5 z, [: ?9 c$ X8 Z行,这个怎么样
& Q9 j8 J L7 h' V; r- package com.xhg78999.mtrfac.render;
( Y4 T8 k# a; M2 V0 I9 l6 q. h1 ~ - / y) f* o6 \" u& m/ k
- import com.mojang.blaze3d.vertex.PoseStack;
# b$ f8 ^ p5 T* K - import com.mojang.blaze3d.vertex.VertexConsumer;
; r! V- O) W4 |- }5 G) D - import net.minecraft.client.renderer.RenderType;
6 a$ x |# S' L4 \/ m6 g - import net.minecraft.resources.ResourceLocation;
; g% t1 n: N. h* |
: y5 b& h+ G. }- import java.util.*;/ c/ x4 a3 G" v4 O* o& e
- 8 Z X' U) h* G4 _- T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; ~8 L' H( B3 _+ O! C
: L/ |) j9 ~- I4 h. n0 R; q" J( G3 a- public class LineRender{ W$ `. v8 ]9 D$ T- L0 y: `
- private final PoseStack pose;4 o1 ~. d+ g; X' y
- private final MultiBufferSource source;
w$ \' X3 E6 Z7 o( E& b/ k( \ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 S7 i5 [' w8 O" V; J
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 Q3 G7 U# n6 D
- " _7 _! o" O. N/ ~3 V' j
- 5 W5 R# Q: y; l) e$ H& }$ g: y- c# B
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! \/ u3 b% M! f. q - if(x1 == x2 && y1 == y2 && z1 == z2){
; c9 e4 X+ p+ E- f# j* g - return;
3 E" Z& h1 h5 Q( T r2 w0 D; _ - }# _# Q6 {& p ], g# ]: f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 ~+ s+ U* o0 q6 Y v( u - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 `, ]- Z- Q, E - }' ]8 ]% t' O4 R/ P5 n4 h1 z
- pose.pushPose();0 Q5 T% \' I; r4 I
- final int newLight = convertLight(6);: m& [9 d( b1 T* F0 X0 H$ H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 o: @7 T Z; c* [1 r. s
- final float lineHeightSmall = (y2 - y1);/ [; j0 b9 s' `7 a
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' c; A* ^$ }' b' }2 ~ - pose.popPose();
% }# X' T/ d' Y- O8 J - }
1 |/ u. k& ^" p) T9 J; [7 Z5 h) i3 A - ; P$ n1 N) _5 L
- private RenderType getLayers(String texture, int light) {
2 C+ A) V( U" @0 ^5 | - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% k; s* }/ W/ @2 r! r - }
e# K v3 S$ P; g- Q# Y+ l- ^% B
4 T. I y5 o$ G* T# o- private RenderType getLightTexture(ResourceLocation texture) {+ f3 U2 m' ]$ m" _
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' U) K# m- `! Q) @ - }
# k7 |3 f+ V- m* T0 d* v - 0 n; ?* p* c, T/ k8 [
- private RenderType getTexture(ResourceLocation texture) {7 j6 z6 l8 u) `0 w% N$ S! P
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 X( H/ P* h k2 F, c* G' b. s - }
0 x1 _; r+ r' o2 g/ p$ e) a - 5 b: W6 P; V, S, ~/ A: M
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
9 b& D7 Q9 K0 d$ I0 q2 a - if (cache.containsKey(identifier)) {
' ^# j" y/ I5 F6 ~$ j - return cache.get(identifier);/ L' x3 O2 O& i0 U- H
- } else {
0 H/ J/ H3 W P% @- t - final RenderType renderLayer = supplier.get();% I! t0 P! A3 v0 D! p/ ?
- cache.put(identifier, renderLayer);
' e) J& w0 P) D/ y o7 } - return renderLayer;
8 s" ^7 l# N& c" k* Z0 ~ - }
, e4 Z9 B( E1 c1 Q! F - }" G) L% {5 ^) [' D
- }
复制代码 |
|