|
|
& n# c- x! B' o. k$ W9 Z
行,这个怎么样
" h+ I8 g8 |& Z8 x4 A% P- package com.xhg78999.mtrfac.render;7 s P5 g* _2 y
; U7 w; C; ], A3 }1 v- import com.mojang.blaze3d.vertex.PoseStack;( G- B, @7 a1 E1 `% S4 i+ @
- import com.mojang.blaze3d.vertex.VertexConsumer;# n. c$ m7 U, J1 u3 e. A0 [7 g
- import net.minecraft.client.renderer.RenderType;
* z; G; Z- J3 O9 L+ ~6 z - import net.minecraft.resources.ResourceLocation;; q. H1 d p* K8 Q: @1 Q
8 x# e' t/ @: U% K: y1 ]- import java.util.*;7 j" a) ?8 M u/ X( I
- / l+ {; _$ d' R( B. W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( D d& u I- |1 O - , T+ C" ^2 R4 m' F% y$ ?/ x4 J& U
- public class LineRender{9 G3 m; w7 Z5 G! r1 G. H$ Z6 t0 j( o
- private final PoseStack pose;
) Z" Z% _5 N, ~ - private final MultiBufferSource source;
( s& b2 o# A! i f+ L* | - private static final Map<String, RenderType> CACHE_A = new HashMap<>();( o1 w( J) L# |- e! B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 n0 s$ G1 f* l- c2 k7 @ - & d, M1 G6 `# y7 _* w1 @
- 2 {) T! w( D+ z4 P
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 [& f1 s5 q: O" G
- if(x1 == x2 && y1 == y2 && z1 == z2){
! b9 y( [/ S( m3 Z* v" ^6 x - return;
( z# B; \) }/ W# U! V1 Y7 D" n - }
4 m$ j5 ~, y& k. |9 { - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# R7 L7 y1 k/ \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! r- x+ e } y) R) n; o - }, {+ p8 `* g& D* Q6 F2 N* d' |3 F
- pose.pushPose();
' E6 P0 t: ]1 B V7 X: }; G - final int newLight = convertLight(6);
. @+ l6 p4 G4 ?5 A4 d - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
# V4 }6 n+ f9 `# H& P - final float lineHeightSmall = (y2 - y1);" v- U& a$ z7 _$ ^; G
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! s: D- ~1 I6 q0 s7 M* z; b
- pose.popPose(); k2 d7 l) [: B3 X, t
- }
( P0 C9 V6 B' A8 E5 b
+ W3 ?+ s5 |$ H$ K0 J8 F! h. ?( L- private RenderType getLayers(String texture, int light) {% x9 q$ }- n2 K9 C& v, d `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 H: H5 ?+ ^7 C" I2 G' Y; ~; i
- }" @3 M `3 R3 O# J" U8 ]+ c
- $ Z9 w/ H8 }; V1 }7 G7 J+ W
- private RenderType getLightTexture(ResourceLocation texture) {& q: U- r( U4 f: i( i& k0 c
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 l: E! y* f/ ~0 i3 B4 @; h - }
4 f4 F! H9 Z' ?$ B/ N- u6 a6 c1 s) R2 @
5 x4 T/ q: A; ?! }$ k! j+ u- private RenderType getTexture(ResourceLocation texture) {; w8 |# L/ N- G. w3 Z q3 u- y3 t
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);* t. m+ E- k6 @7 l# B% c/ _+ G; u+ I
- }9 Q* b3 c2 n5 h
5 a* t2 I; v; p; j9 y$ D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ B5 _; ?4 S1 Y- _/ m
- if (cache.containsKey(identifier)) {; ]& k( n, ?; \ Z# q1 h. Q3 {3 O
- return cache.get(identifier);
$ X2 E8 ^& m' V3 G8 `: r - } else {
0 |/ b: ^" u$ b- V: o - final RenderType renderLayer = supplier.get();
6 I0 d- B/ m1 P* q0 s, |6 d - cache.put(identifier, renderLayer);3 o: h8 d1 @" x2 I8 [: c T" a
- return renderLayer;7 s7 p+ X* ^5 Q% c
- }4 B0 T* M" Y& Y+ |' V4 v
- }
; W! S d i% n4 }! V$ y% N2 W+ O0 p - }
复制代码 |
|