|
|
, Z$ i+ ^6 @. f8 r2 U3 v9 _9 x' K
行,这个怎么样
; ]7 p; k" x) p/ P; B7 ?& k! H- package com.xhg78999.mtrfac.render;0 V+ h& c# J1 B% d1 F6 r, D
- 9 S' D5 ~8 _/ m4 `& P0 ~6 o8 S
- import com.mojang.blaze3d.vertex.PoseStack; e f' p' F" z/ l q+ ]6 {
- import com.mojang.blaze3d.vertex.VertexConsumer;* D3 P& M) U: O" ^
- import net.minecraft.client.renderer.RenderType;
* r1 O7 f- _8 I4 ` - import net.minecraft.resources.ResourceLocation;
8 b6 `$ T' O' L( p1 C) a q# w - / |$ j1 P) T8 r3 @/ A
- import java.util.*;- z1 b6 l7 R+ ?: @1 x$ }; n
- ! Y( l( y& J y, L. ` O
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& F* [: z4 o1 M5 X+ M
: z7 y m( K6 x8 P' K$ X- public class LineRender{- w- `5 H9 u/ B$ }2 r$ a+ M
- private final PoseStack pose;( k4 t5 \ D4 K/ P, k/ b
- private final MultiBufferSource source;+ }( y/ }2 e2 i1 i) C _4 v, [) r
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 k/ N- b( ?4 i+ H8 Q& P
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 q& f. g3 Q# E
; Y; y" @( O5 j
% E% |) p7 p% E- a- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 }. _( ?+ D( y F9 r# \: U3 @
- if(x1 == x2 && y1 == y2 && z1 == z2){ V6 Q9 j" H+ T
- return;# B& x, ^/ ?# n7 y) B) U) H( K# c
- }' l6 o: Z% w/ t; O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){) g N# [' ^1 O
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 B0 g1 z0 G6 t/ z) K - }
7 e6 b7 T3 s7 n/ p5 V/ Y! k - pose.pushPose();# U! g& i# n9 n ? \2 p
- final int newLight = convertLight(6);. [( K, ]& W) X2 ~) z0 ?) ~. I9 s- W$ }
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 D# \1 p; w$ |: Q6 E
- final float lineHeightSmall = (y2 - y1);
5 H1 ~% J; A% t0 { - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* g; N: Y2 |) P5 E+ X
- pose.popPose();
, p+ a2 L# K, |7 y& v# |) s5 t - }: _8 O) G/ @! P) D
3 V- S/ x/ f$ l0 Y$ m) o6 A- private RenderType getLayers(String texture, int light) {
7 `8 O5 |/ n! F- Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* O7 K3 e9 E' L# a
- }9 g) s p4 |8 \4 W
; E+ P- w# t6 a( Q1 r$ }. n: L& }- private RenderType getLightTexture(ResourceLocation texture) {4 R9 z" S1 C/ L3 I- [4 U. ?' x/ U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 L$ J. _/ @4 H) H5 G! ?
- }
6 _2 F9 l+ b8 F9 v4 L
- e( j2 N0 v5 w6 H+ e2 o8 x* i- private RenderType getTexture(ResourceLocation texture) {
4 q# l Z" S( H% n W/ h# s# @ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
T0 t5 h1 b3 {* o2 z6 | - }
& E8 H/ ]( n- b! J" p/ c5 I( y7 Z- n
8 I1 r+ |4 @* i5 p, O# _- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { q9 m/ \; l9 A7 J7 @' p% i
- if (cache.containsKey(identifier)) {
6 E/ Z6 l7 C+ _: ~1 E - return cache.get(identifier);
- A! {3 X; U% y/ \# S3 J - } else { e* D6 |' h. Q
- final RenderType renderLayer = supplier.get(); x* C L6 t3 I
- cache.put(identifier, renderLayer);& u' d' v- ^3 `4 [* C( a* j9 p
- return renderLayer;
" }6 G. @* D4 H- s4 | - }
( j5 ?1 P, m0 y5 o3 y# q# m7 y8 b - }
; V+ c$ w! }/ S$ B/ `/ k* m( G& K9 t - }
复制代码 |
|