|
|
- ?/ N- f1 ]6 s/ j7 @行,这个怎么样
Z. g |- }9 t4 g# O- package com.xhg78999.mtrfac.render;+ G b! l5 X$ ]" q4 E% C
- & z6 t! Z4 I1 F7 k9 K4 d3 D- A
- import com.mojang.blaze3d.vertex.PoseStack;
% o; v% s2 ^, Y, ?# z7 H - import com.mojang.blaze3d.vertex.VertexConsumer;7 L0 Z& H, h* U9 x1 o: s, A
- import net.minecraft.client.renderer.RenderType;
[! o* B9 Y) @( f$ U( Y - import net.minecraft.resources.ResourceLocation;# l! z. c- S7 e' }
: y. s+ G Q4 H: \- import java.util.*;0 H! D3 w; h; [. m$ q) ^% K1 B3 I
- 5 ?+ {+ W4 S# M9 t3 @! F1 A$ p3 q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% A- W* R" \) u* v" A8 r3 ^7 g - 8 S; C# C; \* c w, s
- public class LineRender{9 j# L' m5 F# Y3 R
- private final PoseStack pose;
& v) H/ C3 t& O8 y$ G' B* D - private final MultiBufferSource source;
, V$ _8 t& u7 y( n, j, p$ \& t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 [6 H0 m* D5 u$ ~; e* S' F - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 u$ k0 }/ s* \+ e% Z4 ]2 m - 7 j1 Y& {& V, ]- ^9 n
, B, N" F' O6 ~0 ~# T- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){9 ^( H3 x# A' V6 ]. F" h" a; G
- if(x1 == x2 && y1 == y2 && z1 == z2){
. A: {5 c1 ~0 |2 J g - return;( S) Z, h8 s% ]
- }
, F5 ^ J+ p; j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% ]8 p+ }9 S* d) t( _) o& F - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 }1 j. U5 z( x% T0 Z# U8 N
- }( p) m8 d' y! R1 V6 ~6 l
- pose.pushPose();
4 A* _8 G1 P* L* `1 M7 k: B- Q/ M - final int newLight = convertLight(6);) i3 ^/ Y* e6 r
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 `+ I' q9 L6 W+ _1 N - final float lineHeightSmall = (y2 - y1);
+ Z: ~* H, i2 N/ e5 N# l - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) T8 [5 ?, T7 ?) Y - pose.popPose();
$ R4 H" r$ @. G& A. w - }
! J3 |# s# {, b/ |4 N
4 F' D, ^3 r" L( \- private RenderType getLayers(String texture, int light) {; o$ ?1 c0 {' U, H. q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% {) e k% A; \0 R3 ~8 v; ^
- }
, d- S- Z# L/ I3 F8 s! T, N - ! F9 P8 |; d4 s9 m8 A G, F* X& {
- private RenderType getLightTexture(ResourceLocation texture) {
8 ~) U @5 `- v - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 x" t; a7 j* c- ? - }
4 y0 [- T4 I+ e - 1 a9 o' N3 k- a, M" z, _, v+ ~
- private RenderType getTexture(ResourceLocation texture) {3 h6 E x2 x9 k$ y, L
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 N/ @6 J) M0 P( J
- }
# Q' V# E3 s2 v' n! |4 l2 a
& A' ~ _; C% @4 K- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* q/ k4 n& j2 o4 c
- if (cache.containsKey(identifier)) {( l+ W/ s8 r5 F }( F4 K
- return cache.get(identifier);1 v6 h/ A" b1 g8 O _( s+ A) x3 O
- } else {% H( i0 i$ A& t1 w
- final RenderType renderLayer = supplier.get();
& b( N: I+ d- r; V6 u - cache.put(identifier, renderLayer);
/ e- P" t* I7 | - return renderLayer;- l6 v" r5 V8 C. w2 A
- }3 k3 \0 V$ V8 Y( ?
- }
8 ] b' U2 A4 w0 F. @' h3 r- B6 r - }
复制代码 |
|