|
|
( N- v5 N9 T+ v$ W3 [; Z( N; D
行,这个怎么样
& a. I0 Y6 j# q0 X/ L1 n- package com.xhg78999.mtrfac.render;
6 _+ h+ Y: F2 e1 q! e/ k, o
7 B7 g( v0 W3 F) ^& @8 S- import com.mojang.blaze3d.vertex.PoseStack;! j# X+ u. S# b
- import com.mojang.blaze3d.vertex.VertexConsumer;4 C; p! O N9 i0 k' x
- import net.minecraft.client.renderer.RenderType;
- d- I2 [6 l6 B; p - import net.minecraft.resources.ResourceLocation;
# H: l6 o% {7 m1 o7 u
9 Y9 u- A- R ?) n+ R- import java.util.*;& {6 z6 e1 V' L6 M. e! J+ M" n
- . W, t2 ]2 o) v/ F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# C, [- F5 |% ^4 E( Y+ A2 l
3 m0 C9 C" y2 f7 |- public class LineRender{1 B% Z& x7 \, l% A" v
- private final PoseStack pose;
, D% _1 |9 \8 J5 H/ w$ d6 J/ } - private final MultiBufferSource source;
8 I) b' T+ u+ } j# @) Y+ B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: c+ b, L7 G. \ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# E, I. h2 i. x8 A; L; ?# n* r
- " {* h" ^. d- _$ _6 Q7 @: @: d
- ( k4 j4 f! o0 B) R! h- i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 U$ O) h2 `* V/ S6 F6 H8 X - if(x1 == x2 && y1 == y2 && z1 == z2){
$ E! n% s; R: r; j" L - return;+ Y2 V: r* m, \
- }* L: U( y7 Z1 |( {2 \2 E ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, W5 {8 o+ b) E8 |) Q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) u- h t }6 i' N - }- F: x+ g7 |# H r. Q& r
- pose.pushPose();2 T5 z4 b; w2 L' u
- final int newLight = convertLight(6);
9 U# _2 R5 P ~ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); d. n* U2 n2 L: m: z; M
- final float lineHeightSmall = (y2 - y1);: T" x% N3 C: W7 i/ R. d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 w/ U5 b* v* l+ F' h3 L5 N
- pose.popPose();" U6 ~, o7 u2 W' h |5 \
- }
) s: J, t2 u' k/ S1 H6 ] - 9 u+ @: E+ N1 }3 l( W
- private RenderType getLayers(String texture, int light) {
2 c$ M& A% i0 } l, S - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ M9 t. X+ c9 X# p: R
- }3 z9 n2 g' s! [# P7 v4 p1 `% l
2 g" S6 `- p/ f; t7 G- c- private RenderType getLightTexture(ResourceLocation texture) {' s7 ?, H+ [( f. `8 }
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 ?: p% J. y" c - }7 U7 o0 m8 p# G# C6 j
- 3 G, M7 G% G& F( n! }( O+ p- {
- private RenderType getTexture(ResourceLocation texture) {
7 S8 d V+ g8 e- T% t1 B - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 [* m; I7 \5 u; J. k - }
, R0 W8 p( m7 t- E# N8 Y6 Q' o* b - , ?1 k9 W' u. K1 Y$ Z, n3 n7 g: U
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) ]- }4 ^4 y$ P4 b7 r- M8 Y
- if (cache.containsKey(identifier)) {
+ J9 q' R7 ^5 A - return cache.get(identifier);0 H: G9 Q. r" A# ? n; W
- } else {8 @% d' @( s$ [( ^$ } u; B
- final RenderType renderLayer = supplier.get();
u" ?6 y! a' Q- y" P- @! N8 w - cache.put(identifier, renderLayer);
# B# p5 @+ G8 |* x - return renderLayer;& Q% H' F- ]# W2 F. W) p6 z9 `
- }. [$ _" F; q" f, Q& Y2 s) p# Z; c
- }
: a1 `% ^9 v, X# v! z3 C& @+ e - }
复制代码 |
|