|
|
0 |4 Z4 Z& H: p- L' N
行,这个怎么样) i$ M& ]2 b" O; V' z
- package com.xhg78999.mtrfac.render;2 z9 Q( D1 \" z: N L
: D( o* W+ x& d9 B% ^- import com.mojang.blaze3d.vertex.PoseStack;7 W+ x. H2 R2 F/ i# S* O- n* ?
- import com.mojang.blaze3d.vertex.VertexConsumer;- m: v6 o8 g/ z$ p
- import net.minecraft.client.renderer.RenderType;( |6 @7 m; ^8 y8 c4 h+ H
- import net.minecraft.resources.ResourceLocation;
) m+ J7 D3 u( x2 e5 j2 s. u6 G! }9 M2 Q
8 P4 b/ ]. | Z9 L6 l, X( U- import java.util.*;
3 ~3 B$ B3 o( O* j
: G1 ^6 C8 y3 ^* c& |8 N- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ R, u6 y! V% d: f+ u1 `
5 S2 G+ {0 }3 |9 t- public class LineRender{
8 y7 [7 j/ p4 a$ x0 W# U | - private final PoseStack pose;
8 `( z; {/ |8 m3 Z3 i - private final MultiBufferSource source;/ w1 P- z' A$ j# T ?9 |
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 Q9 o- x" f1 e: @
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* F% {- n+ U y% R N/ z7 {; m
- 7 n9 }! \$ z0 c; T5 E u2 {2 W( h
- 6 V* u+ `4 B# m% q
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. X; [7 C8 O$ m+ w. g
- if(x1 == x2 && y1 == y2 && z1 == z2){
" h% r6 J v& G9 a - return;0 s" ^: N/ F3 {: c Y/ i
- }
1 P$ G+ {3 I8 n - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' ~2 @( b* a/ n - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); k3 ^0 t0 v; E! ?. v6 C; T0 j/ Z, Z
- }( f# f+ h1 U, J6 T& @) D% _
- pose.pushPose();
! C. @* `1 v) F l/ p5 ~ - final int newLight = convertLight(6);! `/ h. U/ t& ?& v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* Q; E: n2 B+ c8 w9 c - final float lineHeightSmall = (y2 - y1);
! ~# E2 o+ b3 s9 l2 j- H, V1 I* z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' \1 m5 O% e, q: W( H9 u8 n - pose.popPose();$ i; @4 F$ D q) R4 a/ {8 k
- }
" r! u! E( u5 x6 P6 p$ Q - 3 D+ h% F1 b- Q- f9 x
- private RenderType getLayers(String texture, int light) {- ~3 d5 U6 ]- F
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" p) p/ H6 }( q, x6 h' e
- }
9 c) ~3 L- b1 i7 s - . F$ \( U3 ]. C( q
- private RenderType getLightTexture(ResourceLocation texture) {% M/ M: e! @* f# o3 n
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 s) n/ F9 \( ^1 q+ z9 j - }# ~4 ^8 x D9 Y. u8 g# n
& K4 g) o* p2 N/ X8 r. D! O- private RenderType getTexture(ResourceLocation texture) {4 U& K N1 ~2 e! t1 r& o2 I& Q0 y( r7 F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 n5 V; R' f. M' E L - }* ]/ S: K5 l+ _1 Y6 [
5 ]8 q; f5 s6 H! n- g5 y: H& Z, m- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# O9 r& O# Z1 q( M/ c - if (cache.containsKey(identifier)) {
) P9 m& [& P% t - return cache.get(identifier);6 G- w: }& W4 B5 T7 _& X' X3 m
- } else {/ ~1 J% I% y t. H* `; X6 i
- final RenderType renderLayer = supplier.get();
& K2 {3 r9 J' i( ? - cache.put(identifier, renderLayer);
9 v3 T- ?2 |* C! P - return renderLayer;
; x; K2 s% A2 J& j# p - }
! v/ z% J" H9 x4 ?3 Z - }* B9 h& Y3 i; S& Z
- }
复制代码 |
|