|
|
' _" Q+ y/ m2 j1 O
行,这个怎么样
* e( O3 W' k. s/ X( y8 v- package com.xhg78999.mtrfac.render;
* ]& r. L& I9 x0 i( Q - 0 T. e) L1 w6 C' R
- import com.mojang.blaze3d.vertex.PoseStack;
4 n4 A9 |, i, J% C% U+ `& X - import com.mojang.blaze3d.vertex.VertexConsumer;3 S! e2 b! F/ E
- import net.minecraft.client.renderer.RenderType;
6 V4 B& f$ I4 A+ \" O+ h - import net.minecraft.resources.ResourceLocation;
; N) X+ h- Y' c4 r - l" P% o0 c8 ]1 x. `3 k q) F
- import java.util.*;3 u* L' B6 I; I2 `. h
- W4 k; @5 e- T( E! _/ a6 o4 \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' D# d; }3 @7 P N: F- T x
- # ~6 ^* A5 ^0 O4 Y" U% C. l0 \, _! Y
- public class LineRender{
0 `( V' S* \1 }, ^' l9 F - private final PoseStack pose;1 c1 A+ ]2 ?6 k) Y: N' Y& o3 c
- private final MultiBufferSource source;
' ^, C4 A( X+ h. i. } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();. Y) d9 I. H; i8 G# j( I8 I
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: x5 H0 C3 l' s9 R: e
# U1 H% ?+ X1 G; `5 u; H- + k+ i' d1 B1 A+ x: u) `9 D& U
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& j! v" m0 U) f. U
- if(x1 == x2 && y1 == y2 && z1 == z2){
, G3 Q! d/ y- `$ n% p3 h - return;
4 V: o& P7 ]3 E1 z9 `- S- R - }
% \0 }6 K5 E F5 M6 } - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; c, J! W5 F# t' _7 a) U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
4 I3 R3 o: ~, H* r - }$ Z$ f& h2 h' H; O
- pose.pushPose();1 E5 v$ e: c1 P* d; s- d
- final int newLight = convertLight(6);
; E$ n# w5 m9 l, k* ] {* i - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! E5 d) y Y; ~; t$ s0 L& X - final float lineHeightSmall = (y2 - y1);, ?; L5 }* i8 U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. D, Q+ S4 `1 g5 L: } - pose.popPose();8 _9 J9 T; |9 |0 Y
- }) _' ]: M/ B R5 y. e
- . c" H+ I5 N3 @ e ?0 `4 J( |; z
- private RenderType getLayers(String texture, int light) {
6 J3 Q/ |$ K, [8 J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. J# X0 _+ c f - }
3 z1 j! F& R/ @) G7 z, X
+ W9 Q4 m) k$ ~( a, t- A- private RenderType getLightTexture(ResourceLocation texture) {1 a1 b! d E P; P* f
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 p! v5 s$ z" B# ~, Z
- }
8 t; T! Y" t6 [3 ` - 8 t! X0 W7 R1 z; a
- private RenderType getTexture(ResourceLocation texture) {
/ k$ _! @1 {; q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 V* m. W# }9 v5 S' m- _8 n/ t
- }: h9 W7 C7 m+ l: l8 B8 a$ e
- + h1 M5 Y1 x# G
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 _6 u2 X2 o- b" X8 A
- if (cache.containsKey(identifier)) {3 Z9 D/ P) M3 k& z% B ]) T9 p
- return cache.get(identifier);
; Y! s! y4 T* J3 \! P. D3 k - } else {
# a- @4 i7 q7 @+ M& J - final RenderType renderLayer = supplier.get();$ K! p% o3 a% ]! D% p# ~6 x/ E, g
- cache.put(identifier, renderLayer);! S* Z! g/ p1 b, D# \; o
- return renderLayer;5 ~: W" U" N, G2 z2 g1 Z! u
- }
$ `( b$ m; L; s, ^ - }
; y/ S& _& v% o- n5 j0 m- j - }
复制代码 |
|