|
|
4 a, Q3 v7 B4 Y. y4 P
行,这个怎么样) K7 M; _8 d, e9 |8 R. v# J
- package com.xhg78999.mtrfac.render;# o8 [& ^5 J5 B+ y. _4 Z
: D( p4 j6 d5 u9 G. f# J* B- import com.mojang.blaze3d.vertex.PoseStack;0 Q* F9 B- g% ]* n( H
- import com.mojang.blaze3d.vertex.VertexConsumer;6 R1 E4 v$ H5 R
- import net.minecraft.client.renderer.RenderType;; x9 x7 ]/ g" ]0 `% O- |, u; W0 J A
- import net.minecraft.resources.ResourceLocation;2 T2 C7 s+ R) d
- 4 a9 c/ w" B b: d, x& R
- import java.util.*;% [+ Y. Y, q3 N3 i# ]
- & }/ D! t4 B V% g& m' ]2 @
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ a% g; Q) T. Q/ [4 U
4 W4 `* v" M4 t$ V" c) X- public class LineRender{
6 W( ^3 {2 D! K1 p3 l4 q0 @ - private final PoseStack pose;
% M: O M! G7 h$ l3 u3 b$ G' l - private final MultiBufferSource source;- V& D2 B! y' O8 w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ z9 U: v. h! \0 `
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ `+ w& F* x, f/ |, `. C
% {- ^4 i1 s6 H& }; I) J
& G6 k3 i* d1 C2 H! `# @, p- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 J/ n5 v6 |2 @9 f9 k( n& c
- if(x1 == x2 && y1 == y2 && z1 == z2){* ]3 n: [+ O5 e, Y p5 \
- return;
+ V) i# D8 _* y, c9 j - }$ b4 H9 a; G7 Z: o' V
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 p' h6 ~8 S3 j! c% A# x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 |5 {% G8 U b3 T% V( c* F3 R
- }
@, W$ M, N a! M# s" {# c - pose.pushPose();
# l3 J5 N5 x3 V3 Y2 {1 D - final int newLight = convertLight(6);
) ?4 k. h3 P% r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: |$ T T1 y4 D
- final float lineHeightSmall = (y2 - y1);
7 i, B! J+ w0 W' {$ z) _: Z9 K, [ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( P* o+ c; [; F8 f - pose.popPose();' m6 t! L) v$ q( n L
- }3 O6 c5 x0 Z6 N) ^
- $ v; x9 |1 G# y% E0 V$ H) L
- private RenderType getLayers(String texture, int light) {% T" r! H! h' Q4 ?. w6 B$ [
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
?4 ?3 |1 H/ D* R - }
$ S% N7 D4 a S4 H3 o - - m/ C; \& q" K" B7 S/ t4 {
- private RenderType getLightTexture(ResourceLocation texture) {8 `+ b5 w8 X! t$ z3 ~0 J' \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 }% H8 S+ z9 r( M W/ R - }
! \6 `% W2 x$ [% b4 y
$ M$ U! _* q* e7 G- I/ B- private RenderType getTexture(ResourceLocation texture) {
# D; x2 C4 Q# T% n% M- A8 i0 D6 F - return this.cache(texture, () -> entityCutout(texture), CACHE_B);* B; o, l# ~$ W+ m8 P
- }
$ J0 q1 [* D' I$ {/ p - : N* D% X* @0 K+ s u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 L5 }( O& C8 K7 }6 k! W - if (cache.containsKey(identifier)) {
+ p# U8 @; j! u; U. V - return cache.get(identifier);- f& _1 @3 y I/ N0 m
- } else {
- e7 M# \1 |# q# L* b+ o - final RenderType renderLayer = supplier.get();4 b) F" G' F3 O# z. x& t
- cache.put(identifier, renderLayer);9 V- M. S3 z- A) U: s/ j) h& ]
- return renderLayer;% L, e' _8 \/ c; {7 K, w; y% V* V
- }6 a$ U7 X( x+ `3 \6 n0 ^# ]5 y
- }
: M3 K- ` R! g, y, S) Y - }
复制代码 |
|