|
|
4 p7 V0 S& ]5 q/ b行,这个怎么样
3 n8 E/ Q- V1 P& b! i0 V- package com.xhg78999.mtrfac.render;- ^' {8 O( ^9 o
- - I3 I% n) c; _- [% y" f! m" T2 k" H
- import com.mojang.blaze3d.vertex.PoseStack;
5 i/ |9 }1 s; ~ - import com.mojang.blaze3d.vertex.VertexConsumer;7 ]. i' m; u6 }: o$ `" s
- import net.minecraft.client.renderer.RenderType;7 B6 h9 L9 N) {
- import net.minecraft.resources.ResourceLocation;6 g' M- w' j" X
6 L4 \; k6 h& ^. U7 z- import java.util.*;
8 M. o V. c1 E& D - . w0 a' m* |4 N A- S E) L
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; @' x+ t# @# Q7 d - * J' p/ G$ P1 L
- public class LineRender{* {6 J" Z. K% }1 E
- private final PoseStack pose;
+ k1 P3 C: X9 E+ G+ ~) S8 ? - private final MultiBufferSource source;( M, I4 I: D$ X( W0 x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 X7 u1 w# ` N3 D! Y - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 b* o, m& Z/ x$ z5 I) F/ A4 O
- 5 Y& w f, L9 z9 r6 J6 i
- . q6 f& `6 F" t; E9 x2 F5 b4 }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ f* S- ?, Q, M; q
- if(x1 == x2 && y1 == y2 && z1 == z2){
# U* t& ] q9 {$ _& z3 N1 U1 h* Z& u4 Q - return;% @ r4 k! S6 @
- }" L/ Q; e! S+ C) D* o
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 R& ]7 _1 i4 B c. Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% \* L9 K- ~1 u$ s - }
9 Z' N3 J& `$ ^ - pose.pushPose();: _5 Z1 x. E6 o# f. w
- final int newLight = convertLight(6);
- x& |* ?3 _: [. k# f# c9 E: F- w - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 w$ o! z) Q* T5 n( h
- final float lineHeightSmall = (y2 - y1);
& y& A7 H- M- r6 w, v) e' j% Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);. ?# L. i: _' Q, L
- pose.popPose(); [- @! k& r. r; ~. S" c0 ]3 |6 x
- }
5 `: h3 a, d5 w5 I1 M C1 A
# G ^% b9 q/ c& A- private RenderType getLayers(String texture, int light) {, f* ^# F4 A+ h5 P; e" o8 ^# x
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 i3 \; w" w6 k- N5 i9 R$ ? - }
: T0 T0 m5 l, t _/ j# m f3 u
. w) E; o, q+ n1 T2 s' e0 D- private RenderType getLightTexture(ResourceLocation texture) {" Z/ E& _* d7 F! O% g% j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, J& R0 e7 U% Q$ V- d( s - }2 X2 q$ C \6 S( ~2 @" s5 _/ g: Q
- ( I: W E, S7 \4 a
- private RenderType getTexture(ResourceLocation texture) {: e" s' h% a$ S2 f9 H
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ Z5 r5 ^1 ?( H% U! } - }& q3 R5 r" U: f+ n+ S
5 d7 \' J! R1 H7 \+ u; S7 j( w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ J) W. o* c9 {2 c; R - if (cache.containsKey(identifier)) {/ z M* }" Y/ a8 _# C! B' G
- return cache.get(identifier);
% J k/ ~% S) I0 j/ p) ^7 N5 O1 W - } else {* w( c; W4 j. F3 r$ B
- final RenderType renderLayer = supplier.get();
3 m2 w- f/ o0 o, t, J - cache.put(identifier, renderLayer);; ^% Y) M: T y3 G K
- return renderLayer;7 e, m% d# \4 d2 P/ q( _
- } M1 _+ F+ `! J1 v- s3 W2 H/ e5 `
- }
8 X8 R! k: q6 j3 v" T) x' x - }
复制代码 |
|