|
|
/ ~" I, h. q+ w i7 f4 P+ n: J& @, |
行,这个怎么样
+ l" u/ n, M. C0 x4 k6 g- package com.xhg78999.mtrfac.render;
l+ Y) A" |) R5 C0 s# W5 \% \ - ( G" B, ~9 |: u0 h' e3 c
- import com.mojang.blaze3d.vertex.PoseStack;1 P m& j0 ^; D# `9 Y/ ]
- import com.mojang.blaze3d.vertex.VertexConsumer;8 M8 z% D0 T- e7 R. I n; C
- import net.minecraft.client.renderer.RenderType;9 y ^7 @8 N& k
- import net.minecraft.resources.ResourceLocation;
7 z* q2 F# \! h$ \6 u) a. c: H
( K g6 P) i, D- import java.util.*;1 c- E- z3 F" A6 ]6 v7 n
0 q( E! a/ Y7 N5 u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ u$ d, f1 [, D5 H/ B; ^3 Z5 B
5 L: j3 ~! g+ Y7 \1 w% ^& ]2 ?- public class LineRender{
( `+ d/ b+ F ] - private final PoseStack pose;: I) Z1 r: }; c) J6 ~1 @
- private final MultiBufferSource source;
- n6 O, R# M: s8 S7 } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: P- e, v* X3 o- u& J - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 a; x4 R& v; Z
7 y$ Y5 [9 J4 B" ~5 i' W, u3 O; T- 4 q. N- v; R+ @- |0 ~! p6 Y: L5 O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ R8 F, x& }+ o" K8 G - if(x1 == x2 && y1 == y2 && z1 == z2){, _2 d$ Z) w$ q1 ]# X
- return;
$ K: p3 T5 h, p2 D0 E( } - }
@! K5 y" ]+ F- `% i1 f" v - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 Y5 f0 E, V$ M; ?! b# {/ t+ i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
( ~% a { }& l2 M) o8 X0 Q% y - }: w2 z; y5 c' d, f
- pose.pushPose();1 z5 X* n$ C" w
- final int newLight = convertLight(6);$ E4 X9 j. d, I4 a7 R! h. g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% j6 W Q- @ `! {) p$ @( } - final float lineHeightSmall = (y2 - y1);6 w1 z6 q* A* z% Q ?
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ F- U8 u Z/ q& ?: O - pose.popPose();
9 ]! d8 n9 b7 S( [$ }6 n4 F - }0 p* s- [9 p% p* {
Y8 r( {) `: c8 }2 b* H( v( Z, k- private RenderType getLayers(String texture, int light) {, q0 X& |' X0 u5 |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 _7 c \% }+ Q9 _6 F* J, D& K5 x* l! c - }
, |3 z0 q; j* _) M: F g" N/ d) k - ) l$ Z' i* l$ E! S6 ? d8 Q5 Y
- private RenderType getLightTexture(ResourceLocation texture) {! R2 q( K0 {: H% ?4 H! Q, T- Z# O
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 _9 _& }' H5 I0 M
- }
2 B& R; a: o6 j& l
' k# m+ D5 `6 q- private RenderType getTexture(ResourceLocation texture) {
4 y4 n, {0 P+ c* h$ r - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- L! O1 W5 _6 [8 H- s1 W" n - }5 S1 y8 `. a0 c5 v2 a, I. L% @3 P
9 `- V/ e Y( S9 P# Z" W4 I# H! B- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: I) t, Q& E. v# u
- if (cache.containsKey(identifier)) {
! L- l5 E1 T2 T; f5 A& r - return cache.get(identifier);. x2 O0 R8 ^& U8 u3 f; N
- } else {
& L: j l0 y/ b) q% H C0 I3 k - final RenderType renderLayer = supplier.get();
% ]5 n' J# l+ x+ t - cache.put(identifier, renderLayer);
1 s/ Z* j2 W! y - return renderLayer;. P+ g) Z. x( H/ p" Y" O
- }7 y( S2 x: p3 n6 x/ o) {* U" _
- }' ]2 j; z/ J* q. V4 P3 c
- }
复制代码 |
|