|
|
4 J! Z: e( G7 p) q b* Q9 D行,这个怎么样4 w1 i9 Q. e2 s# b0 O
- package com.xhg78999.mtrfac.render;
3 d" U; ~. q) M" @% m
& h5 A7 C: y5 s8 E8 T" C- import com.mojang.blaze3d.vertex.PoseStack;! U3 o6 X+ @9 E% I% `. w( E, W
- import com.mojang.blaze3d.vertex.VertexConsumer;
& z5 P, Y7 U3 m% e! z - import net.minecraft.client.renderer.RenderType;
c. N4 I+ g' A: T - import net.minecraft.resources.ResourceLocation;
: \8 {$ Z5 @4 O6 Z/ }
5 p: _. _# S `* {% d# W+ j- import java.util.*;1 i& a' P- k$ n' U4 S1 r
- 0 ^! w( O5 f3 P/ p: o' H7 W4 b9 h
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( I0 n% j$ y7 A8 p0 H6 Z, ?
* S! x$ H4 P0 f* D7 v$ H- public class LineRender{
3 d) S4 g, @7 E3 H' s. a; A7 T+ U - private final PoseStack pose;) o: x0 C* B, _$ l
- private final MultiBufferSource source;
. S8 @. R# l: a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();; b. P/ n! c+ T5 C$ }9 \
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); T" E& f( s/ k: q, N
) h- r! J h. j# P: b8 h- " v; a- E J, D! D
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 Z3 w, O: A: v% i" b4 D$ Y
- if(x1 == x2 && y1 == y2 && z1 == z2){3 y! j' v$ O) ` \0 r3 q
- return;/ y; n: E+ x7 Z* `4 A3 F
- }8 E1 }4 `+ L7 O; B) [1 {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 q: }) Y6 b; E+ X/ u' \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) e; T! ^# R4 s/ ~
- }: w1 o) D* I# {8 |% T- I! f& l
- pose.pushPose();
5 q1 `8 X* i# V+ {/ s3 k- O' Y - final int newLight = convertLight(6);
( e/ S. X2 I4 A% o" T - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& P X$ O) r% @1 v: u! `, {
- final float lineHeightSmall = (y2 - y1);
" H0 g s: N2 T# Y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 k0 b9 [0 U$ H6 w - pose.popPose();
* i, Y5 _0 n1 q; y9 ~% p! y - }
& B! _% f! S8 s" Z$ ?. |1 o
" a+ |/ J( o: i$ c z" N- private RenderType getLayers(String texture, int light) {2 K6 r5 R( v M* `- g& T4 x0 ^' x
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* J- L, T2 N/ `2 r, C
- }
( w2 [/ E& a% {) z4 ?; i6 n - 0 u Y# S; K" F6 b6 ~
- private RenderType getLightTexture(ResourceLocation texture) {% i' P, j: @% y' V, o) _. v4 e( z! U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ H! _# _6 ^1 q j - }4 e( B3 k, G1 P: `; P/ R
- W. v" a; M- b% b
- private RenderType getTexture(ResourceLocation texture) {0 d. h' {& @2 J+ q# n/ e# X& T
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! f4 ^7 N& L& F6 V+ k! j9 s, `
- }' U; {! n) J: Q& x5 j5 @' L5 o
- " K3 R7 |8 L/ M9 }4 j
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- b2 \9 l$ X6 I; {& B- ~, y v
- if (cache.containsKey(identifier)) {! o# L) [' }5 @( f1 [# j
- return cache.get(identifier);
4 k: W; S* I: n - } else {+ f- p: r& f" K" j
- final RenderType renderLayer = supplier.get();
! n/ N. m% p5 o$ {$ d0 |' N1 x6 m - cache.put(identifier, renderLayer);
4 [! Q9 r; o. s - return renderLayer;/ g4 M8 I) c2 d. `- x
- }; t7 a" i6 V, ]. ^5 m- u
- }8 d" Z5 {; L _3 X- Q
- }
复制代码 |
|