|
|
2 x$ a$ K0 Y5 m8 f# L6 [; C行,这个怎么样" k0 S8 V8 Q# s1 j( \
- package com.xhg78999.mtrfac.render;' A/ m" v) i0 t0 l( i$ X$ O
2 f! U7 G% Z8 q3 T0 f- import com.mojang.blaze3d.vertex.PoseStack;
+ }0 t: b% o8 Y# q - import com.mojang.blaze3d.vertex.VertexConsumer;
: h0 l/ h5 |* M5 _- P9 c. \; p - import net.minecraft.client.renderer.RenderType;
/ L6 P! [' j, ?6 g - import net.minecraft.resources.ResourceLocation;3 H# D/ `/ [( U2 {+ W3 G
( ?" }1 y' g5 X+ y2 c- import java.util.*;+ {$ i$ T. S; H. U( P
, Q1 o9 H- h8 Z! N! a& n% z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: E5 L1 I& \" Z7 }
- $ ~, R f O/ n
- public class LineRender{
" j. X$ o' G9 r v# ]0 d - private final PoseStack pose;* r P- C x" j2 O r, R
- private final MultiBufferSource source;
# h* o' H( `$ T* I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 u l+ o5 h$ e) ]$ M7 [8 K( t - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ V8 f8 r! p( l
8 |& `* o& g \( _5 t3 e) Y4 |- 5 z3 @/ k( Y+ }2 i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){) q( J% u9 A0 O y* U' y
- if(x1 == x2 && y1 == y2 && z1 == z2){0 S8 v& F' |+ R. ]8 Z O
- return;% u. N- K% k5 H4 S/ m
- }$ O3 W% L5 y$ r+ M* R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 Z C. j# {9 g# u( A2 Y: a
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) `+ s2 _0 x1 o+ [, L5 G
- }
8 `$ S# O3 H- @ - pose.pushPose();
% ?/ c) G5 m J3 j% G! Z' @5 x - final int newLight = convertLight(6);; H$ A0 j& S. W: b7 E
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 Z% j5 b. J b6 I3 C- C - final float lineHeightSmall = (y2 - y1);
2 s6 V/ O* [$ `2 G5 h - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. b4 a D4 ~8 A, Y+ t - pose.popPose();4 E, N& t7 s& U6 L' d B
- }, Q" _# u. ^' { ~) `; B9 n
- ! z+ I2 [4 c/ m7 P; M
- private RenderType getLayers(String texture, int light) {. b, k) k- C) Y4 N# r
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, o6 x" u; r* ^' q: T2 U - }
0 P( M5 \6 E/ h$ k8 O* c - + j+ Z$ [3 d* f% i+ ]3 L
- private RenderType getLightTexture(ResourceLocation texture) {- {6 J; A ~7 I4 H7 U& q" [4 \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ M5 y! S/ `- `: \ - }
$ Z9 R2 T0 v# T Q& Y
& \3 w+ J2 l$ e/ `! T A. T t ~- private RenderType getTexture(ResourceLocation texture) {" Q0 ]7 j5 `$ L: Z4 |
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! o) ]6 i0 R8 u1 _! | - }
0 L, t4 Y$ J2 t4 ^
' L) P3 H$ G! {- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 n; j1 E7 g2 C; j/ E
- if (cache.containsKey(identifier)) {
9 S+ b M: l b1 l4 U - return cache.get(identifier);
. |0 [, J: `8 { - } else {% p7 u* `$ z [+ h
- final RenderType renderLayer = supplier.get();
- Y7 J: K8 S. M' ^ - cache.put(identifier, renderLayer);
0 W; X& t$ ^( ?7 w7 K - return renderLayer;2 y! U2 I" h& r- q( `+ t/ v i, Y* M
- }
+ ?5 F! O0 I( U9 z; p" ?. x - }" \* Y. F" r. e. c
- }
复制代码 |
|