|
|
/ [0 L9 N& a/ n6 `% w$ p2 P. P+ k& k
行,这个怎么样
: g# R% ~) @8 Y- package com.xhg78999.mtrfac.render;: S$ s! p/ T! V" v6 y: c( a: T
$ P. D1 j7 c* E6 q) ?- import com.mojang.blaze3d.vertex.PoseStack;
% O8 n6 g# d! K" n - import com.mojang.blaze3d.vertex.VertexConsumer;/ o# @9 ~7 F) X. c
- import net.minecraft.client.renderer.RenderType;
; F5 K( x# q4 ]1 f( D' Y - import net.minecraft.resources.ResourceLocation;
) e$ E) k) |5 D5 Z: q$ [5 Y9 v6 f
8 d/ U q( T4 M& O$ V: J5 x- q; Q- import java.util.*;$ i/ `. K% y) C# P
- 1 u: q3 F& [; F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 U: C0 f' g/ b5 y) \ - % v) _' Q) E. ~9 d* }
- public class LineRender{
9 R( K" x5 h3 ?. V. a - private final PoseStack pose;6 R( a+ y! ~; B4 s) a9 h0 t
- private final MultiBufferSource source;9 X+ z. p6 E. o, p8 a, g% X* Z2 g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 z9 B' a3 K) H. n& Y1 c - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" w7 N# J1 l% }6 N
$ o# a) H/ J* W" c$ m9 {
2 ]: t2 r6 [( T& @2 e1 }7 M4 k$ u- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){, ~9 R( F8 p# ^- y% F! }
- if(x1 == x2 && y1 == y2 && z1 == z2){
. s {0 o( ^ y' R& ^% W1 S - return;
( D% y3 `5 n! K1 q3 d - }: q3 J1 H6 p, F" ^0 u( \0 R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 m% h7 {' e8 o. z# \ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 h; W( J7 m; w% \/ M3 F5 k' X
- }3 D( I0 w0 |5 Z# K+ m, A
- pose.pushPose();* H/ N* I( h: Z
- final int newLight = convertLight(6);/ X- i8 B! u/ i, q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" b( [( q7 D2 ^% a7 f! }) |# { - final float lineHeightSmall = (y2 - y1);
: O3 G* ~+ ^( L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ `9 P7 B& K3 T& h6 `; T - pose.popPose();; p9 c, U; m' p5 }: l7 _) k
- }
5 d! b5 y9 Z% C - $ x9 H d7 v% }9 \! Z7 y
- private RenderType getLayers(String texture, int light) {9 y3 Z6 k$ y& C9 t ?- B
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 p: t* C' N5 T0 H5 ? - }
+ @8 l7 T, s9 a3 s: C - , I, k( ]- c" O
- private RenderType getLightTexture(ResourceLocation texture) {8 W5 z3 `" P; I' W6 `" i4 J
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! l4 e+ N8 [/ Y3 G7 K7 e0 B2 E
- }1 w; H4 r& U# j( L( Y
- , `4 r: K: ]% q' b7 r& k
- private RenderType getTexture(ResourceLocation texture) {
8 O0 R. W7 f# X" L* J$ ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);- Q0 x6 z) {+ K, ]
- }' N& r7 V/ l7 z/ M2 f3 V, W4 c3 g
- : J5 f6 C. Z- Q% z b# e: e0 f
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 c- [1 T' x5 F; W$ n5 L: t
- if (cache.containsKey(identifier)) {, U7 m" l8 l* _5 l) O2 f" F# l
- return cache.get(identifier);
) c; K5 A" q8 V( L: E; s0 V, k - } else {! S0 M! ~0 u, D! t1 |5 O& `5 s. W
- final RenderType renderLayer = supplier.get();
$ Z1 A) g& r* u* w# q& c" s3 o - cache.put(identifier, renderLayer);
: j' M* m @( D3 \ - return renderLayer;
( D5 z9 n( k3 I4 m( D7 K5 x - }
, h u; _ |+ j# d) m - }$ y8 k0 U: _: k8 J, C. x' F
- }
复制代码 |
|