|
|
, `/ N/ E0 d; k9 n6 |% K- q行,这个怎么样9 R% }- R/ \8 c+ Q b+ T
- package com.xhg78999.mtrfac.render;% K, W) T+ S7 q, s8 p
" n8 k |. K2 x9 n3 M7 U2 {# }5 W- import com.mojang.blaze3d.vertex.PoseStack;8 H# v: b- R- y* \* U+ j2 m
- import com.mojang.blaze3d.vertex.VertexConsumer;/ ~ A- a0 l9 ?- H, J( P- A
- import net.minecraft.client.renderer.RenderType; N, Y' K% S8 @# s& S' a3 ~, q
- import net.minecraft.resources.ResourceLocation;! j) A+ g5 f0 C7 d2 I% g
- 8 m/ X- `" N+ j2 b6 F
- import java.util.*;
" S- C* B+ r7 G' G
7 P6 ]0 U4 c+ d, ?0 w. I( F- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ r Q! C* E g8 C0 W4 ^ - ; Q/ ^% K+ ?" r; u6 s' N
- public class LineRender{, H- Z n& F. u( f3 Q7 A- [$ [7 E" t- f
- private final PoseStack pose;6 \4 p, c& H4 M. V( D
- private final MultiBufferSource source;
" l. N e, j+ Z: ~ ?1 \ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 q$ W* v. H( Q7 D+ O b$ _2 Z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* b# f% }' t5 ]- v; T- V* Y - 8 i/ [5 t. g: a5 w, ^
- ! O. Z% M. ~- o7 X
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ B- Y* Z- S0 h2 O4 \$ H - if(x1 == x2 && y1 == y2 && z1 == z2){7 ~0 K3 f! A4 P$ p6 C% E- l( L
- return;6 W+ g' B( Y4 i7 K) {
- }
/ \& D( H# Z' ^+ V9 L2 M3 }* i - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ l- v$ j$ U3 f! J: K - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ l: c7 w) l& v, v/ p
- }. f2 x3 |- B8 N# h: z$ ]+ G
- pose.pushPose();9 N! E' a; s* f6 ^2 M
- final int newLight = convertLight(6);+ f4 A( a/ d9 D. n4 Y0 f# y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ I2 I- E+ C# o; O5 M: h6 c5 X
- final float lineHeightSmall = (y2 - y1);
3 M x! ~! S1 |3 e - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% h6 Y1 ^1 K; ]4 d - pose.popPose();1 J0 {* d" N+ z. z$ B
- }8 h/ d! s2 Y k9 [
" u" s! S2 A! G( j$ ]- private RenderType getLayers(String texture, int light) {
* U' v {- B p" v* X- q# z' G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; n" }# U( u, o* n! O4 |3 J2 Q
- }
; D6 f8 s# ?" P; r6 Q7 _
: ]6 E; @. H# I, M- private RenderType getLightTexture(ResourceLocation texture) {" {1 i) a2 d, D5 b$ k1 Y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: c+ u* B! G. V/ L/ s" S, H8 w: n - }
+ k3 L# Y4 S& ?/ k - & T. q8 x5 u8 H5 z2 a, E z# V4 Q; t
- private RenderType getTexture(ResourceLocation texture) {" G# m5 J5 I7 n) U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);) t' K: F: g) Z4 ^9 {& G9 D. V
- }
! l2 \- k. p; m5 o2 n3 B% I - - ?$ j }/ o& L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 t- K+ z# Y( T$ D( p
- if (cache.containsKey(identifier)) {
% e) g$ A+ t3 @ - return cache.get(identifier);3 n& ]* C0 \2 r: o
- } else {( \; y& ^, K) t7 m# o( _6 I
- final RenderType renderLayer = supplier.get();- o; E) j+ {5 o: m' u# ?
- cache.put(identifier, renderLayer);
; `# w. D9 M+ R* i7 P q: z - return renderLayer;
5 u; z7 b% d; x - }( N" S5 S7 K( @" @7 M
- }( d+ l& L# D# z' s; y
- }
复制代码 |
|