|
|
! f, {9 v/ U1 q1 ?4 |3 X行,这个怎么样- Q& j2 g: x% B, i7 P: m+ R! Z. v
- package com.xhg78999.mtrfac.render;
* p, R* m$ X0 e; U" @ - . a1 J/ ^1 b0 G, k1 B! [
- import com.mojang.blaze3d.vertex.PoseStack;
. H' H0 i2 u3 b4 z% q' C9 U - import com.mojang.blaze3d.vertex.VertexConsumer;
6 U1 G) U( z3 ~* @/ L' o - import net.minecraft.client.renderer.RenderType;$ V$ t$ [' r; p& R
- import net.minecraft.resources.ResourceLocation;
" M# E0 N% I# i4 p - ; z0 }' u+ j$ a' y/ k7 W
- import java.util.*;
% f& y6 W S6 v9 c! Z - 7 t' m6 c. M; S' o
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ I' }6 y: k2 D$ A4 i) j
- 2 @) }* q* w/ R5 m0 ?
- public class LineRender{' t& o4 r0 f2 ^0 J4 V
- private final PoseStack pose;
7 A; U) J) ~9 Q7 [ D7 ^* | - private final MultiBufferSource source;- u5 Z b+ C& |$ C
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* @6 [- E- ]% O9 U7 S, K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) l/ d1 t! R( E5 A, e8 j. j
- # L' u+ ~2 } l: p1 O" y. g
- 5 j# L' }$ N/ Z1 ]% D
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- |; a% O. e2 j - if(x1 == x2 && y1 == y2 && z1 == z2){( {) b- _/ g% c; \0 V
- return;( Z) K1 u8 z/ p. k) y2 w0 ^
- }
5 P e# D* L- W# ^ T) B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; ?2 d: M0 _4 Q1 h& Z: J - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 \5 Q* c. Q% q# s6 _& n# F - }( Z. b% T. @- w7 F; j' B4 w
- pose.pushPose();- P; |. n3 r6 Q6 m
- final int newLight = convertLight(6);
; N( j! y6 o9 n* Q9 ]8 k" d - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ G+ Z0 u4 ]$ \ b; t - final float lineHeightSmall = (y2 - y1);
" V. l/ Q( r/ n - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: g. o. s0 v3 d- d* d+ {* T6 r/ E9 @ - pose.popPose();; t$ i* X; p2 ]- I/ S8 r
- }
& ~, r7 i; |1 |* A9 h* y
5 V6 {& ^0 n" v: O) F- private RenderType getLayers(String texture, int light) {
* b$ l7 f& A, {7 a8 I( k) n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. b! O3 A5 }7 b7 H. t - }
$ M% t9 A# f. J# |; s
B& Y2 y2 ?) s2 u: R; S, j- o- private RenderType getLightTexture(ResourceLocation texture) {
/ H1 ?" b; ^! O' ~ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* H3 {2 o6 b- Z - }: }( \) g5 g) Y. r" T
) ]) h3 D( U* `- private RenderType getTexture(ResourceLocation texture) {: U# m( {) E4 Z+ Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; {$ p" n2 |: n& ^" f) M
- }* G% @! l: |' O# y' Q
- 7 `6 z& {! _6 C* ?" o0 c; L% e- D
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 z7 e' a1 e) Q" v
- if (cache.containsKey(identifier)) {
2 ?7 g+ C: o' ?/ d, `3 E) d# L - return cache.get(identifier);! \; U |# } U- Z: i0 S
- } else {
& @8 u- O8 {8 b7 y% @ - final RenderType renderLayer = supplier.get();& ?0 W. W5 i1 x1 E
- cache.put(identifier, renderLayer);
- B! n, X: c2 [# X2 c; P3 a E - return renderLayer;% @" \* L4 W7 z p- s* C( l5 [
- }" ^# f. _8 n0 w4 w) z
- }
& d% X* d6 h9 B2 J8 Y! z: H# E - }
复制代码 |
|