|
|
2 H* u& K( a$ J8 ^行,这个怎么样5 D/ _2 A' A/ b W+ _
- package com.xhg78999.mtrfac.render;6 ]7 a3 {* l; G! Q0 Q2 s
& R& h4 } x+ a9 }( G B4 _- import com.mojang.blaze3d.vertex.PoseStack;
3 F4 Z5 ]0 Z' T' ?1 |/ Z# k - import com.mojang.blaze3d.vertex.VertexConsumer;# f) g7 Y1 Q, F5 g) m
- import net.minecraft.client.renderer.RenderType;0 ~0 d: b5 P; E& E
- import net.minecraft.resources.ResourceLocation;
, ?# r" z, R# K/ P) f3 [! F - 3 m5 F1 j' @# c* q
- import java.util.*;) ^1 t" X* T- h4 X+ F5 `
- 6 B: r5 ~1 a9 E4 ~( a" e+ T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
4 ]5 l* g( m+ y3 }$ O9 Z - 4 k: p" a& s6 P4 Q
- public class LineRender{# [# n$ H6 i7 p9 b
- private final PoseStack pose;& s1 m- N% d: j; u' Y
- private final MultiBufferSource source;
8 E! I( {; h7 j$ |6 o v# N0 y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();' n0 i* w6 Y$ y3 ]4 @" T0 U% s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 a- K# j! ]6 x/ u
- " T H! V" l: w1 ?$ X1 e0 M+ V
- " k _. b: L4 i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& U, \% y6 Q" r( p& p9 l - if(x1 == x2 && y1 == y2 && z1 == z2){
- Z8 s# w# j. x; ?8 a: F9 I5 _$ S5 J2 { - return;: z, ~! U2 B: H6 G* r
- }2 s5 f, w6 t# o, O: a% k; n3 Z9 E# k
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 ^9 g8 F9 i, i& ^9 y3 Y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
+ F M: @, d5 P8 p% S - }
8 i6 S, q' a$ v - pose.pushPose();
* \& p7 D- e+ n7 q! q6 V j - final int newLight = convertLight(6);
1 g+ B9 F S" R9 n - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' m9 l K9 z9 k& _7 O) C" d. G
- final float lineHeightSmall = (y2 - y1);
1 e* X. m: q. r/ `" z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 N7 n/ B1 @! h7 N
- pose.popPose();
8 N" }: B6 u; H2 A - }
5 e. {" }+ p+ s5 y
0 m; g4 |7 H3 s! a! Q- private RenderType getLayers(String texture, int light) {
. m3 w! Y& q4 Z# s6 K+ _! N3 c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; G' y3 p- X5 s$ g1 G - }3 V; Y4 L3 r) E: t
- + h) I" m" f0 T4 u$ Z& T+ R0 l
- private RenderType getLightTexture(ResourceLocation texture) {& p# G: _4 y1 m8 R2 J
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( j/ L# w% o5 R6 {* { x - }
% c2 h- Q3 J/ v G/ b0 p8 ^1 f/ U - 4 g! [" {( d' @9 p
- private RenderType getTexture(ResourceLocation texture) { M% _, q1 g R. x% S
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 x1 r& |, ~& y" w$ B: N% W* o
- }5 _, @! f1 { M# m1 y
- 0 M3 X) C% }7 \- N3 w# t4 _
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# t& a/ r" \0 T L$ y: G# p* K
- if (cache.containsKey(identifier)) {1 @ r: Z$ Q+ f+ t q9 n% y" Z3 G
- return cache.get(identifier);/ ~9 O' U2 N$ {( L0 [0 v( _
- } else {
& P7 p, P* _2 T# W - final RenderType renderLayer = supplier.get();; `6 N; {+ d. L- ?) _
- cache.put(identifier, renderLayer);
. j3 D2 P# E# w. T+ X, i - return renderLayer;
" Y1 z& }! t' M+ k* p - }
+ t9 Q" L& C, F - }# t3 _& h4 V$ u" J
- }
复制代码 |
|