|
|
: E- l6 | q7 f" F3 n8 A$ e5 M行,这个怎么样
7 L$ g0 m) q8 p# e4 v% W4 L- package com.xhg78999.mtrfac.render;
/ z' `0 Y# r0 v3 D
3 V: i( U9 G" j5 G$ N- import com.mojang.blaze3d.vertex.PoseStack;7 X5 ~( Y3 z+ {* n( S) j3 f
- import com.mojang.blaze3d.vertex.VertexConsumer; f- W/ r4 c: `" v
- import net.minecraft.client.renderer.RenderType;
% }/ ?3 P* G: N2 J7 A - import net.minecraft.resources.ResourceLocation;3 |/ E( `2 S8 W6 m
- 9 H% ^; L- G+ `( F' ?, r! L
- import java.util.*;
/ w9 L3 | l& X5 T" O
: y7 f. U" h h* z' C2 s) v- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: D7 q) y$ f s
" g2 p; I0 S( \- {, [/ i1 E3 P0 h( R- public class LineRender{" q! K. k$ X9 t! }- [( M5 d
- private final PoseStack pose;
- u. x. ?1 }! f* B! f - private final MultiBufferSource source;) h2 P" `- ?. p1 f3 \
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 D) N, q2 n8 H6 f0 V
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 n* a9 g5 X+ Y* F
8 t! K) a5 z0 Z9 q
4 { b" f U- t! }$ [- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
% o* a: R' d7 } f2 o5 P& _ - if(x1 == x2 && y1 == y2 && z1 == z2){
8 L( L2 } f% D `' e - return;8 O6 S5 a* F6 ]2 J% z
- }
, ^5 d6 ~ D, Q. [* V4 H: Y/ _ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* I- ]% w- l) l: [" L$ q9 Z# D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 u. Y: {+ [6 F4 H8 B# c2 D& f) } - }3 n, y D, k) i' z# d; p' {
- pose.pushPose(); m6 Y( B) i* k) @. E
- final int newLight = convertLight(6);$ _2 J7 k6 d4 G- @
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 |; m5 \$ N- I1 R& _7 L9 ~ - final float lineHeightSmall = (y2 - y1);
% u% K$ J5 j7 U9 U; X2 X - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 N) w n" T$ C7 N# H( k
- pose.popPose();
8 `: f3 n. c& Z( q& { - }
- X4 S0 l1 }& R0 k* o; l
/ s3 w% B1 J. o2 Y+ [6 d! `* z- private RenderType getLayers(String texture, int light) {
- [6 ]+ z/ Q+ T& B, z7 @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 ~ X7 H6 r( B - }/ ~% m+ F- W6 o% k" c& U
- ! U+ N' f. {; }* k0 t J
- private RenderType getLightTexture(ResourceLocation texture) {
" I% L& K7 V2 r7 Y2 Q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. b, t1 A6 S% ]* o8 o; h2 E
- }
/ c3 }. Y. R! g V. H - $ _; @# g2 w6 G
- private RenderType getTexture(ResourceLocation texture) {2 ~( J2 t, X0 m
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
i1 E. V: H& w1 H3 ?) O, Z - }
7 N" [, G9 ^9 n! j3 r, Z - : Z. y6 D) ^" _$ |- Q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 A' n/ E9 Z" i2 |, l" l5 A: G - if (cache.containsKey(identifier)) {4 H, Y, u: l& R6 V, N8 L
- return cache.get(identifier);
% ?8 X" H: _ T% ?, s2 Q% U& f1 e. y, f, x - } else {8 ]; `7 a+ t( U# m
- final RenderType renderLayer = supplier.get();
* u% v2 J# C8 p$ Y/ r. n - cache.put(identifier, renderLayer);& h3 J9 Y& H2 y- F& I
- return renderLayer;
+ q6 s( |" O2 I; G - }
+ U* o) B$ M, W; _. t$ T P - }. Y0 |# _# A! e: C5 p
- }
复制代码 |
|