|
|
- I. k1 G. v, [" n1 w5 b! R' e
行,这个怎么样
/ N9 M9 s/ [8 S+ _" @1 G- package com.xhg78999.mtrfac.render;
0 Z/ y; s5 Y% @ W& I/ J4 s8 f
6 d& l7 Q/ g( G- import com.mojang.blaze3d.vertex.PoseStack;
& i9 l+ T! V- q' _ - import com.mojang.blaze3d.vertex.VertexConsumer;
9 c& y) U/ b; ]2 T: a - import net.minecraft.client.renderer.RenderType;4 J$ S; T# r0 j! U
- import net.minecraft.resources.ResourceLocation;
5 o6 s% @ G7 G, T2 {/ y5 X& z
8 P' G1 k* R3 f( K% ^% `- import java.util.*;6 M4 I5 q) u. n( e: d2 B
+ o, \# K) `+ v3 e# n; t N- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 N+ P8 ?% K0 C - + [! i0 o! |5 ?9 S5 I$ y* D: D
- public class LineRender{/ D# ~9 m `$ Q1 l* b+ j
- private final PoseStack pose;
7 z8 K" v& l# t3 M/ [- Y - private final MultiBufferSource source;
6 O, k, @( D1 X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();& b d/ H2 }' h" y: }
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, p) a) O J s# @. n. F, ~/ l* m
- , l6 G' z! [7 }3 Z# p! @
- $ y0 {4 |# t% H, x% }4 c
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. K( ]7 S* q* y
- if(x1 == x2 && y1 == y2 && z1 == z2){
z+ m9 R( C$ o1 t' I - return;
! j- A2 l" D+ {7 o7 x/ _" f& \7 S - }4 H: C& T( s# h4 D3 a
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 G5 d5 c9 _6 H1 s; T7 R& Q1 \ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! \, } E _3 B - } a! c- _6 S+ [& W! y5 Y4 z' J
- pose.pushPose();
3 h- g. T1 w2 {: W9 T% g, g1 B - final int newLight = convertLight(6);
& p' S7 H3 h; l/ I - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 d$ f& g- _ c q0 q. ` - final float lineHeightSmall = (y2 - y1);
% u4 A' {7 a2 `' k0 v3 ?& a9 M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- @+ s( M% Z6 U) u' d - pose.popPose();
9 }( L$ f/ w+ _ G& ?5 _ - }5 V0 m$ x% c; x0 X- P# F/ v
& q/ g6 i$ i# {* |, I- private RenderType getLayers(String texture, int light) {) N! t- g& ?- c7 M
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" B# t) a" g- C' d5 p5 J - }9 ]0 _9 o' i- H- Z
. y7 R% v/ [4 h: a0 O- private RenderType getLightTexture(ResourceLocation texture) {$ v) X% _! l! A8 f
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ I2 y1 A" U6 e4 B
- }8 i9 D% J6 G' F9 n% j e
0 O! ]; f, l) }0 M- private RenderType getTexture(ResourceLocation texture) {
) l' b: c+ x- W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: i: W; Q6 W9 b# f0 _+ R) L - }
# A) z. h8 ?( }' n
% W7 }3 N8 P: M1 g. z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 @; d( O' n) w0 b5 G) G' `
- if (cache.containsKey(identifier)) {/ l2 f: P8 _1 k' l/ r, {7 [" o
- return cache.get(identifier);- m Q! |3 `$ S' C- ?
- } else {9 S& |- B( k3 P
- final RenderType renderLayer = supplier.get();
( ]+ y" ?7 r1 m J - cache.put(identifier, renderLayer);
8 X2 t$ t3 {) G - return renderLayer;7 @) h% I( k, j5 ^9 Z
- }
0 ]6 R: u9 A+ o# A- A% |4 T0 v - }0 O) Y- E* j0 L' a
- }
复制代码 |
|