|
|
1 _1 e. } M7 l5 @# g1 j) ^" `2 r
行,这个怎么样
" h3 [; a0 J% _7 e# E |1 u, _- package com.xhg78999.mtrfac.render;
. m# L8 v6 v" M* [) @+ r! \( P - : x7 Z9 |% _, Y9 v! Y( u! q
- import com.mojang.blaze3d.vertex.PoseStack;4 ?# C; D& r8 _+ S" b3 N; m1 Y
- import com.mojang.blaze3d.vertex.VertexConsumer;2 a4 F7 j9 f1 S" j# H% z; v+ q
- import net.minecraft.client.renderer.RenderType;* C$ S( G, U2 D- {* T
- import net.minecraft.resources.ResourceLocation;' l$ [- d1 i/ M) V- B6 I- T0 N+ F
- 8 ~, i8 A/ q$ w# M4 R$ S
- import java.util.*;
3 r5 K, G- M$ W9 { O( e - ; W% k: _' a& w4 x: G: F9 G! @
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" v1 _, D# }0 {& |
; k6 e' j* |$ K. ^ y8 o- public class LineRender{
% J; ]6 ^& N# s* ^- j( q8 S - private final PoseStack pose;
$ u, f' O* r3 `2 l - private final MultiBufferSource source;* L; @% z) G6 m4 _
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 R w/ N$ n# Q, @5 y - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
7 ^ Q/ L% U: f& u1 o; u9 l
. U9 H' o0 w! b, }+ H0 f- # ?. X6 X: n# s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& p$ A5 ]: N7 s
- if(x1 == x2 && y1 == y2 && z1 == z2){
" i; C& P$ m6 h9 s, C L - return;5 s* V- U. ]) N& m: c: Q0 l
- }7 {! c, C* L! `! `; y5 T+ X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: U; Y0 l K% o" ]7 D% F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
' h; x* ]! o' r - }5 ]3 u, A. v" ?
- pose.pushPose();2 P' J3 p) i2 f; I
- final int newLight = convertLight(6);
$ k# ^( d2 ~% C& P0 M$ W1 ` - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ B a4 y/ W! t
- final float lineHeightSmall = (y2 - y1);
6 e* \- S- Z' k. H - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, ?8 w7 W: G# W$ T/ F6 P* P" }0 A
- pose.popPose();
0 L) i7 C5 B# `1 B5 p, ^ - }
! n6 l) r) p) i6 _! ^" t, q - + k) Z/ |; b. M' o8 s) a
- private RenderType getLayers(String texture, int light) {
& t( J R. k# t! W+ V" I/ A - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 |9 ^0 g. G" K0 _) k* b
- }+ T; n2 [4 c/ I& Z/ T
& K; r4 P3 @1 _- private RenderType getLightTexture(ResourceLocation texture) {# z3 Q: S) `& ]* u& i# i
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ l6 G5 [8 P/ p1 h; N0 F1 v1 h - }
4 ?9 H1 o+ W& O1 B+ f! ~2 G5 X
4 Z. v, j( g6 n5 B* g( V% j- private RenderType getTexture(ResourceLocation texture) {
( p, A; `5 m7 K6 W | - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
b! B* N, I4 ^" ?6 O - }
5 W- X- k0 H+ q( }. f6 X5 Q
4 K* |/ ^; t9 r* J) v! m- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 O9 m% j6 b3 k - if (cache.containsKey(identifier)) {
/ D, D [. V3 h X2 y9 g - return cache.get(identifier);
. i9 _9 O1 f9 a- w. L6 S7 O; M - } else {& o1 p7 V0 g5 x4 U% R. Y/ P
- final RenderType renderLayer = supplier.get();
7 I$ ?- {$ V. F* ~ - cache.put(identifier, renderLayer);/ W, s; F- e7 Q
- return renderLayer;
8 F9 c i; L5 L% {- z. ]. ]% L8 z - }
5 ]4 q8 I: Y- m7 i - }; q! ?0 n; Y. g2 n) h
- }
复制代码 |
|