|
|
5 E$ G: Z( z( T0 r) r
行,这个怎么样
$ e. K ]6 p' L. z$ A, v7 F- package com.xhg78999.mtrfac.render;4 \- w7 F/ H+ L/ B9 h
- # M6 j6 A3 X+ u) \! t1 @# B3 R
- import com.mojang.blaze3d.vertex.PoseStack;) J* |+ w2 c$ T5 y
- import com.mojang.blaze3d.vertex.VertexConsumer;
% {& F R; }7 W$ x( U" p - import net.minecraft.client.renderer.RenderType;% M: m1 X V$ P6 m, Q- c- I% F6 B
- import net.minecraft.resources.ResourceLocation;6 |- _8 [- M7 g
" Z7 ]8 m7 Q9 T% |5 b7 N3 l- import java.util.*;
* P; W2 g/ E9 M/ P. m - : F/ e2 Z( U- }( w2 @9 I9 d0 `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 M& M6 A' O! j( j+ y
$ C: `) v4 O7 W9 D% O* o8 p- public class LineRender{
" T6 V2 l+ y8 e! N* f A - private final PoseStack pose;
6 U4 q, u- L. g% m - private final MultiBufferSource source;: q, Y% q: t$ U% s2 _
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% W+ k+ m* [( n& ^ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 T- | F+ G# g# m - * H4 J8 t l9 Z% E4 @2 s7 H# H, W6 ?
- & x; a/ l! ?6 X5 p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
( l, {1 g# i1 Y; J - if(x1 == x2 && y1 == y2 && z1 == z2){
5 Z6 W" M( C7 `9 ~0 q1 s- } - return;
% |6 T: W9 c3 r% n) u# i - }! Y5 N2 N- Y5 J s
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 C+ ]( M, C2 A; |0 s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. f9 A q4 F; x9 j% ~9 R) z8 c) j+ s
- }
3 Q$ ]' i" ]- J# F3 i/ l) Q3 ? - pose.pushPose();
8 b: h$ \0 ?5 x( G - final int newLight = convertLight(6);" l3 G" ?( N! @- V9 K- k4 Y" B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) G$ G+ H7 K. G/ ^3 T- N - final float lineHeightSmall = (y2 - y1);1 O0 E+ M4 c( i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# F' o Y. R) @; U8 { - pose.popPose();
' o: o, J5 f# c5 ^/ U/ c* f - }
1 W2 F2 H. g2 c/ B - $ Z/ a3 Q1 @& f8 H( @" J- h# f! `
- private RenderType getLayers(String texture, int light) {* C& s8 n" F- D. C
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" V" k/ s! J1 B- e - }5 G$ k" X& Q. a* H$ l
# f7 ~( Y# g0 L( y% O3 G7 l- private RenderType getLightTexture(ResourceLocation texture) {: r8 k2 A7 l A' j% C0 h! z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 m% b& T D' [, M" K4 r - }! o g" l+ W- d+ o/ @+ B
- 0 ^1 F1 u. R$ x0 Z9 S+ k7 r
- private RenderType getTexture(ResourceLocation texture) {! Z% ?9 }' v1 s% M0 @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! d% C: [8 g! a5 d0 L) Z- o - }
+ R+ L9 b6 J4 w
7 g* `- Z- U5 Q5 h: n2 F- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. X& Q/ ~ M7 [5 @ - if (cache.containsKey(identifier)) {9 G. X. Z4 Q" j1 F8 R. D
- return cache.get(identifier);4 ^" y( z! L, X8 X
- } else {
+ I. p- G: ^" ~1 o9 D - final RenderType renderLayer = supplier.get();7 H6 R' v' Q0 N0 W1 s. ]5 S
- cache.put(identifier, renderLayer);
' o- o6 K, \- h4 _ - return renderLayer;8 S% S" `6 G8 p" I" R. L8 h4 Q, J
- }
; O' c' r- _& \/ e - }
9 L6 _2 @% W/ X, k9 z8 |# b$ J - }
复制代码 |
|