|
|
' L2 I" c+ d) M
行,这个怎么样; _+ X! G: G* d! i% g- n
- package com.xhg78999.mtrfac.render;9 b" J$ p, o! C
- 0 l1 E: H# e( U+ W5 `! A, u
- import com.mojang.blaze3d.vertex.PoseStack;: r$ v/ Y% ~9 V3 l+ f+ G7 l
- import com.mojang.blaze3d.vertex.VertexConsumer;; p# y, ]! {1 r# i
- import net.minecraft.client.renderer.RenderType;
- K* L4 o; i2 \4 b" Y - import net.minecraft.resources.ResourceLocation;
4 ?3 s6 G7 m6 x% Y' \# c
0 C% B* k, U; E8 F0 F- B6 [- import java.util.*;
/ s; `: b7 h9 { - + L* s1 e5 Q8 s
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. q+ E) x# _! Y5 L0 Q5 S9 v' g - % h, m6 m. ~, S
- public class LineRender{* r' T$ f$ @: J) I* k
- private final PoseStack pose;0 [4 W: k% o3 u4 h2 r3 {
- private final MultiBufferSource source;
! w: a# H! |+ C; e* { - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 X" W% B0 \6 W4 e9 O2 Z2 C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
3 v3 g ^+ n( t( m' o8 @ ? - " P, T8 ]* a, j3 ]
- 8 C" x8 y( E+ e9 O) u) I* z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ l: p H) s% `- r- m. g$ R - if(x1 == x2 && y1 == y2 && z1 == z2){
6 c$ c. G7 g% C% Z - return;8 R7 \3 ]2 ^8 U! z, f# q$ _
- }
% @4 _, B. a: X" M7 s) a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* s5 d) F$ d; {, `
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" ^) T9 j% J) ~: D% x - }
v; D, b1 ~: g% A4 I' C3 l0 w - pose.pushPose();
' C/ P7 V1 a7 S( M6 T3 K - final int newLight = convertLight(6);3 E' o2 X7 k, S- [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 U; o# X5 d/ A# N" L - final float lineHeightSmall = (y2 - y1);6 J: M9 G4 i9 o. d C) d7 f
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 d1 G8 O% g* k" j - pose.popPose();. H4 d" @% [/ q. C% ~
- }+ t5 V- }+ M9 ?4 w# K3 p# P
- ! ?) m: Z1 `6 ~0 i4 [3 G/ M4 D
- private RenderType getLayers(String texture, int light) {
. J D( N" W0 S( w& l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 o- k& S* K, q- f
- }
. P3 B" V4 J9 Q. S
& p* A/ y1 [/ |, p0 H0 Y9 D6 ~$ ^2 N* h) a- private RenderType getLightTexture(ResourceLocation texture) {
2 S8 ^: n% B! ]- l) Z4 Z# V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' ], w! R1 O8 z) n/ h
- }* V0 R, |: Y0 Q
- - s* [9 X) k* b k* q
- private RenderType getTexture(ResourceLocation texture) {
- A9 Q" l |; X, J1 |9 t( T7 T - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 A2 a% ^4 k, j9 r# k6 S. N - }
* e3 L% C0 a1 \! h! f - , W% [. [ N. K. ]7 \$ Q6 G% n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; G: Y& S9 x) I# j8 d/ ] - if (cache.containsKey(identifier)) {
" p" q& {( X& l7 V$ J - return cache.get(identifier);
! A% l! f5 n- K( [3 W - } else {; {7 n" B1 m% k# ]! W+ ?! A
- final RenderType renderLayer = supplier.get();+ U- g' U2 B) |- q( T
- cache.put(identifier, renderLayer);
0 W" \; i: ]7 B! L# X# c+ G - return renderLayer;
& R$ x' G3 C) \' q9 [# z3 Q - }, ?5 L( A2 ^: D/ H/ y4 j
- }! v, }4 {- u6 M( k
- }
复制代码 |
|