|
|
$ L& p# P9 h: R0 Z
行,这个怎么样
0 q( O& c1 g. Z% W- package com.xhg78999.mtrfac.render;: o N7 i; ~8 Z9 p; s
- ( H# a. Y o3 M0 @1 ]. H1 \4 ^5 {
- import com.mojang.blaze3d.vertex.PoseStack;
, Q. W2 E2 V! Q - import com.mojang.blaze3d.vertex.VertexConsumer;: I0 ` I Z, I) z, b# G. ?
- import net.minecraft.client.renderer.RenderType;0 R; U+ y% e+ `# z
- import net.minecraft.resources.ResourceLocation;3 j- r/ w2 v- A8 ]$ J7 w
- 3 w4 K, e" t" [$ C# u% r
- import java.util.*;
7 _' J$ [% O4 A( F1 m - 7 m$ {& D' `. R- t7 j) I
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ G7 o& E( O1 T! U X7 H
- 9 i0 X' ]$ g8 x* g7 p
- public class LineRender{' M0 r4 ^" R$ J$ d1 D, r
- private final PoseStack pose;
+ J" W% I0 U# g3 A - private final MultiBufferSource source;( V% L/ w% f0 [1 P% n, i
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 M2 b; f0 d7 Z! A9 ^, w
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ j6 V+ j7 l/ T* C l* i - 2 b8 a% b8 M4 Z6 T
- + B$ Z) o+ C1 v3 J
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! X3 A2 V0 n% } Q5 P
- if(x1 == x2 && y1 == y2 && z1 == z2){/ [' f8 s+ S) u2 z& v
- return;1 s% L+ z4 t" I( ~1 t# k
- }0 G1 n2 f# H: X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ f' Q. f* x- @, ^$ g) v - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- `2 U# L# E( G$ {1 S4 O
- }
3 A F+ _# P9 T6 ^2 v4 d8 c8 B - pose.pushPose();
# }0 ^- [' ^# k) Z* y - final int newLight = convertLight(6);5 S- a' V. D, U
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 G. J2 w: S8 S& |6 v. `1 i6 ` - final float lineHeightSmall = (y2 - y1);
- u7 o8 L& n$ O* E4 J4 ~8 t% j ` - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 r6 _! `' g& s
- pose.popPose(); O- _% r- d" P4 ~3 ?" g
- }; g4 b/ }0 V. Q# R3 {
- * y; X1 }# e1 ^
- private RenderType getLayers(String texture, int light) {* _% ^& w: Y: `& Y$ B
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# J; M! }9 X5 E: u$ J9 v - }7 e$ C8 V2 \" ^' m
- 3 Y8 G' G- K/ ?! s! o7 c6 g
- private RenderType getLightTexture(ResourceLocation texture) {6 ]" J1 f) k/ m$ Z [! ?
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. f/ M# y; H7 A9 p - }
# Z8 x# E$ i% l' R( V; x3 | - ; a( A* t/ `1 G7 U5 y7 {3 j2 O
- private RenderType getTexture(ResourceLocation texture) {
; j' D1 z& [) n* t' m1 x/ |5 Q, q% D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);. D1 _+ f; B0 I( e6 x2 w8 c
- }: I& Y5 { V- t! p
- Z8 U; D/ f+ S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 k3 r1 L2 e5 P5 D" R4 Q6 w2 J! x - if (cache.containsKey(identifier)) {4 W" d; H+ T1 l* a4 P
- return cache.get(identifier);" X# N6 K+ p, p( T
- } else {
2 {+ D; M! j+ W4 r7 O2 b - final RenderType renderLayer = supplier.get();! @2 u. d& |& }/ W( ^4 i
- cache.put(identifier, renderLayer);6 M+ ~. s$ ~' N" t( p- N1 N
- return renderLayer;
+ @ m7 m( g8 P4 _3 O" B - }
0 _$ y8 H# F1 B( H- ^ - }
$ } Q& d0 W. f, S$ g, f - }
复制代码 |
|