|
|
8 z2 j7 G* j$ E0 P0 f# d行,这个怎么样2 z/ r* N4 u) o8 E0 X, P; B
- package com.xhg78999.mtrfac.render;; \" c6 L# V; e8 a( U/ r
+ {* J( C; J: n' y( E- import com.mojang.blaze3d.vertex.PoseStack;
3 C* K) Y. b& F! E8 e$ m5 O - import com.mojang.blaze3d.vertex.VertexConsumer;
! V8 t, Y2 i0 [! C% t2 m - import net.minecraft.client.renderer.RenderType;
( F2 w2 T9 k% ~5 H; S - import net.minecraft.resources.ResourceLocation;- D% h( H _$ g1 u2 u3 W) H s
) [& j9 i3 p: Z( |$ C- import java.util.*;4 d6 K& A, }: g* u
- : k- R) s$ P# ^" z4 E7 r2 ?
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. k X2 t) A& N0 v. l# R4 p
; O% f v: s% `- public class LineRender{" ?& _3 M1 w0 ]9 w' ^: p
- private final PoseStack pose;8 u* r( O1 w% {' m0 w# @1 R1 Q
- private final MultiBufferSource source;
& C1 m3 |/ ?0 ~/ G - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 F% G9 Q( g* ^, [" a
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ C8 |/ V4 s4 Q& X9 k - 1 d+ t- W2 ~7 i3 {( ?' x. D+ Q1 N8 R
- , [) }; O& Z% [, e- @* u8 p" n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 B* Z/ h$ S u2 ? - if(x1 == x2 && y1 == y2 && z1 == z2){
# |# z4 V* L" L2 |0 ] - return;
& Z/ p6 n! z6 Z2 y! x - }
! m4 c" F+ ~8 W- R; S% J2 A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( ^' h, C& {6 k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! p0 f/ _. ]+ f& F* P5 k9 h - }
p+ y0 L+ s o - pose.pushPose();1 l% ^" F% U5 f# x
- final int newLight = convertLight(6);
, d* o, q/ ]' {5 K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) r1 Z- `' v x R- o4 b - final float lineHeightSmall = (y2 - y1);1 d/ @: f/ X( C8 W
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 a7 R) C( V+ z* {2 [$ Y
- pose.popPose();
0 u z3 A) h; I# D - }
# ]- I# n ~( s: A. M$ I5 V - 5 n6 Q: `) Z; J4 E* V4 u9 Z
- private RenderType getLayers(String texture, int light) {
$ n) a7 Y) ]& Z/ J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; @3 y/ K3 O' G1 z" ?* H- h# L
- }! i; h# A* w8 {1 A
- 8 S1 ^. a3 V2 I5 B
- private RenderType getLightTexture(ResourceLocation texture) {
" l$ G1 I I; H5 @3 n - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, o3 g5 O( n8 j. C8 l
- }
3 d7 I; e6 U4 h0 C0 W* x) e3 |$ o - 0 u0 r# a: J4 {
- private RenderType getTexture(ResourceLocation texture) {
! [3 ~3 {+ a% w4 x - return this.cache(texture, () -> entityCutout(texture), CACHE_B);# q) S) P/ I5 p C9 A
- }
% C9 ?/ w, Z+ A U: c
. N# v/ y3 Y; p- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 ]! X! `; q! ~& R6 l+ k+ g; {( G - if (cache.containsKey(identifier)) {' R- y* p% Q2 {6 s2 l6 f3 {
- return cache.get(identifier);
- U+ l/ {$ g& r( N7 J/ D/ N' _ - } else {9 f& [4 i1 S- T0 `
- final RenderType renderLayer = supplier.get();
/ _; [( o' ?7 J3 ?+ Y5 O, u - cache.put(identifier, renderLayer);' X6 L8 m6 m3 {/ B
- return renderLayer;. F" w5 U4 H" S) c
- }2 }8 n. N$ g! H- S
- }7 K& x& _9 Q0 }, t' \
- }
复制代码 |
|