|
|
& w3 E# {' d* }; y; r行,这个怎么样, ?' k& m; \ ^. S& G: ?. A5 o- \
- package com.xhg78999.mtrfac.render;
D# P9 P7 P1 J0 Q4 z0 r+ S) J - 2 t: X h* u8 [% W7 ~/ A% n( m
- import com.mojang.blaze3d.vertex.PoseStack;
9 L6 n5 S7 @3 R - import com.mojang.blaze3d.vertex.VertexConsumer;5 w5 y: u! T/ y& U& B
- import net.minecraft.client.renderer.RenderType;" D; A: z0 { h) B( c! {2 }; ?+ d" J
- import net.minecraft.resources.ResourceLocation;4 o& V7 J( T& C* ^7 i% J; K. |
- & [. ^* W& q, f7 Z. a' c
- import java.util.*;
: y$ h4 B9 N0 G0 f! o3 u: }' g - : ~/ M0 i9 F2 c/ x0 K" \2 S) \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; b9 _8 k3 R2 Q* n: L7 ?3 t8 _( B
- % L$ e! @" B0 y# ^
- public class LineRender{
# L& V V A' c: u3 P6 ]! I9 V# x - private final PoseStack pose;8 G4 l! m" Z7 R) z- P
- private final MultiBufferSource source;1 H P$ h- b8 G6 ?) j4 ^% _+ ~+ K
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();& _; m. c0 P% _, p% B: |0 N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
J8 r8 O5 g5 j) F1 G) V
& V1 h3 C' l* @7 u9 a! N8 ] T; x9 c
$ k. u I1 m$ p- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* J7 {% _+ f7 D3 F
- if(x1 == x2 && y1 == y2 && z1 == z2){
" T3 Q1 |5 P$ y! v; O - return;
/ K' _/ m$ o0 ~6 l2 q - }) l) i* @5 O. h9 N* ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 Y! g( U! P1 ?' J5 `7 o - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' h: k" U5 X5 m! ?7 x( a
- }
/ I% t7 f4 q& f - pose.pushPose();
, X% T, j0 a3 \& W" A( {6 H - final int newLight = convertLight(6);
8 \9 S+ h% P/ {3 x: Y - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ y; } J/ y) |- N. x5 | - final float lineHeightSmall = (y2 - y1);
/ R4 ?. e& j+ l) Z: I% l J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# \5 ]; L4 p7 S0 U1 B7 ~
- pose.popPose();( c( b0 V2 A; y N
- }
5 i1 k/ M* o% ~$ R- i! @
8 c# d) K! p7 l/ o7 V$ Z' B( L( i- private RenderType getLayers(String texture, int light) {
; N) Q0 ~# \+ x# a7 a* \ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 b+ w5 X' \2 ]7 g& o
- }
+ b- p' F( u. i. u6 A
) B" {7 F5 e: N% t1 G- private RenderType getLightTexture(ResourceLocation texture) {2 d! J! k# [1 s3 z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ P" O; U6 N' g2 j* V - }6 J- |5 v$ Q P; w2 h
# k* y1 H0 H8 m2 T. U- private RenderType getTexture(ResourceLocation texture) {, G7 l7 {( a% L, Q* `0 V9 y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);: o1 J' }2 h0 z+ B
- }2 o9 t$ x( J) z6 z/ [
4 Q. W& v7 P9 Q; Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 x. v4 y8 k. u- s& G0 N
- if (cache.containsKey(identifier)) {
6 H' Y! b5 s4 g- Y. x9 ?( m% {3 s - return cache.get(identifier);
6 O/ N! D2 T/ M" P - } else {* h z* B! P: b
- final RenderType renderLayer = supplier.get();- x( i# W6 d' N) h0 |
- cache.put(identifier, renderLayer);) G8 Z4 |: I6 v% _
- return renderLayer;
& T8 ^2 B) ^! Y+ ^6 h - }
5 u: A4 j4 F6 K* e8 m6 i6 Z - }+ _1 W; ~2 G6 v( m4 x
- }
复制代码 |
|