|
|
4 p+ Q, l {6 t0 E
行,这个怎么样
: E, G# R% }3 o% @- package com.xhg78999.mtrfac.render;
~- s2 `. F O y1 f - : K3 A% Y* K: u9 L# v
- import com.mojang.blaze3d.vertex.PoseStack;
, `. l8 X) j c) L - import com.mojang.blaze3d.vertex.VertexConsumer;
/ @/ Y" |: f1 T2 c( c8 w - import net.minecraft.client.renderer.RenderType;
, I5 i5 O3 a5 k. a' R - import net.minecraft.resources.ResourceLocation;1 W* ^! f0 s4 n7 r- u! @$ V
- % ]' Y) c; h- E- ]3 R
- import java.util.*;0 f2 a5 |5 {: D$ |9 L
/ p" Q, _ z6 ~7 Q" v2 F* U- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; i5 s$ T; i7 c9 l( Z: X - , U: k1 m! ]' j6 R3 B9 l
- public class LineRender{
# O3 I0 w$ t& |) ^ - private final PoseStack pose;
$ q/ N( M5 v4 F - private final MultiBufferSource source;9 s0 p$ b1 d/ F/ e9 I4 w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: H: L: h K1 h6 {! W8 v, g$ z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' X8 u7 P" C" Y. G3 q5 W% A+ ~
' {2 w6 {, B4 A- x* o, m6 T; k1 b
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 k9 v$ e4 c% A0 p9 @9 a# p
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 ^4 q8 {! y4 D: k$ y0 Y1 C8 D - return;
, u# a( u1 q$ k0 d( O1 U - }
& |1 l& \- ~) o# `' _) e - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- H" ? N( R7 i) [2 T - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' s; i+ o2 v5 `2 X9 D, K9 D
- }" O7 o- q, g* z3 ^
- pose.pushPose();
( k0 M3 `! ~$ U5 J. c7 A' Z - final int newLight = convertLight(6);
4 L) t/ o$ x/ _' t: B) V6 b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 `% R$ S% a5 D/ z! ~( g - final float lineHeightSmall = (y2 - y1);
% y0 ]3 A# `! A2 k( Y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& o2 H: G; R* E - pose.popPose();" _( h% Y6 Z- C1 o5 o
- }
; p! A5 N3 D3 f a! o- E& _1 K
! Q# {9 r% l& u- private RenderType getLayers(String texture, int light) {
7 G5 b! a- r `1 ~! T& H1 l6 S - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));. O- h( a6 n7 l' _5 v* X F
- }/ x! `) ?% u# S
- ' H% Z- F& s, i+ S0 ~" o$ ~7 }% n
- private RenderType getLightTexture(ResourceLocation texture) {
, K; b& Z9 x$ u8 D& ?' Q6 ? - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, P0 i5 g7 ?9 e9 g2 {$ ^ - }
2 _, o' f8 t. [8 x - 7 _9 w% s2 {3 Q7 M; e6 c
- private RenderType getTexture(ResourceLocation texture) {8 Z3 h ?0 U0 h0 w) h& s) T) E
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# z! K* Z% b, D% G
- }
+ f N; N2 T# i7 Y5 g- w, O - ) {9 {. R" r W6 n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
- p6 i! ~, a5 [6 K- E3 Q - if (cache.containsKey(identifier)) {
+ z' J( W* s- s1 G ^8 q5 Y' i - return cache.get(identifier);
: ~1 S9 R ~4 [ - } else {
8 [2 I9 j7 w$ W& Q: B - final RenderType renderLayer = supplier.get();
# I* Y) r3 b) H# p - cache.put(identifier, renderLayer);
% ]8 v ~0 i% ?' G+ ~ - return renderLayer;
, @1 g3 R% C& v9 W* \* w - }
7 t6 @' ?+ l, G j r& U - }( l. @8 v& j* @7 Q& j. N9 d
- }
复制代码 |
|