|
|
: x, j' l4 C* t8 Q行,这个怎么样
+ Q0 C6 L z- n8 g4 I r- package com.xhg78999.mtrfac.render;' t5 G( J9 K& A: ?
- , v4 Z0 D8 d. _" f4 v
- import com.mojang.blaze3d.vertex.PoseStack;, O- {7 @. M4 c& |) d
- import com.mojang.blaze3d.vertex.VertexConsumer;
0 k& [/ }2 i0 k' i- S - import net.minecraft.client.renderer.RenderType;( i8 p7 {0 S7 R7 V& O# n7 o) A
- import net.minecraft.resources.ResourceLocation;: V* f$ h, H6 s& R# x
- : l( G y9 D+ D& W& g$ s4 R, C
- import java.util.*;2 q9 P6 C `9 v9 a
, e& y& ]" v# u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: T* b! V3 t) I- a9 C
- 1 r* X7 I5 w! W, [4 m
- public class LineRender{: y/ X; O6 X1 c) A( r3 H- j
- private final PoseStack pose;
9 k3 c2 U3 T' z* R& g7 f; b - private final MultiBufferSource source;
1 V; [8 }3 f& b& P7 O) G4 o - private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 k: I$ x2 C3 j9 T
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# \2 l" I" C( O; m
3 O" G0 t$ G; T' H3 f" y% d/ \- u5 s4 k7 D& _$ x, ?+ P0 Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 P* y2 ?0 ?( B. J
- if(x1 == x2 && y1 == y2 && z1 == z2){7 N7 u, H& l @/ F/ [6 Q' f2 Y5 K* E: o
- return;
1 f9 t' B- ~! |% ~4 t - }
& F' ~0 D0 h) t; K$ m& _ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* y; M. z% Y" y- [
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! p; X- o& K1 J* y7 \& X P - }( V! u6 s3 u. d0 G5 G+ V( _
- pose.pushPose();
: c" x' f9 Y* _6 o8 ~8 v - final int newLight = convertLight(6);
3 B* [/ X+ R. K; [$ j! K/ | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 @8 B4 K& F) y A) ~ Z - final float lineHeightSmall = (y2 - y1);+ r1 {/ v8 N" E2 D9 l7 d) h
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 Z4 K0 y& r, _6 b8 ^% d" [ - pose.popPose();7 X- S7 }& D4 T! e3 L
- }
# c. V0 v9 f. L) |
8 A$ Z+ ?) F8 D! `9 W+ x- private RenderType getLayers(String texture, int light) {$ e9 m0 F- H/ z( I3 ?) h
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 a0 K, f6 [* A6 V( q& W - }
" R X3 ^4 F* ]2 o" z
( b) @* l! \* E- private RenderType getLightTexture(ResourceLocation texture) {% L' {4 G+ [" @
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 c4 R" K- g) D& R, v. ?4 g
- }
. P! O6 ^% ?8 ? - " ]* t" D/ @$ t
- private RenderType getTexture(ResourceLocation texture) {
5 S3 f- r. X! B- k8 y: @: w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 q! e% ~. H0 z7 e
- }
! K# ^5 ~( v( p! B B. J - 0 W4 R! ]/ R9 i/ h' [
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 o9 P/ \7 d5 d: Q M - if (cache.containsKey(identifier)) {
' C5 F# x4 t+ V) R- j8 ~3 u' ? - return cache.get(identifier);
6 @+ D) q3 N* ^ z - } else {' ?( O8 N5 e1 Q
- final RenderType renderLayer = supplier.get();4 [3 ~) T8 b- W
- cache.put(identifier, renderLayer);0 E0 Z& _9 u9 k
- return renderLayer;
! G: {, n% j- j% k: b7 h - }
# \: P. C! ^; v$ G3 C3 R2 y - }
% h0 q2 O6 ?# V }3 U - }
复制代码 |
|