|
|
4 v1 N8 f/ y& _" m! z行,这个怎么样
* g- |8 ?- [+ z: Z0 N/ b" |- package com.xhg78999.mtrfac.render;
# T# t3 K" l6 K$ C1 s N( w
4 r; D. `: m- e' W0 I& g& a- import com.mojang.blaze3d.vertex.PoseStack;* c' Z, g2 g5 P B5 Z6 ~
- import com.mojang.blaze3d.vertex.VertexConsumer;+ ? v& w2 x( ]: W+ `; v5 I
- import net.minecraft.client.renderer.RenderType;
; i, S3 I- Q" r3 g( a - import net.minecraft.resources.ResourceLocation;" U! y' k3 z8 e, P9 V; @8 L
- 0 a+ D+ L5 M# j) b
- import java.util.*;& T# g7 P/ `! i' F5 r: X( L
5 b+ k w$ t: I$ Y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 n; T( p2 u+ e" j
7 v# P# I1 N& Q, c# o3 z/ m- public class LineRender{) w$ p, l9 D# p' V; x1 ^+ D
- private final PoseStack pose;5 L7 e4 i; d/ ~3 D# t' h
- private final MultiBufferSource source;/ V% x- G: T+ h( a$ Z, G
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& a, ~* W1 `9 @ ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" o" F( [* F7 Z" P: l
- 0 |) u- x4 i9 M! h! x2 H+ W
- 9 L! B; w6 V" R+ Y" P' D5 \
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& O7 F7 n) M% R I5 l, q& g0 E7 L
- if(x1 == x2 && y1 == y2 && z1 == z2){
) K' B* X# |+ p# O - return;: Z4 [7 |1 x2 D2 v
- }6 \6 s7 V% ]- B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 w3 x- y3 w" y6 o
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); S# W* z1 k3 e; V* I1 e
- }
8 E4 i' }2 @$ ]4 [+ F - pose.pushPose();: P) Q, s. t+ T6 S3 Z9 l3 W
- final int newLight = convertLight(6);; A4 Q, e2 d) R7 R5 o( y* g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' S0 A- P; C5 U% X0 u - final float lineHeightSmall = (y2 - y1);. V, L, ]7 C5 C& `0 ]# G! S
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);' ^0 w+ d4 r' s. l
- pose.popPose();
/ |; {. ?! H) _" m* r- e - }
9 ]0 F& J1 X' m- p) z7 V8 b$ l+ Z - / S# ~4 d& s- v; S5 G
- private RenderType getLayers(String texture, int light) {$ ]% h+ {$ ]& W% l' q7 s+ k3 D
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* l" E8 i: L& C' D6 f: s' f$ R
- }
6 @, A* ]* j* |# n% G# D
$ r. W5 Q/ x; v- private RenderType getLightTexture(ResourceLocation texture) {$ s2 g! m' W8 s
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ ~0 d5 B/ V& B. g
- }
: Y* m' w7 U C: j' L; D# B% E$ S2 r' w
- A% P, b) ~* L' n. ^1 G# {4 v9 i7 Q- private RenderType getTexture(ResourceLocation texture) {4 ~% B+ b4 |! j3 g' x; s% \
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 R& T! R; x' K; i" V) T$ `
- }( O0 g9 Y: d3 s
# }8 o3 Q' I" Z1 |) u, y, G( ]- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
- O$ \) O9 ^- d- J; ~$ O) @ - if (cache.containsKey(identifier)) {
# @3 b( T' w) R - return cache.get(identifier);5 d2 p! W' b8 ^
- } else {
3 Z+ K7 X4 D5 [. Y. V7 M0 W - final RenderType renderLayer = supplier.get();
% [8 J& G; n( f' [ t - cache.put(identifier, renderLayer);& {0 T1 S6 V& l
- return renderLayer;& I9 [6 H% P/ L& F: z6 f
- }
: v) z/ W8 U+ h - }
9 l0 c( ?7 W x% N - }
复制代码 |
|