|
|
9 \) x$ k# p0 _' X. w- t行,这个怎么样2 @6 P5 [+ X8 X0 |# S0 n# @8 S
- package com.xhg78999.mtrfac.render;$ P& N2 Y S y8 g( F7 O" ]
- " D3 O4 y3 G- e( g g" R
- import com.mojang.blaze3d.vertex.PoseStack;
" Q+ a4 Q8 ~, c, ]: O) V - import com.mojang.blaze3d.vertex.VertexConsumer;3 h" O& H" a8 Q% W
- import net.minecraft.client.renderer.RenderType;
0 A# V* o* J, @# ~2 ] - import net.minecraft.resources.ResourceLocation;) L5 T8 L! k! H0 u
- 2 k! b* e- U" K. O6 V
- import java.util.*;2 `+ V* W7 } Q( n
- N2 f9 `$ e! u% `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# D+ A; Q9 W0 M+ A7 U
6 @ ~ B" k O; e f# g( g2 t" G7 D- public class LineRender{" ?/ {- h8 ^8 b' M& f7 r, {
- private final PoseStack pose;+ R5 f3 O9 b. r! X5 G
- private final MultiBufferSource source;
7 i3 }7 E, o7 }' B4 w - private static final Map<String, RenderType> CACHE_A = new HashMap<>();# r& p' |9 H R8 ?7 W3 O2 Y1 [
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 n w( u9 J0 C8 t4 f, t2 d( t, y* [
- # u2 O1 S: d8 q. X( k
- # `5 e( @3 A2 s* R+ `5 s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 u8 I+ t6 V+ J% H6 K; B( g }) d) w
- if(x1 == x2 && y1 == y2 && z1 == z2){* e$ i7 K0 ]) G2 M" o1 W) H) z
- return;
0 k% D+ b+ z7 v9 ~0 O/ [0 z5 U7 Q - }
) `2 n( G4 D5 g2 L& ?* k! `% j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% X$ P L+ i* d
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' x- `, q+ `0 ]; M. x
- }* _3 Q7 t9 v/ U) y. f
- pose.pushPose();+ ^+ H0 e2 A& y
- final int newLight = convertLight(6);
% F/ r+ |/ H% M$ G7 h% \) [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ I4 y6 \5 |, { G - final float lineHeightSmall = (y2 - y1);
3 U* C: o, ~$ [& ] - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 S7 ^* k+ j% d2 o: S) x1 j* _
- pose.popPose();
0 |& \- p( \- ]: L6 N% R& `$ W - }7 ]* I$ [9 r2 g$ {; `( [% V9 d
! y Z+ |$ ~& g {. j- private RenderType getLayers(String texture, int light) {/ q- V( w' \' s" k4 Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' O9 D2 T; m7 ?5 ]% B" f& \5 g: Q9 ^ - }( I: @4 ]" h K* D1 c+ a
- 7 A0 F" U. k' L$ Q o# }5 J& y& s5 p( U
- private RenderType getLightTexture(ResourceLocation texture) {
% L, p) g- |4 c" V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; \% n) f& _' V- P& D
- }$ w9 k( [: |4 ?( i( I$ }8 k
! p" X u3 x4 `$ ]: F- private RenderType getTexture(ResourceLocation texture) {% ?. T+ J2 c: Y" ]1 `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
@2 a: s' H, I M( e! Q2 P' \ - }: |: i0 |; t: U5 w b. I4 {8 r8 T
- - i( ~- b$ w( B- w4 p
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
9 ~3 Q, a; E5 o, \; r; [ - if (cache.containsKey(identifier)) {/ s @" V* H* g9 ~
- return cache.get(identifier);$ U1 q/ O, H9 B1 E
- } else {, P2 O7 _# H3 r' \! j, i' x$ ]3 t
- final RenderType renderLayer = supplier.get();& v; u7 |. ]8 a& J
- cache.put(identifier, renderLayer);' F# l! P; p2 p, i m7 V$ _
- return renderLayer;+ V' X$ A% E" c6 }
- }7 E7 _( a. n* L) \4 p
- }" J; v. \* I2 n5 C
- }
复制代码 |
|