|
|
7 l& a( R* Y. _! I( m; X
行,这个怎么样
( Q( D& t, i" E! U5 ~- package com.xhg78999.mtrfac.render;
, @6 z; b @" i+ u* E2 s; j/ d( L# m - / C* Y8 @5 N; L# H P; D( Y
- import com.mojang.blaze3d.vertex.PoseStack;
# e9 P, T9 f$ O# Q/ C5 s% t/ F @ - import com.mojang.blaze3d.vertex.VertexConsumer; |' w3 }: }+ ^, Q4 c7 ]8 |8 k
- import net.minecraft.client.renderer.RenderType;
" M8 Q) `! d# O; I - import net.minecraft.resources.ResourceLocation;
3 _$ \4 l! g. H& u
$ e+ ] g4 F1 L; u1 c% H- import java.util.*;4 i' K4 p' c8 r. P7 \
- * d& @) z+ b/ V% ?+ C
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ H- y0 D, e: O: Y* f2 L' `5 R+ t- V
3 k% k5 C/ \" w! {, I0 S2 e; s- public class LineRender{
: K. e" b5 W6 K e - private final PoseStack pose;( x+ A6 k/ L7 l+ F
- private final MultiBufferSource source;
# w" x& G; F, I2 Z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* y# x7 G5 x I
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' D+ Z) g9 h3 P' y" P- @: O. m
, l' R7 |* K6 b; r3 d1 H
5 `; H9 ]- z8 y5 C* E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! j! j5 I1 `& U) e3 d! R0 ?6 F8 A
- if(x1 == x2 && y1 == y2 && z1 == z2){
- S9 `1 U1 D4 ~, |' S4 U - return;( e* g' P& R- L1 u6 |6 U
- }8 Z) V2 k; ~) W3 u; M1 f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# ^) W4 F: ]% X4 e) s
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; Y. C# a: Z- G; V1 Z3 S( h+ t& s - }& f. a* e, T* \2 W( N6 [3 C
- pose.pushPose();. b) _6 r: \$ Q
- final int newLight = convertLight(6);
) ^: M4 o0 O; P9 o& n - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
# ~+ a* M) G! K9 T' t+ B8 R( a5 N - final float lineHeightSmall = (y2 - y1);
$ i0 U F0 n: ]/ M* F, X# x( t* L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* M- ?6 q. Z5 m7 G
- pose.popPose();
1 T% {# \0 b+ f; G - }# f$ \- j1 F# q- p u% h
- % |. a' k/ ~7 s1 \
- private RenderType getLayers(String texture, int light) {7 i0 ^* b$ e; D+ m9 [
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 W* W G, g8 J! I6 r - }# c8 ^2 }+ A- z* \6 y4 ?0 z
- 3 z0 S% E! Q5 A: d* Q3 d
- private RenderType getLightTexture(ResourceLocation texture) {
& G- k% b: ?6 v" V9 S! d% E - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ A$ h8 }$ S4 ?. S2 @
- }
8 j2 C9 N- r Z( H - 6 N( I, q! m+ g) t: [! L& z2 {
- private RenderType getTexture(ResourceLocation texture) {
0 d. }8 m* d, F1 E* t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);, c& ]9 {6 Y, u0 V; @
- }- E- i+ m/ d2 O, h
- 8 l- ]4 G8 N: K% ~' q3 u) ]# d
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
( d8 l9 y# x) }3 X% y: A) f& w- d - if (cache.containsKey(identifier)) {8 F( w5 X5 ~1 L4 P
- return cache.get(identifier);, j3 h. X. k' K) W0 b
- } else {* D/ O) b' H$ V5 F: u4 Q( |
- final RenderType renderLayer = supplier.get();
e/ z% v2 c& h- H u - cache.put(identifier, renderLayer);
/ e ^9 F# r$ D - return renderLayer;
! r+ I* x( d1 z0 C. T - }
! x/ c) T$ Z& n8 v - }" L- T4 ?8 F; H$ @) J" V
- }
复制代码 |
|