|
|
, w" [2 {! l4 _4 {
行,这个怎么样4 r% y+ t0 @$ E( h( u3 J: S
- package com.xhg78999.mtrfac.render;
9 E6 n0 y% f4 ~$ O6 }
% ]. _, u% p' l2 }8 D7 a- import com.mojang.blaze3d.vertex.PoseStack;
, B2 Z; b3 ?/ a) U, p - import com.mojang.blaze3d.vertex.VertexConsumer;
" d! `$ @% ~+ K. Q, b - import net.minecraft.client.renderer.RenderType;
3 c# z$ `! k, J+ }; c - import net.minecraft.resources.ResourceLocation;5 ~! t6 c7 o# M! k2 b- L
4 q6 ~% D" {. v: r9 Z: _- import java.util.*;
; I8 r! N7 T4 g; f - 7 R( |' }8 D, ?& b% z8 s. n
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 P: Q7 c4 N7 n5 L0 R* V - 4 s) {& b; y4 H$ o6 I& r9 p# v8 [
- public class LineRender{
! O- c+ j6 _9 Z- A; u( G+ ^5 x - private final PoseStack pose;; M, E& y6 G/ V/ w! n# u" {$ }
- private final MultiBufferSource source;5 U" L0 B/ \& M+ W' j" N( Z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();; n; n9 l! U7 A3 \
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, r) o$ a- Y. B# {: q& m
& f7 C# W7 c' } E& D2 j5 |8 j- 3 p. t8 [8 @6 U4 f2 T+ F3 T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ \, |4 i, [1 y
- if(x1 == x2 && y1 == y2 && z1 == z2){, H5 N) o( O$ O" M" N4 c
- return;8 R, e( M* }2 M4 q
- }) \2 T d. F$ G% W. l; a
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 q: N+ }9 q0 e" F - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); `$ ]5 R5 ?( G8 Q
- }
. d+ p! q( M1 f0 J - pose.pushPose(); O5 k/ k8 ~( D1 y3 ]& f' a/ U
- final int newLight = convertLight(6);$ s" |% g5 F7 s$ {( C3 y8 X
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 x& ?4 k1 q, X
- final float lineHeightSmall = (y2 - y1);
* ]* X5 ]+ Q) z9 W: Y6 U - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 I% \! |/ `; \! ] - pose.popPose();" u" @4 J, r& z7 ?3 l
- }
: l! r/ {- B8 H7 O - ' I7 e" O& }/ P" t/ `5 W$ r3 G
- private RenderType getLayers(String texture, int light) { |5 Z% V+ u) w* @! h. @# O
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ t4 x6 m7 {0 K& p - }0 h/ i C& R- m# x. n' B* d
- l C- A1 t% e9 V) l8 n
- private RenderType getLightTexture(ResourceLocation texture) {* V& q) S: @% _/ z9 C
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* Y) s% [4 |* n' y- q. u p - }
1 t) K" }+ ?0 @/ X4 s6 x$ p$ I
: w9 h, P5 r( s; [- private RenderType getTexture(ResourceLocation texture) {6 {2 P' F: \5 i+ P' w* V% B
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);8 o2 G' J1 R! x1 F1 w' B
- }
, T! k2 K/ N8 `& ^. K, G& z% N) l
5 u9 n6 S- Q: j7 h; j5 }- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
9 d* y9 k6 s8 q+ W" w s - if (cache.containsKey(identifier)) {
: Z3 m9 b0 r3 c) O0 }- [ - return cache.get(identifier);/ K c' _* Z/ H5 ^+ _/ J
- } else {
, {1 s: }9 X! j - final RenderType renderLayer = supplier.get();9 v; ?' G' l% }% Q5 @7 w D
- cache.put(identifier, renderLayer);$ B" [3 g( p8 v2 ^; C
- return renderLayer;
! T) ?0 v0 H, C% l; Q - }
% n2 k2 [ F, C. K1 x7 o( k - }
/ } Q2 H% v5 |# G1 t - }
复制代码 |
|