|
|
% e: q* b. i* M+ m) h& i& s0 o行,这个怎么样
' Y/ [; x: [7 R; _- package com.xhg78999.mtrfac.render;' w% j9 x7 j+ y0 V6 }
- ' l! r3 o$ H5 G9 ]( C' Z
- import com.mojang.blaze3d.vertex.PoseStack;
@2 R% b/ l2 H - import com.mojang.blaze3d.vertex.VertexConsumer;) i1 ~& P4 F" w3 X! R
- import net.minecraft.client.renderer.RenderType;
% S. P$ w X% d8 K0 J - import net.minecraft.resources.ResourceLocation;
4 _" X! o4 W1 {. ^8 Q
8 w+ v0 ]7 C( w1 Z2 Z a: m; N- s- import java.util.*;. `5 Y0 N- f' u9 v$ C6 }
1 m( l$ Z, |; R Q. _: Q+ j* A5 P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 Y' m' M$ l9 j" V8 y
2 E6 f& S; I" X+ K" H: |2 T3 ~$ j: i- public class LineRender{- Y0 V& p5 n" h; G5 X2 J5 C
- private final PoseStack pose;
6 l+ I4 J0 l5 I- c2 p* N- j - private final MultiBufferSource source;
0 y" Z4 i" v% R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();4 L% K w. A' h+ {0 j6 S: M; T
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: b# r% I( \7 G3 v
$ Z# E- [' u, o6 s# R/ W# ?, t- 3 i# x5 A7 B8 R" X& g" Q
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 A6 D( m) A8 P% E( ~, b
- if(x1 == x2 && y1 == y2 && z1 == z2){3 P9 D8 B6 n1 O, t$ u2 n
- return;
8 M' j. \# Q% w2 }. j* v - }. h+ ^3 E* g( u& j T$ [" v
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! ~+ T) I9 M: P7 }! E: J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) J$ d! }* k3 V' l. S' U* b( Q
- }* Q! J$ A0 i/ w5 C6 {' O
- pose.pushPose();
9 M) p8 s' E! Q - final int newLight = convertLight(6);
6 E+ @8 w! ~$ h: p5 M - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 A4 V/ l3 U2 b5 W t* L
- final float lineHeightSmall = (y2 - y1); B2 Y6 ~3 U8 `& l5 G9 R' K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; l/ k8 T; x) w8 n+ Z& ?, L& X
- pose.popPose();
S c, x6 [% F; z4 D - }# ^5 a; L7 Q' d3 {3 P, }
5 h3 `- V1 `. y; V; y f- private RenderType getLayers(String texture, int light) { q! H* }) A% p
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, Y* y0 ]" a4 k- Z/ f
- }
1 `$ Y6 F; C# t" g+ J& C0 l+ D - . x* a' {! F8 a" H
- private RenderType getLightTexture(ResourceLocation texture) {- O+ F# p7 d7 K& k5 r k6 f( b5 C3 P
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" Z. {# a# K/ o$ n0 ~ - }
3 |+ i0 |# M- ?+ o - $ v3 G4 ?5 D3 @$ Y: P0 [) I
- private RenderType getTexture(ResourceLocation texture) {; h' H- i. T6 ?3 n1 E8 b* V- a
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# z; @1 N$ `. ^% @* ]: ]
- }4 Y$ ]* x9 `- e. L) P- A
2 Z* G& F+ r% e1 Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' K" y& ], E3 T" n x - if (cache.containsKey(identifier)) {
/ c6 G; M- x" M) z - return cache.get(identifier);
C' Y6 v9 a7 C6 B0 q( D* m ? - } else {. s n$ C# ~( [1 S2 ~
- final RenderType renderLayer = supplier.get();: c' L: G; F, o4 n! b4 S+ r; W
- cache.put(identifier, renderLayer);) c+ l( {- E5 ]" U* w. q, B
- return renderLayer;/ P5 D( d) w& ^0 V" |5 L3 y0 q2 H6 @
- }3 b$ a- X4 a/ }; o: ]9 S
- }
# r6 w% E9 n9 e/ e# n - }
复制代码 |
|