|
|
$ V+ C7 A1 l3 f
行,这个怎么样
. u8 F2 g* W y& | ~- package com.xhg78999.mtrfac.render;
+ E+ a4 S- H$ m% k6 a/ J, r, a9 d - * \' B% f2 O. T9 e1 x' L: w
- import com.mojang.blaze3d.vertex.PoseStack;
" q: t1 g. o8 @, ]) _# Y. L. ] - import com.mojang.blaze3d.vertex.VertexConsumer;$ }2 B8 g. u5 j' H" j+ l
- import net.minecraft.client.renderer.RenderType;* R7 N- _$ j9 `
- import net.minecraft.resources.ResourceLocation;, |' X. @# m# v8 ^
. _1 x a; e% n( N2 d( }- import java.util.*;, R- j/ h& T1 h9 ^7 o, Y2 c
- ' d" b) h; r0 R% q6 F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& g! Q3 ?' A# Y% s0 q
1 E `, j( T' r7 ]+ r" \- public class LineRender{& ~# u* N5 u8 R |$ M( V0 `
- private final PoseStack pose;9 r/ h9 q( q2 M8 N
- private final MultiBufferSource source;
* E0 h5 y+ h5 v0 t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 b5 k8 a1 D1 I% H) i
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 Y3 L X( \) Z
6 \4 g- f, h+ y7 S- ! [- j5 ^# H% z6 ^' Z* w* I/ L
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 d2 _6 Z& B1 u4 L9 G7 h F
- if(x1 == x2 && y1 == y2 && z1 == z2){2 g( ?% {3 u z- N
- return;
6 |3 R" j7 z) I6 H. v. m - }! D0 D* `; Y/ L0 z, ]( Y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ P# Y6 H$ r! s2 H4 { - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, S+ `5 z) K6 G, U3 ^ - }: x# n1 C7 I2 j" v
- pose.pushPose();+ i/ [4 x9 c$ r" x0 c
- final int newLight = convertLight(6);/ q, }+ K4 ` |' B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 g: d! u8 B' z/ S% Q! Q: e0 x
- final float lineHeightSmall = (y2 - y1);
+ S5 d5 ^% S2 {2 M1 i! R - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 j3 p* r; h9 ~- Z: W" B. M
- pose.popPose();" I9 F0 q' s& v% b. Q
- }
) c$ _: E9 v& S* C# g& ?+ ]( @
9 P2 y/ v- y9 c) I9 U7 v0 n1 E- private RenderType getLayers(String texture, int light) {
: z4 c! Q' D" |3 V: B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( X" r( ?+ e' o, y, z9 V. B - }
+ y7 x7 b8 h4 ?" p - , O" u8 o% D1 p u# }7 i# D
- private RenderType getLightTexture(ResourceLocation texture) {
1 F- i& L6 Q4 k& z( Z - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: R6 l3 ?6 A% u/ a) l9 ~, z
- }
- c8 E* z: A# O) a - 2 V' l# G, `* l+ ?; o/ }
- private RenderType getTexture(ResourceLocation texture) {& P' W0 I- }5 D6 I
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' a! |- Q! Q: U3 ` - }
+ y# @9 \8 p! T2 j
7 o) P0 M8 U( X5 m- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
- M( N% \ J! S5 f# |7 o - if (cache.containsKey(identifier)) {
/ v. p) D' `( W! ?! I5 x - return cache.get(identifier);0 l9 W* G1 J% i/ M
- } else {
- I6 Y6 d8 u8 ]) ?" B - final RenderType renderLayer = supplier.get();; `; v8 T% a+ V* E- o) O
- cache.put(identifier, renderLayer);
4 i/ h1 x, B# D7 w0 `% U - return renderLayer;# d7 x4 A/ x! ]9 y6 y- L
- }; B: z# o l: b b$ s/ E+ i+ R6 ?
- }" b2 X8 B/ `* _9 ~8 j
- }
复制代码 |
|