|
|
, H1 ~$ |' K2 C5 k行,这个怎么样, i4 s/ N! t; X5 t% D
- package com.xhg78999.mtrfac.render;; b- p7 y3 B+ [; @" q& B" `
5 h0 d* H4 e4 A/ @- X5 l; M6 c- I( r- import com.mojang.blaze3d.vertex.PoseStack;
1 p+ `% @& d8 I0 U$ j6 q - import com.mojang.blaze3d.vertex.VertexConsumer;7 F% x5 \: i" H3 ]
- import net.minecraft.client.renderer.RenderType;2 t2 W/ }/ V" X6 M+ g8 h. X$ V5 N
- import net.minecraft.resources.ResourceLocation;
/ D/ k, D8 J1 X# O$ a+ ?6 \ b( _0 E - . P$ ^6 x9 s( x+ k4 B) Y
- import java.util.*;
6 D4 ?! {1 x, M8 g6 s( W
# P) D* \' s( h- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% t6 E5 {0 |1 n1 D7 ~1 S7 V
7 [1 f& b8 s" B' {; [8 W- public class LineRender{
$ n, b' B8 ]: n7 o - private final PoseStack pose;& k' J" c m; p+ q7 f. o7 V
- private final MultiBufferSource source;
$ E3 J% ], a/ E+ q) D% V1 ?( z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: A" A* w4 e* x" e - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! j } v& s4 c( d9 l$ \. y" `
9 e7 ?& F: {$ @! p+ W- - T6 j$ R! I4 I* D
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 F& S* A. S n8 Z8 T6 H4 f k
- if(x1 == x2 && y1 == y2 && z1 == z2){
0 a$ @8 ?" Q8 Q9 O( [, d6 @5 P - return;
% Y0 c8 Q% D5 P( T$ O - }
! h: o2 _7 D O; s - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 M0 h0 q, ]8 M' e& Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& Y$ v5 R# ^7 w
- }
# n: m2 K; h( ?# H2 n - pose.pushPose();
" P+ C8 L+ P& n# q$ [* b - final int newLight = convertLight(6);% g. K* R6 a- q9 h k) v$ b
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 K/ X& R4 x/ B7 I
- final float lineHeightSmall = (y2 - y1);9 z1 k2 l, y; B( F; K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! m; Q& ^, e3 f2 ~3 J - pose.popPose();
( u- T/ r; `' y/ u/ ] m' ` - }
) g6 W8 X) N- U' J; F) R - & Z. g) i, K6 R3 D+ o- V) v
- private RenderType getLayers(String texture, int light) {9 h# ^+ w, {. X2 Y$ {& b. w
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 t$ P6 T2 `. w0 x - }
, q0 o- _- n, L8 A! ?( F. D - 7 C1 y- m) l& q8 D, X
- private RenderType getLightTexture(ResourceLocation texture) {
* U; f7 L \8 G6 I - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 m! J2 n/ P2 E4 }$ p- O2 X
- }' Z, V8 P! y, W5 b; ~3 f
- 8 s" j; S; _* i: `/ {1 l
- private RenderType getTexture(ResourceLocation texture) {
1 J$ \+ W# D# ?# S5 N, Y3 V - return this.cache(texture, () -> entityCutout(texture), CACHE_B);; D7 s" ?1 N1 H/ G' n: z2 ^$ g
- }1 @5 `9 Y* J" S( w9 v0 L9 Z
- ! S, i+ e: B8 Y0 ?
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ Y' a; I( N) O, T: z+ i: Q
- if (cache.containsKey(identifier)) {
# y- b, @: I) m6 g0 R$ R( n - return cache.get(identifier);8 g1 T( F- D: O$ W- W9 x+ ^
- } else {
* H5 m; X P7 a$ N/ J) `, f - final RenderType renderLayer = supplier.get();. o! O2 l: N% I: k. N; F
- cache.put(identifier, renderLayer);1 U3 Z* j9 p! C' G
- return renderLayer; D, G6 d/ A1 \) j S; @% d
- }" h1 B4 S) f# D$ s5 V: x
- }
7 @, d" g: @4 R5 \ - }
复制代码 |
|