|
|
8 k7 A: D/ W1 F行,这个怎么样
- g0 A( b, d* ?- ~, }4 U- package com.xhg78999.mtrfac.render;
$ y/ {) o5 i3 s9 H. c& d - . Y9 \6 S @! H/ g# J7 b6 k2 B. t
- import com.mojang.blaze3d.vertex.PoseStack;6 V8 [* [& v4 V$ |+ B% F
- import com.mojang.blaze3d.vertex.VertexConsumer;
* G a, [) z& G% ] - import net.minecraft.client.renderer.RenderType;
/ Z8 }) M) d K# Z0 ^ - import net.minecraft.resources.ResourceLocation;8 T9 R% L) x( F2 C2 f9 K4 X$ t8 }
7 x+ J1 q* G' x& J( m- import java.util.*;
* E/ Q X6 Y1 V: Y
0 v( k* w( H. C9 f2 Y. F# q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) ^) o7 Y( y$ I5 F% L+ G% }/ @
! [/ S0 N7 ]( W& i7 `9 J5 j% e- public class LineRender{" |5 e9 q d7 Y3 ^
- private final PoseStack pose;
L4 F7 x$ d# ?- v - private final MultiBufferSource source;2 o- J6 x6 o. N+ J0 n# x# Q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( ?- |5 w! r/ O& g& H
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, B" m$ M A' @: k" p
+ K5 _2 t' Y! I t- . g2 ~( i$ D$ J) r; K& ]" }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. c7 [1 v$ h5 E - if(x1 == x2 && y1 == y2 && z1 == z2){
( x; q4 x6 b- _- b5 b6 a, P0 A - return;, E6 W, \5 b3 b0 |
- }; f& f8 w! u+ `2 f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! {. g5 e& d' W
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. R$ n6 U4 C1 V+ I% o
- } W% N0 @$ S# q) j% H- ?4 C2 p
- pose.pushPose();
/ L! F+ D7 u: @: p - final int newLight = convertLight(6);. c6 q0 x: u& t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( i- L6 M3 B; K5 E3 l: g4 w
- final float lineHeightSmall = (y2 - y1);6 Z4 y3 H7 s3 |
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% `, H" W; L9 T, i - pose.popPose();
) c# `+ Y3 l: b) ]$ l - }
( h4 _7 A1 J+ ]6 o* e9 F - 1 V6 v0 b( y7 M2 j& T5 Y
- private RenderType getLayers(String texture, int light) {
- r! i5 c/ r t6 T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; _5 m2 ], c6 E, |& ~
- }: I( N4 [) W) F& ^- n# L3 a
# ]6 G) F1 o% _: L$ ~- private RenderType getLightTexture(ResourceLocation texture) {; V6 a: e8 A4 H6 a/ ~7 K' E, }2 {
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' P k5 s* n9 m2 |
- }
1 X5 a5 T: q; n- ]& Z5 J# j, z, w! J
" n$ S( G6 b' R+ P! `- private RenderType getTexture(ResourceLocation texture) {
$ W4 {1 D& C: s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 W# k1 j* x! @0 O2 {( W - }# y: a# @, V6 l6 C$ W* ~" j9 |
; r# z+ [6 ^7 ^% `% d6 E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 H2 a. R. F/ \4 b, o - if (cache.containsKey(identifier)) {9 Y# K+ g2 {1 l; a
- return cache.get(identifier);
{2 N) M$ ^8 b0 \& z- N - } else {
. m; y! o% x3 @0 i( |- S8 S$ S% B - final RenderType renderLayer = supplier.get();6 L. p* D1 F8 C* N% J
- cache.put(identifier, renderLayer);( b1 ?% B/ L/ O8 f9 W3 E3 f
- return renderLayer;
* h3 Y& }3 T4 q- f$ y9 T - }
6 ]+ ^3 k7 p4 r" r$ y - }
, X% J! {) X. F9 a, y4 J! @. I- |4 L - }
复制代码 |
|