|
|
6 o' K1 w+ A. Z' Q2 I) V Z. U
行,这个怎么样
; i( h- f% X+ Y; X8 h" D- package com.xhg78999.mtrfac.render;# D, V2 f9 M; l5 e# v% |
- # c. e" ?6 J) k3 W8 P
- import com.mojang.blaze3d.vertex.PoseStack;! O# d' `8 ^ [. j3 K
- import com.mojang.blaze3d.vertex.VertexConsumer;
) F- ^: ]# _/ } S, Z0 S - import net.minecraft.client.renderer.RenderType;
* a. H2 P0 K9 S/ `9 w - import net.minecraft.resources.ResourceLocation;
, H# _1 T' ]0 q1 C" }0 C* D - : r {6 a/ n! N. ~+ A4 I, B' v( {; X
- import java.util.*;
. G G& X- p& p
- o3 W. I5 {) F6 k- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, Y q: t; p5 {1 M5 @4 M7 D
- : l! p: n) |/ q( ^0 P8 t7 P* d3 K6 B
- public class LineRender{' s/ J8 W( }1 x9 N
- private final PoseStack pose;* z' F4 K5 f, a( l( {* A
- private final MultiBufferSource source;+ @+ D: `8 E& h
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 M/ j, A: l, j' I% j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% ]6 `3 g4 v/ t B6 h' P - ' c3 O3 D7 y% _) ]) I% }
2 d" E2 f- k6 `. S2 J; x- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 _1 K* [' i9 p7 B - if(x1 == x2 && y1 == y2 && z1 == z2){5 d3 [8 w+ x( c& J' j
- return;
3 ]. L" D# Y( O$ N - }+ a/ g9 M: i2 l! J3 T l; @$ T
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& f# U! W$ `; J# E- N - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); R) O$ L2 X. W, |& Y& y
- }
! o9 X& ]1 z, C - pose.pushPose();
/ z% o& W4 O* d* t* A1 N - final int newLight = convertLight(6);
9 O1 _9 _2 r7 `4 J6 d* p - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" Z& W, j7 W6 k2 E/ L+ Q$ s - final float lineHeightSmall = (y2 - y1);
& N0 I" V h4 |( a - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 h; Y$ j& a% d( l, R2 b
- pose.popPose();
& V4 l0 r& p/ e. q {9 q - }
% P v& |& e* s) w - ' q, t* X3 ]6 ~9 P+ P& M0 V
- private RenderType getLayers(String texture, int light) {0 ~. x" J" K) H0 ^; U+ h
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# I& I3 e, }6 I% B6 Q
- }
( i! Y1 A, y, A! ^
6 E5 c4 R: U3 I4 {, L- private RenderType getLightTexture(ResourceLocation texture) {5 m' ?2 _* [0 D1 \, Z0 l' i9 |+ o
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& ~- }# Z% k/ [8 w5 n7 u
- }
, C3 | A( i- f% c" ]
5 _. Q( \( z( h3 a7 |- private RenderType getTexture(ResourceLocation texture) {
3 x7 F2 `# p0 k5 [9 H - return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 e' ^% u9 Q. ~" D0 e- D( j
- }/ ?( a9 H* D3 Y. d/ V* h
2 j1 i$ N; h+ w. m# F- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 }* ~/ I6 ?4 Y
- if (cache.containsKey(identifier)) {: N! w8 |6 N+ \% f% D4 c" B% z
- return cache.get(identifier);
0 [% t$ k8 f! s6 t, v: q/ [ - } else {
$ L! l' S- T g- X0 F: j! f - final RenderType renderLayer = supplier.get();" c! Z& E4 u; B/ C" c
- cache.put(identifier, renderLayer);" |6 `& N0 h0 X& m/ [
- return renderLayer;
( s% d; e9 B' ~2 m) n+ N& j - }& |8 M: M: k! ` V, ]! {
- }- {, l0 b2 T {+ A" c! j
- }
复制代码 |
|