|
|
- b- P- P5 V- K P+ l行,这个怎么样
$ F, t; R' z P" V5 w) ?) `- package com.xhg78999.mtrfac.render;7 Y6 X: D& m- F: i
- , R8 o4 ^2 L$ I8 L
- import com.mojang.blaze3d.vertex.PoseStack;
2 k% N& h4 \: E# o* m - import com.mojang.blaze3d.vertex.VertexConsumer;+ b. I( t0 }8 l% j; I/ I4 `
- import net.minecraft.client.renderer.RenderType;) d1 x9 K2 f+ P; G. b1 E( f
- import net.minecraft.resources.ResourceLocation;
2 H9 H3 z2 O+ T; r' W8 N
0 e/ G" I3 V* c& R1 S- C- import java.util.*;
9 [+ b# [4 T0 k# X0 R" V - ! w, u9 q! _0 L% O! u
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(5 r$ y5 a1 S4 d$ B5 H3 k
3 S# f0 z: C- q7 s, v1 [& ]( D- public class LineRender{0 H! y4 ? H. V
- private final PoseStack pose;+ }! \) Q( a) O8 A, y. ~" V5 S5 @
- private final MultiBufferSource source;6 W1 d0 x4 V0 L- R) e9 Z% O
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 v* ~6 } V+ T2 N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
a: v; p, i* D1 i: P( e; B7 R - + {+ b% {1 ?" P) Q
- + i2 ]2 w( f* c( R% _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; \3 G+ C; a: {3 u2 w; R7 i, V3 l
- if(x1 == x2 && y1 == y2 && z1 == z2){
6 |0 X6 T- t+ {3 |4 ]- f - return;% l/ T* x9 |3 T
- }
6 z7 Z% M- k9 {; ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# L3 C5 _5 U( G1 T' y/ p! P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 Z+ q K# [0 y1 J2 k
- }" W8 v4 M' H. ^; }, m- I' o
- pose.pushPose();# S& r8 ^( A" t" S* a1 f6 c3 j
- final int newLight = convertLight(6);6 a! |; f ?1 J
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ E4 e" L8 Z' m- Q B' o - final float lineHeightSmall = (y2 - y1);# Q6 X. e" D: ~1 N) O* F) L
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ R( {7 ~ f+ x& u6 h- Y6 M% b) p
- pose.popPose();
0 g& d. W* _1 K9 N1 z% P' F3 N - }+ E9 Q- F3 ^0 A4 `- x' E% G
- , W3 M" u" q+ X+ J/ `
- private RenderType getLayers(String texture, int light) {
$ x6 n' ]2 ~& u4 K n V. l' _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture)); s7 c7 o4 j) w/ m% {
- }* M7 K5 \. N7 D, B0 }
- ; O8 W/ o* M! H# Z0 V& e: s* |
- private RenderType getLightTexture(ResourceLocation texture) {
+ w: P* p9 \1 `2 G5 ^; Y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 d* H" n8 `2 `% y# H4 T - }7 r- q; M4 ]$ d# p5 N+ S1 n+ I
- % B( U: e- x- x% Z$ U
- private RenderType getTexture(ResourceLocation texture) {' s$ g! H. L( m0 _) U
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 o# F2 j. }2 K9 i# F0 J - }" I+ x9 G; [* n; P1 I# E0 g
8 T4 q, D/ h$ K- W1 R% A3 I4 a& _- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! N) D: L/ C% L9 J7 ]9 H1 e( _' o
- if (cache.containsKey(identifier)) {& a& E) Q- {# s
- return cache.get(identifier);/ l6 Z: a. g# I5 |5 V8 z8 g
- } else {
& T$ p2 Q' k- O5 @' O% w' o - final RenderType renderLayer = supplier.get();
/ u4 w' W5 z2 P* ?3 x6 u2 P j - cache.put(identifier, renderLayer);
2 O! o+ e& m/ {. N - return renderLayer;2 y" n& C( z1 Q1 l
- }
5 G7 v# p9 F) L - }/ \/ B( e% u$ g/ z1 r. x# r- l
- }
复制代码 |
|