|
|
8 _3 {; ]$ k2 j5 |行,这个怎么样
. N/ o9 [. N, F) t- package com.xhg78999.mtrfac.render;3 A" x0 D) r4 r
- & `2 K3 D2 m) O
- import com.mojang.blaze3d.vertex.PoseStack;
3 @* @3 o/ }4 Q2 C: c% e% Z - import com.mojang.blaze3d.vertex.VertexConsumer;, P' q) z' k9 e/ l7 `' E* A l) Q2 H
- import net.minecraft.client.renderer.RenderType;2 r" }! b" J8 y1 L- @" U* S5 n
- import net.minecraft.resources.ResourceLocation;
- |' a+ \5 H' I& d& a9 B - ; h! {" u9 E1 z' K6 G
- import java.util.*;
; v) o- K1 V! \, |; Z
y& L0 {# N" Y2 G0 v( _. m- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, b% E$ u# j/ @* N- l1 s- X. Y - 9 X5 W T5 o+ r8 @7 N- c" B
- public class LineRender{4 ?$ r. G5 V* @; C2 `- g6 E$ _- o
- private final PoseStack pose;" |* T' V8 u8 g4 e
- private final MultiBufferSource source;
1 Z7 ]8 l% \8 m$ e: h5 X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ @2 d, y" C! l( U - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 J7 Q9 N" |4 w) u - 2 U) ?1 d1 D3 w; D
* W4 r0 c; a0 B8 D' X# N" d- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 H5 Y4 Y9 L2 T$ Q8 q, v
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 a+ b/ U" J Q* G - return;* Z: m5 J# y* f; z* g
- }
3 F' ^/ ~" b5 u. a* v& Y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- ?1 c$ K1 l/ f( c% @7 R& @ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 O2 k4 D, t( h& Q% M/ H& A9 y
- }
" _: H/ n: ?. {& W7 Y3 i3 ?8 J' F - pose.pushPose();
. F5 X* z0 {' \1 a - final int newLight = convertLight(6);
- D; M9 F! I8 `8 t, H" X2 M* l% h - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( A% G8 k/ }5 j$ _# v! W ?
- final float lineHeightSmall = (y2 - y1);
2 Q0 ?( c! \7 n5 K - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 {1 z6 C# |4 h0 o! L. E6 r
- pose.popPose();
0 ?; g9 \7 h( }' ~. j* \ - }
1 A+ S; F& |6 e: c0 P! W4 F3 C - . G4 P. p5 m: F/ f. U- t0 h8 {0 G
- private RenderType getLayers(String texture, int light) {+ l$ D4 ~3 L3 f! j, z* }9 Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) M4 t. h h j& a L, U
- }! j) L3 c5 b" Q4 s3 }$ z6 @
, K; T" W4 E. ]/ Z# W- o- private RenderType getLightTexture(ResourceLocation texture) {/ q4 i) M* \2 j8 \& D
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 n' j; d; v" a- D& Z' q3 p2 V: k - }8 ?1 f6 w! o: r( T; T, s
- 4 ]4 E8 g$ w* p
- private RenderType getTexture(ResourceLocation texture) {# [4 s! K6 m9 C5 }, m
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* w" M# V$ M0 l" s2 I* B: @ - }' J( V" N9 O! v* B
# W! L% o! ^5 M- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 k, S5 q8 N$ O1 [- y, m+ _ - if (cache.containsKey(identifier)) {. L9 x. P, _6 f" y6 H( q+ v
- return cache.get(identifier);
; q G5 l* W( m o; S0 y# p& T1 C5 K - } else {
% `: \. v! ]4 z+ D# k$ j1 o - final RenderType renderLayer = supplier.get();
t, j% z' e0 h4 W% c - cache.put(identifier, renderLayer);7 O) X+ h+ s: |8 |, U
- return renderLayer;1 e' l6 E* ^8 I" K; k9 B
- }
- D9 j% n8 d! Y4 s& p6 ~ - }; ?! F9 A$ U' \: g @: N7 O
- }
复制代码 |
|