|
|
. A) @0 v# E! H1 `. d7 v行,这个怎么样
& F' n# T0 h; Z- package com.xhg78999.mtrfac.render;" y) A0 j7 m e/ k% ] b. M
- * \$ N9 {5 |8 W+ P; F
- import com.mojang.blaze3d.vertex.PoseStack;
6 n: r# e8 W7 N) w5 D - import com.mojang.blaze3d.vertex.VertexConsumer;
# a) Q: [- X" A9 d( L$ _ - import net.minecraft.client.renderer.RenderType;
5 E5 h+ K! [" F6 A: ` - import net.minecraft.resources.ResourceLocation;
* e8 c% `1 E [" C j0 d( I# j - 6 _7 {' C) I; q D
- import java.util.*;
1 \: V, L8 v/ X3 e, l, Q) Y; l
8 S4 C" T' e. S" u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 ?/ G0 k6 f; z2 K7 v$ p5 L0 m
" {( t& N9 R- L5 R% ^- public class LineRender{
6 o0 N5 Y P4 \$ x; o7 { - private final PoseStack pose;$ x! f2 O* o. L
- private final MultiBufferSource source; Q2 z. q9 \$ E8 k4 ]
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: S9 Q" B1 Q: }, j0 @8 O - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. O: ^. w9 i# r* t
- 7 d0 ?- g+ f; a0 M' j" i! k
- 4 B. V/ k: s. m: `# y0 t( ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- K. L; f p) I2 b0 i% t% X - if(x1 == x2 && y1 == y2 && z1 == z2){% B2 j/ N3 |9 Y3 G
- return;
9 h9 n+ k5 b! h& q - }
; J7 U2 E- Q5 Y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 ^8 d5 l8 m1 E! r# ~2 a# W
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ ^$ ]7 d/ J" R+ N+ B
- }& @. y3 I8 I+ u$ o" w
- pose.pushPose();. _0 ]: \( s' m, H
- final int newLight = convertLight(6);- f2 M# j5 Q @3 u% |1 \% f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) S# V' F: X* [
- final float lineHeightSmall = (y2 - y1);
1 T* ~8 i6 V. n, u1 Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ X* C2 U9 [' q5 y$ P0 ?7 ]% q - pose.popPose();+ {9 @ x8 u3 k
- }" s/ p: g' x. ?$ U
! }) F' z. ^# h8 J, \- private RenderType getLayers(String texture, int light) { N2 k/ i3 N9 R) ]4 @
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# Y6 ~5 {5 I! g% i4 ?) A1 H - }
5 O0 g: F% i$ Y+ K! V3 y# z2 @ - 4 E6 h2 _2 i" G: D t8 S
- private RenderType getLightTexture(ResourceLocation texture) {6 I4 _: M/ n! d& F, G
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) k4 z; O9 b0 b) C1 t - }, }. [7 x/ @! X2 S
- % K: m; T$ W: C- y4 S/ q
- private RenderType getTexture(ResourceLocation texture) {
8 S5 e' S7 i6 T. t' L - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 F# w8 U3 w4 a! U/ C$ Z8 f9 ^2 m/ o# ` - }
" U$ n3 K ?! Y+ o5 A
6 q( v0 `6 k2 W, C6 Z4 I) r- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ S7 X" r4 a1 ]
- if (cache.containsKey(identifier)) {
, |4 c0 h* T* u! A- y" x - return cache.get(identifier);
/ H7 C; W( w) N; F# F - } else {
+ F; g% d- j/ {8 W1 @5 V# D7 [ - final RenderType renderLayer = supplier.get();1 H' Q9 P/ M! ?3 w- V5 e8 \
- cache.put(identifier, renderLayer);
: X4 n5 D( w$ T - return renderLayer;
- o4 K1 p8 D. m - }
' s2 W- g, b" ^% R# m, E0 O. ] - }& f. |! h) w' b+ u2 f- |# D8 x2 \
- }
复制代码 |
|