|
|
) I" _9 D6 ]0 ~2 B行,这个怎么样. c4 C: G4 {2 `4 |% T
- package com.xhg78999.mtrfac.render;
) i Y& w& Q% {& L! [ V - [4 `* {& `' T$ x
- import com.mojang.blaze3d.vertex.PoseStack;( U# T/ F. N' Y) Q! F: ]0 U* p
- import com.mojang.blaze3d.vertex.VertexConsumer;4 @( V) Q; u" E- W7 A
- import net.minecraft.client.renderer.RenderType;$ Q. }0 }, X" V- g* j
- import net.minecraft.resources.ResourceLocation;9 P! s7 @8 x* Q! ], H- W- {' K
- 7 F! h6 r) `0 f# D% s* _0 C- O) n
- import java.util.*;
! |$ r# x; t4 ^ - ' w' F! L9 D3 D ?0 K6 }
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) m, a0 D8 Z3 w; r, i% T. ? - , _; X6 h+ `0 X5 e; ]
- public class LineRender{0 i" G# k# I3 j* _# S- q0 G
- private final PoseStack pose;
& v7 ?' ^3 k2 J+ }, { - private final MultiBufferSource source;
- |# j8 @- O2 L( W$ H! d3 J( o X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, q, y3 G+ U; o- W+ I - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 N* | S8 F5 J) `% j: B. {
- - q" L: D X9 S9 B& l" `5 o5 ]
- 6 |$ [6 M8 U! B' i6 _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 y& U9 R; s X+ K% O# U
- if(x1 == x2 && y1 == y2 && z1 == z2){
- J; j- g- C& E1 i9 f5 a, r- r - return;1 Z U, E5 ]# C
- }
2 i) g! O4 I0 V8 i6 }! I - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){4 z; C- F0 O# L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 W5 s4 r# R O
- }
( k( J8 U9 l: w. h+ w" M - pose.pushPose();
6 Z& k+ \: r* O- J8 p - final int newLight = convertLight(6);
0 O$ s+ H1 I% p5 z - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 p0 k4 n8 Y3 b - final float lineHeightSmall = (y2 - y1);3 u& G& B* g! Z/ j( L, [
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- X/ `4 \. {! X7 p+ d/ Q l
- pose.popPose();
9 {3 M/ F$ I% M - }
; o9 y. w. H* T
: p5 v% U1 ~# w' t, e4 D) k# n5 b5 X- private RenderType getLayers(String texture, int light) {1 ^ h& T3 F4 o/ Y! v6 R
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));6 Z6 s ]7 z" Y* k( }$ Z! z
- }, ?$ v+ M+ I& o! H6 |$ Y9 R
. j( S, ^! G, y0 E* M; O) I+ d- private RenderType getLightTexture(ResourceLocation texture) {
5 {1 f& L. B4 O* \8 t+ y$ b - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; q( n( n$ E! t$ @. D" r* G" { - }
: L/ v8 b; o* H% A: W
3 F# D, `* M! _/ S! E2 X3 J3 T7 Z- private RenderType getTexture(ResourceLocation texture) {( a) b. v' e" d! s' z2 w" b, @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. d5 I9 ]. ]+ ]8 T' d' u - }
; j) G) F( w. i5 D0 _: d5 \ - p3 z/ _- r4 h) s4 ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% g" v+ `( ^$ ` d8 C. b, q - if (cache.containsKey(identifier)) {- K! H* d; o5 i3 q8 c0 k2 K
- return cache.get(identifier);
8 Q& m8 k- b) p A. T c" q# X - } else {5 X- D, I z/ @% P) f7 \# V
- final RenderType renderLayer = supplier.get();- F8 m8 E. g' U0 D/ s$ Q8 o& {9 e
- cache.put(identifier, renderLayer);4 ]5 t9 r d) o# W
- return renderLayer;" d1 }! [) N9 X% w
- }
& f4 n; U$ p; f - }
5 |# k: ]( } Y. a- s - }
复制代码 |
|