|
|
M$ q* _* k h
行,这个怎么样
* u. C5 I+ n+ T5 X h- package com.xhg78999.mtrfac.render;
9 P# k* p$ |( Q# e4 a% ?: Q% I7 N7 G
% `: o6 O/ j0 X. n# a' o: C- import com.mojang.blaze3d.vertex.PoseStack;2 R) S# P$ F( n2 u
- import com.mojang.blaze3d.vertex.VertexConsumer;) F) G* v& i9 L7 O
- import net.minecraft.client.renderer.RenderType;
1 y# q6 U! @3 B; V, N/ ] - import net.minecraft.resources.ResourceLocation;
9 S$ p0 L; Z( t - , _: g: l9 X4 y" q
- import java.util.*;
1 w3 H% j: _' H9 Y3 F3 }
1 T: K6 g' f+ P# z' j; \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# U8 y& L( M$ N- j' M2 } - ( F4 n8 j( l4 n8 t5 Q
- public class LineRender{
$ S& C7 _6 I, S- B: e; p - private final PoseStack pose;: N. P3 A0 o3 l4 n) C( m
- private final MultiBufferSource source;5 n6 N# T& E& K) I% d6 ^. G0 {
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();! `' V2 U, O b) V+ @( X, w
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ x9 j' v, r5 L0 Y( N" Z - 6 k( ~4 T/ r7 v! n
- * f0 `' A6 Q: j0 r$ i' K4 h/ I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- m% b7 e2 y( h) D% N - if(x1 == x2 && y1 == y2 && z1 == z2){
6 k/ y5 n( B$ v4 s: d - return;
, g3 L- Q- p+ |& f - }
; f9 Y" ^2 |% n# k) y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ O$ j7 o, g" g+ X9 c
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 j$ ]( l9 t( t' K/ l5 A
- }
! Y( r0 I0 Q. P! s: N: y2 b - pose.pushPose();. x* X, U) T/ ]! R. |' X$ \
- final int newLight = convertLight(6);
/ L, m0 B+ M B" B; J& ?' ^ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 `# B2 A) q; i i R2 N - final float lineHeightSmall = (y2 - y1);. [- \1 k+ V( l1 E- }
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) W& L+ T. x0 | - pose.popPose();6 c; h$ ]/ ?$ Y
- }1 G( M! x5 U- D0 }1 D, a9 {
- 4 `% q( f% J6 h/ ?6 L$ @; y
- private RenderType getLayers(String texture, int light) {
" X3 y6 L4 @! I$ y+ W/ i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. c! G9 j# h9 T1 N5 R: C - }
: ?; l+ O* b6 x. [
; Z% m4 y- Z+ b0 U/ n2 O- private RenderType getLightTexture(ResourceLocation texture) {
% u9 h2 |/ i8 w6 Q4 | - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
D& A5 G: K( J& v( w2 r4 f: R; w - }
: x0 j k Q" s: P, N% ?) P - / l3 q7 D' W8 a0 d. Z
- private RenderType getTexture(ResourceLocation texture) {5 ^% b0 U/ A1 q; X( }1 A5 q6 K
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);9 a T6 ~3 F1 v+ Z: I
- }8 h- l- A! a+ J! b! |
5 S) m9 l. `* Q: P- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 Q. v0 z+ d' n - if (cache.containsKey(identifier)) {
/ ]" V# d5 |) M" v# R - return cache.get(identifier);
' v) I' `8 D5 ^( p6 J* w7 l: s - } else {
W6 q8 D4 d* ]$ e# T6 \/ n - final RenderType renderLayer = supplier.get();1 F5 p: V( ]: |. `0 M
- cache.put(identifier, renderLayer);
. U4 v4 x5 W- n! d: O2 Y - return renderLayer;
5 V) r9 e5 A% H4 k! K( ^* l - }
# J! I, H- r: Z, Q Z- X, e( ^3 D - }4 I! v, z* h- s T
- }
复制代码 |
|