|
|
1 d# z, `+ G5 L3 s2 e% F+ ?" n3 a行,这个怎么样; |9 T! _6 Y* |9 l* \% \+ P( f# {) g
- package com.xhg78999.mtrfac.render;
1 V# o/ n% W, a( P4 y - , N2 H" F8 S4 X. z/ l; B, O5 K9 N
- import com.mojang.blaze3d.vertex.PoseStack;2 G7 A& `- `6 { T" K& B0 p8 A
- import com.mojang.blaze3d.vertex.VertexConsumer;4 a0 e Q4 K+ U5 A* [
- import net.minecraft.client.renderer.RenderType;/ N; G) ^6 m' f9 R! e8 C9 i; G
- import net.minecraft.resources.ResourceLocation;
; @7 }- Z! L( l& c
9 ^$ ~0 ~0 V) g* F9 C6 f& F- import java.util.*;6 M1 M( h- n5 t$ m3 f1 C, s
- ; y: u% Z$ K0 q: e8 u
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* Y" k: E, C1 _ H$ o/ w
- 4 T( r2 U& N" _# d
- public class LineRender{
8 i, I! X( V7 A1 e' ] - private final PoseStack pose;0 v) s/ J7 z- a" p# {6 ^7 x. S
- private final MultiBufferSource source;4 T6 o9 c7 e8 M+ Q% `4 M3 e5 b" m
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();' T$ W: C7 |* w' W4 z4 B: s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. z0 y- ?* \- ^ - ; ]. U. u! u$ L) N% x& y! E
- 6 o$ a/ N% r9 }! ^
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 |$ t; u. |6 M+ v - if(x1 == x2 && y1 == y2 && z1 == z2){
: O5 U# P6 u# q" R9 Q - return;
" K; K7 z& q5 v+ w) ~ - }3 {6 G3 I4 {5 @7 r
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 F9 j* o( H. Z1 E) I7 p - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. ?7 R9 d# Q* M" @5 ^2 I) _7 ` - }7 U! t( S8 z1 E$ L. ?
- pose.pushPose();
8 G9 @; @6 ^/ q: E3 p5 ]- \# R+ A' i - final int newLight = convertLight(6);! n( L' u( i% |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( u/ I1 V- r! e) P7 c - final float lineHeightSmall = (y2 - y1);5 y5 n. X4 X9 h/ z5 k
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 }8 g( k7 X0 G
- pose.popPose(); y O4 L3 \6 n: N4 r
- }' a- A3 t3 C" k+ q
2 O( l4 R0 W0 R3 d7 a) W- private RenderType getLayers(String texture, int light) { i( F2 J+ G! T. p" w: r; e
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 n, Z& B7 J# Z2 s1 \! j' w - }+ W/ i! Y% L3 u% Z+ U
- + f5 t! h. P* o- [
- private RenderType getLightTexture(ResourceLocation texture) {
$ F! \# x6 _1 p. | S& J I9 ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 ]0 S& g( _* P; s: A
- }
p+ P$ R" s$ v1 t l1 \ - " i. j+ z; k0 N& W
- private RenderType getTexture(ResourceLocation texture) {9 b! U9 ? b7 V' V
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; @) h2 F5 c& u0 }/ Z7 s - }
' R2 f. W- U) g O8 ~( s' l
: R3 K) m2 Z, G* B8 u# v- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: h7 P4 o- E# |; i( [) u8 \
- if (cache.containsKey(identifier)) {0 s" g# q( Y9 c+ I6 q/ c! j
- return cache.get(identifier);
6 {4 V( P; w) Y! F H( o, G - } else {& ~: Y" c9 ^3 a
- final RenderType renderLayer = supplier.get();0 R8 |0 f' O9 e0 z$ @* V
- cache.put(identifier, renderLayer);( f/ O: d7 A8 C9 V, N$ W
- return renderLayer; e A5 Q4 v( C: }+ V& c I
- }
- I2 N4 C2 N8 A# `. z, y - }3 n: J) \* h* Y! E8 B% F& u" G
- }
复制代码 |
|