|
|
+ @9 v$ S: z: _ T& m行,这个怎么样
% z8 \; ]* T6 a- package com.xhg78999.mtrfac.render;
! [3 c0 X/ q/ O4 L/ k - 6 u0 I4 B! G; w5 J* p8 h8 H
- import com.mojang.blaze3d.vertex.PoseStack;7 S" r1 _* r9 k; E& @
- import com.mojang.blaze3d.vertex.VertexConsumer; ]! @$ G6 x4 g6 K6 _# L
- import net.minecraft.client.renderer.RenderType;
" A7 B1 e' E @! j3 I' Y; A( q0 u* y - import net.minecraft.resources.ResourceLocation;
: h1 w0 `: v' J, v" z
4 m5 \, x: ^: v8 E* V+ J* j- import java.util.*;. Y7 R+ G' @$ |. V& i' |
6 [0 R, X% o7 c/ N( Y1 l- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ D4 e- N: G) [
* G S/ \/ b4 u; X7 V9 D4 T5 G! }8 D' o- public class LineRender{6 j) a( B' u# F- @% |$ ~
- private final PoseStack pose;# E% }. n z% F {
- private final MultiBufferSource source;
: I3 N2 z) E/ m7 w - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& m9 m9 T% a. ?" |2 L j+ u - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 l. c b& P% q& I
- 5 \% r- ]0 _) l- Q( b( s% q) D* M( G! E
- 0 h9 N- t4 m3 \+ K& R3 C
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! i4 S, Q0 ~) o
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 f5 ]: n- p( ~" C& k - return;
. c- O/ Q1 o$ a( R# q- K - }' l, K# L0 v) Y& N$ F
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 G8 Z1 K. o% n4 [" [ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 d! \- m; T; R5 a7 C# N+ \( @ - }
3 e( R3 R& W/ Z; R0 W& P - pose.pushPose();" b8 W. b* F9 N0 \ H' n5 C6 b+ T
- final int newLight = convertLight(6);
8 B4 B; i E$ }& B m( G' h7 L - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! F7 c" r0 ~- p2 r, W - final float lineHeightSmall = (y2 - y1); X* V/ B, L7 i- |! }
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ s& m" T0 u# @ `3 N0 k# y
- pose.popPose();
7 I% {3 W# L2 o6 K9 b; F. u) m+ \ - }
+ v; S0 R7 z0 v/ K/ Y. U$ f - ! [; @0 a! l+ [
- private RenderType getLayers(String texture, int light) {
. Y, f( i* @( V' g/ G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 \1 v% E, x! }
- }, m8 S, ^% T* l. ^$ W& S
- 1 W7 U7 b+ y% J& [
- private RenderType getLightTexture(ResourceLocation texture) {! h2 G( O) I- I8 ?7 ^! O3 ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& K2 E; Y: ~2 y d' c - }4 p; X; p3 a$ I8 {
- ! Q7 ?! Q1 J6 U4 c/ b" m. m
- private RenderType getTexture(ResourceLocation texture) {* C% H4 |2 l! K) p4 F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 q; u( [+ d" `5 ~" T9 Z - }
* R; E- K! a9 U( d7 N, D) S
- A- Y) ]7 L1 Y; i6 e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' `1 l& Z( ~4 K5 ^9 k- g - if (cache.containsKey(identifier)) {
8 q3 d* n f$ e* O+ } - return cache.get(identifier);( k* s, [. N/ f- J" M, H
- } else {
4 H* `! \8 v9 s7 Z. U5 d, d - final RenderType renderLayer = supplier.get();# Z( n; t6 u5 @( L* \' w
- cache.put(identifier, renderLayer);$ `0 N. X! h% D; W [/ S
- return renderLayer;2 u+ |6 o1 L. G; r
- }
n) Q8 z& o, d* s0 F9 G* [; T& R - }) J, f0 v# V& [
- }
复制代码 |
|