|
|
* E5 B1 i, A1 k/ W6 M
行,这个怎么样
% a: N" K$ D0 [- package com.xhg78999.mtrfac.render;
; O( Q, W# S8 {# @ D6 H
+ [& }: J% v: {' e! k- import com.mojang.blaze3d.vertex.PoseStack;7 R# ~4 Z( `* ~5 F/ o! C0 A
- import com.mojang.blaze3d.vertex.VertexConsumer;
f1 Q# q; J% F* l9 i. _: f - import net.minecraft.client.renderer.RenderType;2 U+ X( |4 o0 B
- import net.minecraft.resources.ResourceLocation;
/ W& W! r9 ]9 S - 4 Y- S3 J& X+ D+ ]: l5 S3 G
- import java.util.*;
0 s, |( Y. H" E2 z( o: S; c$ `1 X
9 n$ {8 J! ] {2 ^- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" w0 H- ~0 f) C6 I# ^ - 1 m: E+ ~2 s+ g
- public class LineRender{" j7 O* v* T/ y* I& u7 Y* \8 i
- private final PoseStack pose;. J/ s, g; Y" G: _8 n$ Q
- private final MultiBufferSource source;
; U& K9 a" i3 E) p4 S1 C. I1 L+ X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, Z( C+ E+ D v) {: v - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, ]7 j! T4 M) U
/ ?: A& _" ]1 D/ `6 b5 e9 |) t
# _2 }: Q5 R4 b- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ {( K6 b" z; j
- if(x1 == x2 && y1 == y2 && z1 == z2){* X+ B3 y) M* f0 {% h2 t, @
- return;
! k0 A. R2 x( M! |0 P* M3 q- k0 Y - }
. I4 m6 S% T7 ^% y8 W- C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 a. h, S& b$ w7 V* M
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 u9 X$ @' F( r0 P+ f
- }
" N9 U: V" _8 _$ k - pose.pushPose();
! }, t, P8 R7 g' B4 g2 R- C - final int newLight = convertLight(6);
3 d4 a, p }$ K# u - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 ~7 O0 I7 l5 W \7 _ - final float lineHeightSmall = (y2 - y1);
( H! {- h; G( K) J4 g$ W - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 a7 i0 m( L% `8 S. u* u, l* S5 d
- pose.popPose();
- X. I3 o: |% Z8 M: Q# @. Y2 m - }
( N1 n4 E9 a2 t% v
) }( S+ q% F% n- private RenderType getLayers(String texture, int light) {6 ?7 I# N2 g% t2 f% r* e: U* s9 K
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 [/ _' O8 M9 `1 ^, n
- }
" f+ i; y/ I* H, Z6 {2 A/ w8 v9 F
3 X) E3 e- z' b. j- private RenderType getLightTexture(ResourceLocation texture) {+ H0 J+ y4 G# u: A O5 m( x6 |8 ~0 S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: v1 f) u- o7 F0 U* s
- }( {# l: a1 F& v3 U
- $ E+ G2 Q; W( g5 Y# d& [% s
- private RenderType getTexture(ResourceLocation texture) {9 o% S* D$ @" _. J
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 _6 H3 B& \3 Z6 _9 z( y3 N$ l5 M5 d' v
- }
, ?8 f `2 V. F. T+ _' f3 |6 q
! u2 g: C- R A- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 [0 y( o( v+ M/ h% s. Q5 q: w
- if (cache.containsKey(identifier)) {7 ~0 B; V8 n7 g* z5 [1 b
- return cache.get(identifier);
: @4 H- I. n! f6 z3 G3 h% J - } else {3 l$ ?4 `. |4 ~! P
- final RenderType renderLayer = supplier.get();
% X3 ]9 ]4 i) W e# s1 x" b - cache.put(identifier, renderLayer);
7 H# u" O1 C" o - return renderLayer;
% n" m; E: @. z: N: Q7 ~ - }, x9 i6 d1 m5 J, S; v5 ]
- }& g3 b- s/ {5 r
- }
复制代码 |
|