|
|
' p2 }$ v% s# s3 e9 E' P7 X
行,这个怎么样7 f0 P6 U. V8 [; Y
- package com.xhg78999.mtrfac.render;
" t) z$ g% |) b+ e S0 d2 ^( g - ) D' `! @) W0 H+ ]# e
- import com.mojang.blaze3d.vertex.PoseStack;) b w( X+ V% P
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 s- v6 Y& N. c - import net.minecraft.client.renderer.RenderType;2 j9 O F8 C0 p% t8 m+ R: g) Z
- import net.minecraft.resources.ResourceLocation;
8 f: a0 L+ F4 S" C0 W$ @3 l: ?& i - 6 S* `2 v6 x9 a, b3 H1 N
- import java.util.*;
' \) J8 R! }+ n8 H
2 W+ h* s- d+ H2 }5 t- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 d7 U$ D/ o* I$ j& z n8 G- N - 8 i, r; X: o; d0 l+ w
- public class LineRender{, b) O2 t6 q) \# f; b
- private final PoseStack pose;
* h6 f/ T9 x" o: Z - private final MultiBufferSource source;& Z& v( c/ J& E! F5 y8 X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( X6 v& M* b) S8 V _/ L/ f0 b
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; p9 K( j! c: J$ ]& J# J
- % L7 q- @" s+ Y( r
- . y( e+ ?2 v+ `; Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 H1 [, r; B: `' x' @% k
- if(x1 == x2 && y1 == y2 && z1 == z2){( U: h- f% _$ D$ J3 J3 k
- return;
3 v/ V1 s; t* Q$ H - }
8 `2 D7 d: x8 a4 s: x# @5 g7 a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){+ m' k1 M0 o# d) O: q1 F8 a- b
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) H$ J a t. ]9 y" N5 W
- }
+ F5 @" g2 z& M: \ - pose.pushPose();
+ U% @6 j8 y9 G* d; o' @7 F/ o, b6 t5 V - final int newLight = convertLight(6);
" y/ j1 v; f* V; ]. b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 [/ i& N1 d& r7 d% q$ o
- final float lineHeightSmall = (y2 - y1);
! w; N5 }) u7 \- V" I! [8 O - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! s9 A2 O7 n# T. J$ L - pose.popPose();
, E ?7 }' x3 V+ H) j3 q6 I - }1 q5 Q; ~) P1 d% \% v3 z& ^9 B
- % w P- h# q9 }0 q" l
- private RenderType getLayers(String texture, int light) {
0 e, b4 `# m( _0 t2 {- W$ W - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! P+ W3 C& i: j; K+ s. q
- }
& h ?! \, M) ]% A$ d - ; H" u+ M( f# |9 T
- private RenderType getLightTexture(ResourceLocation texture) {4 K$ Y/ J" ^0 \3 V
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 \$ F" R/ \2 d1 X& Z5 {; Q1 i
- }3 W; k+ o! b+ X1 R
- ( z* ?; j1 E4 }. q- O7 Q3 W1 Y
- private RenderType getTexture(ResourceLocation texture) {- a Q- e1 I$ y4 h0 K- c* |" ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);8 f% B! o" a3 b$ L0 A
- }% G* A' L5 h( j" E, } r
- $ Z, O& g- f9 R2 [3 F9 W: n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' v, m/ p* q, b$ K - if (cache.containsKey(identifier)) {
6 w- E1 B. P% E1 ]1 i5 J - return cache.get(identifier);
1 G: w& P% H* F& W - } else {/ z% a( v7 C- P: n' l9 d' p" d
- final RenderType renderLayer = supplier.get();+ @5 q# O* e2 Y) O& M, g' K9 Y+ T
- cache.put(identifier, renderLayer);) o8 m/ f/ O8 w6 c& w; n" |2 L
- return renderLayer;0 j) C [3 F& C/ w, r* }
- }
/ {/ W6 _1 J4 a0 W7 N' R: w - }7 s4 c2 k: P6 l
- }
复制代码 |
|