|
|
2 }) c0 H: [, Q6 a. B) T0 Z9 g
行,这个怎么样/ L- t2 ]& i+ m- W
- package com.xhg78999.mtrfac.render;/ V$ \0 Q* o9 A3 {3 f/ \$ B
5 h2 @8 S* `3 S" H$ R- import com.mojang.blaze3d.vertex.PoseStack;! _! K/ ~9 M- U" T) R; i. e# L
- import com.mojang.blaze3d.vertex.VertexConsumer;! L: ]+ L3 v O0 P. h
- import net.minecraft.client.renderer.RenderType;; |% P4 k3 `8 o1 T
- import net.minecraft.resources.ResourceLocation;9 v& n4 o/ T! I. P' v$ Z% Z; t4 f
0 ~# Z/ f5 n$ P5 ` s& G8 D- import java.util.*;
6 T* U! y" Q3 ^
& y( x2 V+ g+ n- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ F- Q' S' o: m( R) p& N( J' S
1 p; T$ I; h; W6 ^- public class LineRender{
1 q+ z, f% O$ W `% B$ A' L! P - private final PoseStack pose;- ~+ ?: O/ A5 t8 b9 n7 Y5 m
- private final MultiBufferSource source;
' o. o! S, j! q& p2 B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) {' I o5 |$ K* x0 F: w' R - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 t- s8 b2 p" v3 H# x/ ^ - 7 ]9 [9 r0 [# p) ?. }
- 7 v# z, [. S9 G9 v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 [3 P4 V: C Y$ o% x - if(x1 == x2 && y1 == y2 && z1 == z2){7 S- {6 m, _7 q, ]; ^: a
- return;. a: L+ t% K5 i7 Q3 ]9 u' d/ H
- }$ a1 u% O& F% X% b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 Y5 S( w5 E2 l3 F - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, u, C) Z5 y5 O' _! s3 E
- }
9 T4 Q) V* F5 s- j" @& l - pose.pushPose();
6 Q. H: h0 K/ r# t# A) c - final int newLight = convertLight(6);
, [/ f7 A$ ^8 {3 V* I7 r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
]7 v& Q' G8 `) \3 ]# X6 q# r" B - final float lineHeightSmall = (y2 - y1);/ _& i2 r6 \ s0 f6 H' p% g( R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 P1 I q8 j; [ ^. ` - pose.popPose();4 l' `, M! R/ b1 N# s
- }
2 m& e& i$ Q: {2 L7 }# p6 j, B: f1 I* D! f
& K+ q# @2 U/ N6 {( ?* a- private RenderType getLayers(String texture, int light) {
& k0 ^; o) o* `) i" K( n" _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- P9 [9 }" B, t
- }+ C' r% {! z! r
+ e+ o5 {2 H. C5 A- W- private RenderType getLightTexture(ResourceLocation texture) {
2 z0 R. N( V6 D1 I* I% P/ l( k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. L1 c3 o7 x; I9 p5 \5 W - }& i- Y4 z5 S4 j' c# B5 l$ q1 c
) U; w' b; g$ I- private RenderType getTexture(ResourceLocation texture) {
3 a) c. a8 a8 o4 [* R8 N - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& {- y5 [' N7 v! G; `) k# D - }
5 K. m7 Q0 p& A* \( ~ - , a6 ^: ^. M' C& L w
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ D6 l0 M# e3 f' a, z - if (cache.containsKey(identifier)) {
1 A& F) T8 e- }, H1 J - return cache.get(identifier); k: E; O) Q* ^/ K5 ?% a
- } else {" @' k& F4 E* l5 H3 J9 F
- final RenderType renderLayer = supplier.get();4 o3 J9 Z1 G. E+ r' `) C$ @% X
- cache.put(identifier, renderLayer);9 o; V! B* x4 C( `% E, g. k4 ]
- return renderLayer;" P+ n3 d0 K) R% z
- }
( R1 U, Z u4 A3 S0 H) V: J- { - }* `( o! I+ g1 J4 {: `* |/ A
- }
复制代码 |
|