|
|
4 ]; f$ C& _% Z& y% e! f3 n) u行,这个怎么样
; h3 K4 u% \$ N( f2 C/ y- package com.xhg78999.mtrfac.render;" z8 e# D& E" i. C1 C
. [. b- p6 @2 y% y* y- import com.mojang.blaze3d.vertex.PoseStack;
* |; B& G9 p! a$ S - import com.mojang.blaze3d.vertex.VertexConsumer;
J8 Z8 E0 _" b( I3 w+ @8 i3 \, u. [ - import net.minecraft.client.renderer.RenderType;1 m* W6 \6 U+ j, T1 m' [) l0 n
- import net.minecraft.resources.ResourceLocation;8 D: u" T+ F& l! q
- 4 c# N ?4 ^8 O4 N6 A; Y7 s$ J
- import java.util.*;, I) S3 X# r& k
" {2 \0 e% q; _! u; c& t& H5 `0 J- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 H5 `3 S) ]( J$ j3 j* a - ! r8 o$ V5 K G+ p- H, k
- public class LineRender{
% U) {/ @; T- C- W+ S& h } - private final PoseStack pose;. j" k- f! I N/ k. e6 y& [
- private final MultiBufferSource source;! f* a4 E6 E" }" V* q! o+ M
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& \8 Z% G- p/ ^, ?' G4 l - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! ^5 C4 M& D& L( E
7 p) r- p$ _# P6 r( U( w
" ~- D; z2 J6 K- ^$ d, J4 Y- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' Y8 m/ V0 f2 W q: Y( y8 x ?
- if(x1 == x2 && y1 == y2 && z1 == z2){" f4 [" G6 ^4 O
- return;
& ~2 Z9 |8 d' n6 Q - }% r" }. B! A2 ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* Y* U' x. R' u, k' C; c# p
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' [, }" f$ \9 N! V; U- J
- }3 x E* [$ [6 z3 L5 d. s3 z
- pose.pushPose();
+ Z, C6 V9 i) G) W) k. e, ] - final int newLight = convertLight(6);
& ?/ f4 v* i2 e P6 L2 m- u - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 w3 T5 F, H% f Q/ |7 P - final float lineHeightSmall = (y2 - y1);
- i* d! H( z! t; ? - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 q7 ~) d, r: O8 d" H( Q; l
- pose.popPose();6 [7 d9 H2 Z' F( P! D$ O
- }) @0 t$ ]% ^1 ~, ~! D9 Z
, L" P; n0 l8 D5 z1 w- c, B- private RenderType getLayers(String texture, int light) {4 r, j+ E7 }- P; D4 c3 `7 ?; r
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( p) m* H! Z( k - }
) W7 B, b+ M$ R1 b6 a1 L* n - 1 x; I6 D. G! E& e+ L& ?
- private RenderType getLightTexture(ResourceLocation texture) {
, q7 y, q4 B( V8 R8 [ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ W- t H+ L5 c2 J) w% H - }; M4 J" O, u! |) r4 h
, p* e/ U! c1 V6 A# s; a: T- private RenderType getTexture(ResourceLocation texture) {
+ \: s( |" h' [. D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 X" l5 c% e' V4 ?; j
- }) s j2 ?" ^6 c, W7 Q: ?: k
- 1 n- n6 |2 R* [; e; y% |
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, H7 |% X% b) k4 L/ f# W0 p0 r - if (cache.containsKey(identifier)) {
2 i+ l2 M% X+ ? z1 \ - return cache.get(identifier);
& D( t8 v, l2 z1 P - } else {
- O% o, v0 m7 h. U( p' V - final RenderType renderLayer = supplier.get();$ O; C2 w: N0 v0 A* {8 s
- cache.put(identifier, renderLayer);( M+ a% N1 a! _. C8 r9 Z* J
- return renderLayer;( y( N, p# j8 f1 q
- }$ L2 b! E- d( ^
- }7 N X( g7 B9 z3 M
- }
复制代码 |
|