|
|
% B `, O6 j; y. h# D5 q行,这个怎么样
% C7 s1 e0 U+ W( r- package com.xhg78999.mtrfac.render;
. m) l" {& z2 p2 n" ~ - 6 k7 g$ d* i. n
- import com.mojang.blaze3d.vertex.PoseStack;
E+ T+ m/ E% Y' X" S - import com.mojang.blaze3d.vertex.VertexConsumer;+ ^6 v) i1 k! \8 t* ~
- import net.minecraft.client.renderer.RenderType;
* P! K: n: ?; |- n% u% ]+ G3 h) C2 h& k. i1 | - import net.minecraft.resources.ResourceLocation;& |0 ]+ C% r7 r" z3 D* L6 B4 i
- , `. ]- D5 @1 A. I4 \- s9 ~) o0 Q
- import java.util.*;
* j5 r' }6 `, {$ k- B7 p: ` - ; D( ~: c- o2 g3 w, W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ e+ x/ d' @% W% S; X" Z
! W; K k; z: L& o, Q- public class LineRender{
% A/ r3 u9 o4 F - private final PoseStack pose;
. g D" i1 u. l% ^. v, \ - private final MultiBufferSource source;
/ M/ i" t7 [5 e) p5 F0 y5 l. } - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' z" Q5 ~# x1 j' D - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% @' O( m% E$ j% O- I2 |2 ~
/ T( S3 u% R8 D' u5 O6 U) W8 I
$ d0 Q# j8 E. o4 D% k4 t- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 e; u4 V; _' {$ e) ]' P - if(x1 == x2 && y1 == y2 && z1 == z2){: W/ ^0 ^0 K0 y: D
- return;! x2 L" b$ }. B1 t+ z9 q
- }
9 y. B7 f( J2 E# w/ \6 i - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 H; @) s* M0 d, J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. r# @8 c2 f3 b {/ S% F- X6 q - }
1 [2 N7 H8 y2 `4 A - pose.pushPose();8 S" @* ^# M$ m- b
- final int newLight = convertLight(6);0 F, ?- F- m; C( x9 Z5 X0 J, H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# W+ {8 H% u1 {: A& ^
- final float lineHeightSmall = (y2 - y1);' J: ]2 O! \) O# M
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- U/ X2 ~+ {1 M$ f6 `+ `
- pose.popPose();8 K6 p7 j" B' L) ]$ C3 z
- }
% D. k: E4 X) I# t
8 e9 s3 K8 _5 J% a- private RenderType getLayers(String texture, int light) {
4 A' P& P, w7 p# C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ G9 o% l. O9 R$ k' d. u' r
- }
2 }. `; [# ~7 S
" s# y2 c* ?2 b/ _+ \' r- private RenderType getLightTexture(ResourceLocation texture) {
4 B: F4 a2 O5 n' H - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 N5 G7 l% t4 | - }6 y n Z+ W$ r, }( Q
- S% A( K, c. f
- private RenderType getTexture(ResourceLocation texture) { ~: u$ p2 f0 ]! r% L7 w
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);& a( w* [. `5 B5 H6 M, i
- }8 N5 O6 Q1 o# Q$ ^& l# W
- l9 B. y. |* N6 g) `$ w; h
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 ^& J# |4 T: l6 o0 ? - if (cache.containsKey(identifier)) {: _, F' n9 H* F1 y, l8 a
- return cache.get(identifier);& q4 t/ n! h t& R9 {% o
- } else {7 t/ ~2 z/ l. E' d
- final RenderType renderLayer = supplier.get();
2 C3 ^9 F- K. I9 `2 ?+ ? - cache.put(identifier, renderLayer);# R- ~9 T: d8 }! k% O7 j
- return renderLayer;
- P; ^3 t' }" }# b% t$ v5 f - }
/ \9 u4 H8 P( \ - }
9 r( j- [4 D; m8 K: A7 @ - }
复制代码 |
|