|
|
2 R% K) P% J( O G! E$ @* b' B
行,这个怎么样! h! }' Z. h" b% w' j! s
- package com.xhg78999.mtrfac.render;
" @# e A- |- t7 @1 }
- _* U1 t- P( C& k6 {* _- import com.mojang.blaze3d.vertex.PoseStack;
9 L7 Z% o: l. O3 I1 g: f - import com.mojang.blaze3d.vertex.VertexConsumer;
+ S" y; `& J( Q- P - import net.minecraft.client.renderer.RenderType;" R$ X' b& D9 J3 Z. n% N. Y; z
- import net.minecraft.resources.ResourceLocation;/ _( X9 V, E: V' _( p
- + X9 Z0 I! z- q) L8 F- X0 U
- import java.util.*;
$ `! \: ^: S7 Y" ]/ F - 7 f/ ~" L4 t: H$ g1 k6 K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; v8 O% @* u( m1 Z - / F) v; ]3 G+ `, X8 z
- public class LineRender{
! j7 i1 ^5 d+ e& M7 G! m - private final PoseStack pose;, m) y! _6 P, H: I, D8 h
- private final MultiBufferSource source;9 p& O# y* [2 O z! v
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();: s2 P: d L Y3 l1 x& _8 N0 u" Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' @. o: n# t& | W2 c) M2 R
- ! o& O1 Y0 C) k/ q2 _: D
* M5 ^- p5 f8 u9 h7 @" U% {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, Z# l% b- Q! ^5 z1 w7 l6 V6 w W - if(x1 == x2 && y1 == y2 && z1 == z2){ [) S& z( r- q* p3 G
- return;
0 c8 j! G6 P/ t# r - }
0 u* h9 P+ o; R8 `% P. V - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
+ {( N/ h: C: U5 g( U7 {; z* s1 T. ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) G: x3 \% d# S - }
: c, M4 y, K% S+ ~2 T/ _" q8 `( Z - pose.pushPose();
/ b; w# N3 n) S+ ^. d - final int newLight = convertLight(6);
5 L2 u$ j' G- I- U) l - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 |+ e0 A9 G! E7 P* W - final float lineHeightSmall = (y2 - y1);! Q0 ~+ f4 p0 u
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' w2 t% ?4 V# }) o0 E/ ~ - pose.popPose();
! ]" D0 N) K& Y2 B - }
0 E, F/ g. b/ U9 {, u& f9 x; l - ) ^; D9 E7 l* ?7 Q: H6 Z
- private RenderType getLayers(String texture, int light) {/ v9 P3 i, C: ?! l5 `$ P. ~
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! L s- a4 i. Y' B# T( s1 r - }. x# M/ v+ L- t
- 5 h0 a) `; b3 v# y3 P/ ?: Q6 f
- private RenderType getLightTexture(ResourceLocation texture) {
1 u4 d; m/ A* X$ y5 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) l+ Q1 E+ T" I! j# @/ } - }
- |$ p4 Y. r' I3 V1 P: V! q - , `( C0 ]0 R' P' Q% E
- private RenderType getTexture(ResourceLocation texture) {
+ P% k3 s y$ a9 k7 z0 ` - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& ~) [' E" ]( V, X - }" O+ i( y7 T# l. d8 N: T7 E
, Q8 c/ {) J" _( H; k- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 F2 _( f- h" `+ \2 W
- if (cache.containsKey(identifier)) {: L3 |3 d0 Q$ L, B4 l( E3 t- p) ?
- return cache.get(identifier);
3 W. R% M m5 g$ L - } else {
8 C6 f- g2 i6 k) @ - final RenderType renderLayer = supplier.get();( I5 _% ^, G+ @* [9 v, A
- cache.put(identifier, renderLayer);. F: M/ l V% D2 f
- return renderLayer;% L4 _+ v/ U0 |4 v5 K1 X
- }* J: t# z+ K4 _4 P
- }
* S0 ]0 Q# Q7 O% B3 G6 v4 G$ W - }
复制代码 |
|