|
|
( m, S7 A7 x" Y' Q3 E行,这个怎么样8 I: j" K# w C& k3 _! m" [9 e
- package com.xhg78999.mtrfac.render;
2 r- S8 z4 `6 V - 0 G! [# M: e k; ?/ Q# W6 n* ]
- import com.mojang.blaze3d.vertex.PoseStack;
) T9 A& m0 I& T - import com.mojang.blaze3d.vertex.VertexConsumer;
/ n4 I- F1 T1 n - import net.minecraft.client.renderer.RenderType;
, Q: Y R: ^5 F/ y - import net.minecraft.resources.ResourceLocation;
k7 D: q. j" {$ t* ]
3 G/ A( f; W( K5 h- import java.util.*;7 [5 M7 E! u; r( I) \5 {( K
9 P* U4 C6 R, i! t0 ~% u) l- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 z7 P6 B# B0 y
4 y$ }" k# W5 x, ?6 Y- public class LineRender{, k0 l7 _4 Z! Z: d9 j
- private final PoseStack pose;7 w" C/ y3 ]% Z& h' p7 M
- private final MultiBufferSource source;
9 b( f* R0 P D3 ]9 V - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 Y) c$ p9 ]9 f6 k! {3 k! w - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 z9 G" W7 [$ c* A$ S7 e/ {
1 V6 ?5 U6 c @1 t; g" r; J
' V+ s1 u3 b) }# T" J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& p5 B4 U x0 p3 z - if(x1 == x2 && y1 == y2 && z1 == z2){
) ]1 f0 ~9 ]1 o( D9 z8 M O - return;
' J3 o0 ~* _5 L- q8 c! O. V* Z7 b - }
5 \) w$ n3 g9 Z5 X- O4 B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 b) Y0 [ c; [5 ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; e3 s( G: {; B3 s0 V6 T) C) R - }
/ Z4 B8 u! v* z2 |* E9 L0 k0 ` - pose.pushPose();
: ?; C' w) c, ` - final int newLight = convertLight(6);, `& E! P4 f$ H4 O I8 v+ D0 u" u
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( K1 O% w3 D& \( q. I- {# g - final float lineHeightSmall = (y2 - y1);
! q/ e, X' Y* a - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 ] Y4 F ?; |/ e3 t: `& N
- pose.popPose();
0 C" Z; K0 S$ L6 t$ F - }
% i5 B) Q) w3 m) q- ?
% o/ l, G* S$ ?/ B- private RenderType getLayers(String texture, int light) {
, `+ a4 D2 k9 k1 l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& o' Y5 _1 T* E
- }# j W. t3 i8 B- j+ e# H# E: V- U
5 m/ b0 n) b3 y9 V- private RenderType getLightTexture(ResourceLocation texture) {( M5 O/ A( ]4 L, }+ B- x
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. c a w$ t# p0 M& Z: b
- }% ~/ {& }* t7 Z$ q8 G2 x
4 b* d' y8 ? h. K: L+ ]- private RenderType getTexture(ResourceLocation texture) { t$ m Z3 ~8 ?& ~( @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ ~( A7 z& i6 |8 A, B
- }4 }0 E+ X* l; O( l7 ?! c }- ?
. P0 `# A4 m) P/ Y) o: i* M- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 X& [. ^& q6 [( s" u - if (cache.containsKey(identifier)) {6 g `1 R, R' i5 i
- return cache.get(identifier);. |4 N$ x$ J- O3 H% ^0 |9 i
- } else { U8 o. S, B1 }' u* _+ Y! f: `: _
- final RenderType renderLayer = supplier.get();$ _" |0 ]( m% A
- cache.put(identifier, renderLayer);
0 z& K$ ]) E5 o1 J+ C( ^ - return renderLayer;
2 b: |0 `/ e/ j: z) o: Z- h. W& I/ b# G - } l' Q# U8 }" P* }% @1 P$ q
- }5 m' X: z; V; c4 W9 c1 h( L
- }
复制代码 |
|