|
|
l9 { k6 K& b2 ^, d$ q/ R4 g
行,这个怎么样
' J' |* E g" h/ [3 y1 e- package com.xhg78999.mtrfac.render;
: x' s- |5 {6 y; C% b0 I& J7 a0 L# x
0 h& m' i- W! H- import com.mojang.blaze3d.vertex.PoseStack; s4 y. l- q8 O# s/ z
- import com.mojang.blaze3d.vertex.VertexConsumer;8 ^9 R, P( Y4 D5 f7 I# T: L2 m
- import net.minecraft.client.renderer.RenderType;2 E+ y& U9 o i9 z
- import net.minecraft.resources.ResourceLocation;
5 w# G* ?: j x* L - 3 ?3 v8 Q4 z. e1 k7 ^6 }" o
- import java.util.*;
0 s; ~, ?5 q, R1 H' s - 5 M( d; H9 s+ D2 g) n8 Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ @3 F& F( C) x, Y. j! ?, {, E
0 X9 J1 n, s1 C* J6 y2 v- public class LineRender{
: |$ u- f6 y2 `1 a2 s9 J0 d - private final PoseStack pose;, r4 d' V# n" K/ |: U* h
- private final MultiBufferSource source;, b0 f( }: H' y! x+ X6 n9 H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();* G9 L7 T( X( r$ V" n7 b' y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 m, e3 U: T) h% o1 C
' \( M7 R+ x2 ~& n) H2 }9 F1 p4 d
$ p. x! r; v t6 E9 g# \- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 V1 C- F8 u" X' S& y
- if(x1 == x2 && y1 == y2 && z1 == z2){
) N4 E" L" l( D! @5 D" o - return;! `$ T& r/ y( s
- }+ M o* m" x7 [5 i) W m
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: @( b0 e V- ~' v7 O: a& ?4 X - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 b9 e, W% j; T
- }
$ r; w( s j6 n( O - pose.pushPose();
, `5 V! {$ @/ C0 S - final int newLight = convertLight(6);
# \# `- {. [0 M$ N - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" c/ b$ L7 _% Q5 { - final float lineHeightSmall = (y2 - y1);
! Z7 m: R$ |1 | - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 E/ |% u4 S& U" D: o - pose.popPose();
- L: A' q" s0 z/ k - }
0 G- w% S; q! O' [0 \$ ?; l - 1 x4 D" Q# {4 L! p/ H W0 L
- private RenderType getLayers(String texture, int light) {
4 \& q( o1 M2 G4 N5 t - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% |. l3 c3 ]) j6 _" T5 M
- }
5 q! G4 {7 A4 S) f - / b0 J5 D4 E( n, ^+ d$ T
- private RenderType getLightTexture(ResourceLocation texture) {& L$ y7 D1 M: W
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ \1 T- z7 b3 y* ~9 S! c# U
- }
0 j3 P/ w+ i$ s d: l - " I1 ?) Z+ _8 u z5 Q
- private RenderType getTexture(ResourceLocation texture) {0 B% ~# w$ _0 n' H: }
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ i* J0 _" N, J) Q) z- ]) ]! ~
- }" A. o/ \( C) U: u/ U
$ P' m; d& s3 q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, q1 C: K8 J+ o! U$ U - if (cache.containsKey(identifier)) {: K) n. U! L. @) ~, S8 u( D
- return cache.get(identifier);
e3 a O* b$ N - } else {# ?" X% _0 c7 u% E" L' h" K0 x
- final RenderType renderLayer = supplier.get();5 l& T( b: F8 ~1 @4 V# {
- cache.put(identifier, renderLayer);
6 v2 e$ N& L0 ] u2 o - return renderLayer;
8 c3 y6 y0 P9 s# L6 N3 H0 m - }1 S! `, ^; G( @& J6 S& j6 B0 F
- }
3 G+ R- N& }; Z% ~ - }
复制代码 |
|