|
|
. Y" y7 z) t: w; I. a7 f6 t1 x0 y& h行,这个怎么样
5 P& Y0 B9 T6 N3 A9 u- package com.xhg78999.mtrfac.render;
7 z. ]7 H$ p0 s' ]9 O
& M2 d! Z. q, _" w% y" q6 T- import com.mojang.blaze3d.vertex.PoseStack;' r5 [' \# Z# X( l
- import com.mojang.blaze3d.vertex.VertexConsumer;! _6 \& m) l$ E
- import net.minecraft.client.renderer.RenderType;/ h+ X v) k; U" N: ]% |2 D, q
- import net.minecraft.resources.ResourceLocation;
% x9 q/ @5 T2 A4 \, C& Z - . y( v% }0 Z6 k$ q/ X5 [( D' v
- import java.util.*;3 P% r) w/ {- {9 v) m1 ?2 _
- # ?7 M0 y$ Q( Z9 I. _! p% P
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, v% K" G% `- b/ o( k9 J3 m
5 O! r0 c$ a9 o5 M3 }- public class LineRender{1 J2 y% c7 a) _0 N
- private final PoseStack pose;
) s$ _+ J2 L+ l: b) l# i2 A - private final MultiBufferSource source;: U' V3 ]% Y3 t% E
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ x' V* r! f8 Q1 Q. @( c: w
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% @3 G- @9 W' |$ c7 }( B
- 9 s6 ] S; }" b9 F
) z& e6 F r- ~7 o- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- W8 {( \6 j( o
- if(x1 == x2 && y1 == y2 && z1 == z2){; `& X% G; }( L: _: q1 g' W5 m& N u
- return;6 W- b; w: I7 |8 D1 O6 a
- }- w" B) I) {+ @* c
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 H8 ~ j; y* s% }4 [0 D( [* a - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! F/ ~1 C% [! `9 H, w% N: f0 l/ ^7 W
- }
' a! y+ E& M/ c. Z/ x# e# S - pose.pushPose();
- ~$ J1 J. G6 V L. D: G( G! m - final int newLight = convertLight(6);5 T% x. N; X" I4 w0 d# z* D
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) f* U1 }1 h, b1 I, x1 X2 p - final float lineHeightSmall = (y2 - y1);
# q q- L5 {4 H - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
0 k6 C4 b% p! B - pose.popPose();
0 a: K+ j+ O7 U - }
/ y8 P. V9 s9 v1 K* Y8 g. w) o - : o7 L3 ^: u2 ~" P, M( @4 m' s
- private RenderType getLayers(String texture, int light) {
( |0 Z( R& n; Z0 f - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ L v: i% m; [2 Q; [ - }; y0 {8 V6 M" O0 W! G4 M
4 B+ g2 w, o7 i- private RenderType getLightTexture(ResourceLocation texture) {9 h$ _/ z2 V7 O! m+ V: i& p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* M0 ^. c" Y" {+ q9 D - }
$ t, c: Q1 G: j9 a# ^! k9 Y | ]1 @1 W& P
2 @$ V7 L9 @+ M& ?) ]- private RenderType getTexture(ResourceLocation texture) {
% y8 ^9 `) D+ t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);9 R% L% v! B+ f: O
- }
" v2 D+ m; _2 A+ k - ( A; A# W. }8 u% C& L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) y- O# I9 B* B7 n9 W! R8 s
- if (cache.containsKey(identifier)) {
* a% @1 K* n- @* w0 B8 u - return cache.get(identifier);" Q' t* o7 O/ w9 S+ A( k1 L. P7 l$ ^% n
- } else { r# ]% ~9 Y- J% H
- final RenderType renderLayer = supplier.get();
k& S A9 E: v8 M - cache.put(identifier, renderLayer);
3 a$ N$ v# z7 n( ` - return renderLayer;5 g: I1 v7 c2 [+ \
- }
4 m3 G8 q# w6 \ - }9 u& k3 D3 [4 c9 d% e
- }
复制代码 |
|