|
|
0 f0 ^% k+ |% |2 u8 ~; b: w行,这个怎么样
' H6 k: \, f( V, t- package com.xhg78999.mtrfac.render;$ G( ?$ C# T+ V& k4 [
- : i( M! Z6 A; P% ^) w0 y
- import com.mojang.blaze3d.vertex.PoseStack;( d( V, Q: i& n$ u" o: M, u
- import com.mojang.blaze3d.vertex.VertexConsumer;% V, I" m/ C& k4 b8 E/ ^
- import net.minecraft.client.renderer.RenderType;
/ w" |0 c2 I8 V* G& ~4 F* P' g - import net.minecraft.resources.ResourceLocation;
% @8 @, G' U) z9 |
* k( P J' v( e) I7 W% Q- import java.util.*;
" g9 s8 } y# E. Z, L1 S - 1 n5 {: V) W8 q5 P( I% s! k
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 F) H' }( j- i7 f4 e - * a/ d' s5 m2 m, M9 g
- public class LineRender{
( Z7 U& C- O# T - private final PoseStack pose;! _4 m7 J& }, ]3 u
- private final MultiBufferSource source;6 ?/ A' U- T5 Q2 J
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();; a9 K7 Q$ I0 i
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 w8 ~* r4 `- P3 b0 D
+ D; A& e4 b3 q# a& e/ d- & g/ c+ ~3 A! q( @# W+ Q6 M
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& W- x2 }+ q1 Z8 n; y% S- c# D9 Z
- if(x1 == x2 && y1 == y2 && z1 == z2){0 t! j! V- ^1 D: Q& D% B/ c
- return;) n/ b. d8 k8 a" t8 y
- }
0 x% J, `/ Z) t4 Y0 i% g - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 R1 r& b5 s- n; z$ P2 O4 r8 ~: [7 ^
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 S$ \( [0 z% [
- }
/ [- `. \! [" A: s% x* J t% J% h - pose.pushPose();
; h! a. G2 O+ G( R - final int newLight = convertLight(6);
m& K6 U; v8 Q: H6 Q+ }! B0 y4 r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));3 J0 }# G# p% a
- final float lineHeightSmall = (y2 - y1);
& M j! [" y. d( y4 g% S - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);. D. t0 H! R8 V) ?* V" _
- pose.popPose();
5 X6 [" h- C: r0 [* b1 f! V - }
2 ~# O' j1 S2 X# }3 v1 S - ' ^1 O3 M1 b# g1 B$ r' h+ N S
- private RenderType getLayers(String texture, int light) {
' n& r1 q5 [2 @* y; E( J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ Z0 p2 x4 @4 @& L2 x/ `1 i
- }
0 C8 y( X B2 f' e! L- @
, I( S% C6 A* o$ u! ~- private RenderType getLightTexture(ResourceLocation texture) {! ?; q. z, F7 H- @8 A7 G
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" `* [9 q9 R K. U5 \8 q
- }* P2 c0 G6 J* i: o
' Z6 E2 K' D [3 M" Z6 Q; |+ x- private RenderType getTexture(ResourceLocation texture) {
; [' k0 }+ @3 {: D: a% `" J3 j1 X - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: w7 e3 ? X5 k* L9 o
- }
" |/ m+ z/ m% F1 |9 J - 1 _1 r' ^) @5 N) r# r3 j
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 @1 `: R) d: ]' p" y
- if (cache.containsKey(identifier)) {$ D; @! q$ h' Y: l( b: q8 T
- return cache.get(identifier);! n- @" q0 D$ L5 w; c( P& M
- } else {
) D! |& A" n# t0 ]" J' H, |& L- e - final RenderType renderLayer = supplier.get();
( E C* l: I9 a7 `: ~/ ~ - cache.put(identifier, renderLayer);/ h6 |, @ D5 m2 t: B& }
- return renderLayer;* o+ @% a( U1 z8 m
- }4 Y7 R( B7 J& V/ G# {4 s0 B
- }
. p" C7 Q& O" g0 i* X! r9 h% { - }
复制代码 |
|