|
|
) D1 L6 l' s o行,这个怎么样' B. m# }2 O( r3 T" c) j: R
- package com.xhg78999.mtrfac.render;0 A$ p0 R/ `' E4 |, |/ G
- 1 B' m- ]3 E6 @
- import com.mojang.blaze3d.vertex.PoseStack;
4 f7 ~) J% s4 G' D1 n - import com.mojang.blaze3d.vertex.VertexConsumer;& E4 H) ~$ z5 L/ B, ` M: v2 u
- import net.minecraft.client.renderer.RenderType;
2 F; F8 L/ W/ j( {! R" W! Z - import net.minecraft.resources.ResourceLocation;+ B3 T2 i% h r$ a* W$ r9 ?' P
- 6 M9 n/ C9 K1 b( E8 V1 n
- import java.util.*;. X3 s; L$ U+ l K
. r: K; Q3 ]; [: O' y. z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' u- }, n. J9 I( j; H+ E( D - * x# J. ` m4 @% V/ T1 u
- public class LineRender{6 x$ U, v6 K2 p; N
- private final PoseStack pose;9 I3 J) U' a: u+ i" }
- private final MultiBufferSource source;. x' [2 _ b, ~. u, y$ x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ ^& z1 d: p1 {2 |3 M0 T" D- N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();: Q# q4 H. f/ i& \6 Q% ^; K% b
$ s' [1 @. A9 L: u" ~- + V/ y+ P. y+ b1 f8 R. h
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' ^2 [1 _& W' M; X - if(x1 == x2 && y1 == y2 && z1 == z2){6 g/ d4 E* ]0 n7 V" Q3 ]- K4 }- m6 X
- return;
' Q( c" D# c/ m4 j R; g1 Q# | - }
! G D8 h* k8 u. y2 [6 @* P- V' o$ M% P, E - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; B _6 {# v, G" K# H, {1 c6 f, p
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 `- C1 P7 v- L" t6 c4 A; `
- }
) _ K8 ~% B5 d, _; i% w - pose.pushPose(); k' `7 a' A0 ]& z. r! p& `/ f( e4 L
- final int newLight = convertLight(6);3 [& Y4 Z8 }5 j( v8 s1 [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) ^+ o1 B0 U( b) O3 e - final float lineHeightSmall = (y2 - y1);8 u- h5 e \8 O6 Z+ e, n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ J1 `% k2 }; p: W* p - pose.popPose();
: e; @- N7 V' P0 a! n9 S - }$ ]% _0 ] @& J: j6 z/ w: J7 A* H
- ! [( Q! F' s+ O
- private RenderType getLayers(String texture, int light) {
4 \" b g( Q% H V' A* @8 l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 t& j4 s8 Q4 V& u - }+ Z' z5 y" u5 e, r$ i8 X
- 9 R% }& W2 ^4 l, A* ]
- private RenderType getLightTexture(ResourceLocation texture) {' K' P- M" N% E8 ~% p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 B+ q5 a8 ^# J3 t3 c, { - }8 {. i" i6 }% D8 u* K8 _- S
1 j) I4 S4 }9 h* b/ r2 v( b- private RenderType getTexture(ResourceLocation texture) {
* W4 B' G5 W5 g, ?5 b6 g/ U8 y- ]9 z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: q7 Q- V6 _" F4 h/ I- q4 o8 M. }( L
- }3 ^* r9 m3 n; y2 I8 y B# H9 m
- / ^. [# d+ [( n. X' E! O# B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" h8 B; a" i$ J" |$ N6 s
- if (cache.containsKey(identifier)) {
$ Z" Z7 a3 q& H7 l% ` - return cache.get(identifier);' l5 S- ^' n: u0 a- z
- } else {
/ V- V) R! R' L5 h7 Y - final RenderType renderLayer = supplier.get();
0 W' C' G, F" O$ i# E - cache.put(identifier, renderLayer);
: ~+ d' v, n! p l P - return renderLayer;$ Y( y' p% n$ D
- }2 H4 v+ v" S. S- D+ K1 |" H
- }
! l* G. ^) w$ D - }
复制代码 |
|