|
|
/ ?" ~- I3 c' @, ^. a I" {/ z7 v行,这个怎么样( [& H6 T9 ^! d# k
- package com.xhg78999.mtrfac.render;% K) y3 n' }# g' D- a! \
1 o0 `' S+ i: ]" O# r& W- |- import com.mojang.blaze3d.vertex.PoseStack;; E. \; \1 W& I! p
- import com.mojang.blaze3d.vertex.VertexConsumer;
$ F1 z: F' z& \( ` - import net.minecraft.client.renderer.RenderType;
. O' @9 ~. ], B/ L( g& { - import net.minecraft.resources.ResourceLocation;+ O' {' S+ ]- i( w5 m B
- 7 j: v. Q2 g6 I& J4 [
- import java.util.*;+ k+ \1 Q( l& e1 w
+ h3 r4 D: q$ d/ t% G0 K5 s' a4 {$ M( N- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* J) o( X$ P* Y0 P6 ? - ( }' x& e! ^: Q _) y1 [) K& P
- public class LineRender{
. W* E- t y( `& O! X - private final PoseStack pose;3 x) t5 n$ p# D
- private final MultiBufferSource source;
0 x$ X* |# J1 P - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 L6 z5 y4 \. `: p7 N - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ c( [2 P9 S, ^5 I3 |4 U
- : G" p8 u5 ~. b
- 6 y0 [ R* F8 ]8 J: ^# G+ u' ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% i# {+ a4 x3 a
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 k8 x. L& c9 t2 F# n# M - return;7 Z$ N, c% ~/ q$ \- a
- }
( ~5 `' m3 ]: G) T. u. \* M - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, G9 s4 U" J; P0 v6 Q9 Z/ i - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# y9 _) P. c2 K2 k* f - }
. F- T" V$ R9 |& k; ~" o - pose.pushPose();! ^4 X1 v9 K) E4 y
- final int newLight = convertLight(6);) D, x" a3 i' I) ]
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ Z9 H4 `. {0 A! @9 \& |+ t2 K$ b - final float lineHeightSmall = (y2 - y1);
9 ~( \ |% N. o. [! k5 K! K/ w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);4 G+ n2 @; |0 y( e8 y& R
- pose.popPose();
# ~ V, |1 W7 l - }
. O; Z. y- x: g) W1 P: l/ q - 0 ]! t- W" Y* i
- private RenderType getLayers(String texture, int light) {, V) F, b: g1 S, }
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));( h! V1 v; Q: c4 U" X k$ [4 P1 ]
- }+ k& o, q! d. y- \" ]1 c$ ]& @
- A0 s; B( e+ _1 C# h3 s/ q
- private RenderType getLightTexture(ResourceLocation texture) {
& w. I+ p( T. W# }8 I8 b" e; @3 K, ] - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( m; h2 l" |3 M, J4 f f& z a0 g - }' o: L* _5 \: `% R8 c9 Y$ C
0 b5 O' ~ P$ l0 P+ v- private RenderType getTexture(ResourceLocation texture) {
- c/ I, y$ {/ m) i - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; \$ |- d$ C* Q- d7 c - }* ^/ s! k3 J5 X
- # N& J; n B6 M+ o
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) t6 M/ e* }' |- _3 ?( N - if (cache.containsKey(identifier)) {0 R; k9 I2 c0 T9 I; M ?- C* d
- return cache.get(identifier);
7 u+ l1 N( c! a9 f; C) a# q - } else {
8 q% P' J* M0 s% B - final RenderType renderLayer = supplier.get();# T* x k/ L. E- R% _
- cache.put(identifier, renderLayer);8 {( v, T, m, E* ~7 ^# `& }+ v
- return renderLayer; U! W. R4 ?) q8 M( ~4 s, O
- }
, a: ^, ?0 C" S7 l9 e7 `) v) C! E- [ - }! \. p3 @5 k1 E: t+ d
- }
复制代码 |
|