|
|
& n* f; J- a- ^9 e
行,这个怎么样
5 L$ G! w2 k% H: N- package com.xhg78999.mtrfac.render;) o9 N* Z- c1 y5 w' H+ L4 h
6 U; V2 H9 }; d! X- U; d- import com.mojang.blaze3d.vertex.PoseStack;' |- r- D! @; d0 K5 _
- import com.mojang.blaze3d.vertex.VertexConsumer;
' M( {6 k( ~2 Y% I Z6 o1 T - import net.minecraft.client.renderer.RenderType;
/ C$ Q4 N; f- k1 l - import net.minecraft.resources.ResourceLocation;7 U7 ~( E3 k# l7 z( R$ H
) m, A- i7 r% O f4 a5 q; a- import java.util.*;: f/ W! V3 g2 @& }
- & e( ~/ X7 I% S0 w/ g5 s3 a
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 I1 H! A5 L4 p1 `- Y
- $ f5 K+ ^2 s' r. y2 L
- public class LineRender{% n2 }' W+ |* r7 d# Z
- private final PoseStack pose;
0 V- x M( H+ I+ y9 J1 M3 X6 N - private final MultiBufferSource source;
2 l+ m, h8 \" M' U' }& _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ o/ C% L2 _8 v5 E5 `; j( a- ` - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ I& F' f, q+ W' f2 s6 T
% P7 Y$ `! {5 c5 K% D* H9 f- 0 d) M( t/ m9 I2 ^
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* ^4 M0 ^! w8 l o - if(x1 == x2 && y1 == y2 && z1 == z2){
6 f; m8 |7 ]9 h' P) K- M- M - return;2 b1 J4 X' M8 H$ j+ v9 G( n( K: S; s
- }
; y0 b+ @5 p3 r0 o% [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 U0 {# a8 z1 h/ S
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 v& f$ n7 q: s* T, c - }
- [7 O6 s8 q5 e2 ^$ t5 f1 x2 [ - pose.pushPose();, `6 X+ L! T, G' Y+ ~: Q; V- K
- final int newLight = convertLight(6);# v2 A+ T. G' y. K6 R
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 `, E4 [& }( f; {; t0 n4 K @- u
- final float lineHeightSmall = (y2 - y1);0 e2 A4 R0 z8 A2 S) A& A
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 h- s- b" b+ v
- pose.popPose();
$ K7 j' T, X4 U; v- a( J, Z - }
# k+ D; H* {( g5 @! u8 g
) y$ U0 d+ K8 ]- f: d% u0 ?- private RenderType getLayers(String texture, int light) {$ W8 s" C+ a; ^+ G9 e& y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 F( V5 ^( d- O7 \/ c: R; a
- }
2 c* X! D, u/ q+ p - 8 V6 X2 m9 v) ?$ b4 J, @
- private RenderType getLightTexture(ResourceLocation texture) {
" K) O8 M- I' m9 U- }7 a8 O - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" I: h0 A, V5 x" v; _2 d& W
- }" r, j. k) o3 u3 Q# }7 q
& b' _- W" K* U3 Q. w# }- q- private RenderType getTexture(ResourceLocation texture) {$ ~) \' R" l& ~7 g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ Y* O/ t! a% ]+ u7 c% m4 {& _ - }2 ~1 f k* k& L5 q
- & t& J6 @2 [9 N8 w7 n5 J F
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 d$ O! G8 c6 S$ i# V$ h6 r; M/ D
- if (cache.containsKey(identifier)) {) ?9 _2 z( z) Y6 A9 o
- return cache.get(identifier);. a' i) y7 _/ z. a" Z
- } else {% \: `0 Z) v8 @: E! v1 e' M; g
- final RenderType renderLayer = supplier.get();
4 E4 p* l* m- T+ i9 w2 V - cache.put(identifier, renderLayer);
o! N) X9 \+ P& y L6 a3 l - return renderLayer;8 j* P6 D+ Z& r( C7 }
- }
( @0 e' O" @8 K0 Y; O* h - }, p7 c* d6 d: v7 G' @# P1 T: K
- }
复制代码 |
|