|
|
% w) z0 ]* s+ u4 F$ d行,这个怎么样
0 }6 @8 @3 d) ^! s9 u. a/ d- package com.xhg78999.mtrfac.render;6 a4 H( v2 t- q. Q! B9 m& ]. S
: @8 _5 L. x& I& D7 q- import com.mojang.blaze3d.vertex.PoseStack;% Y3 P6 q! t3 r8 ~
- import com.mojang.blaze3d.vertex.VertexConsumer;
9 q7 d1 }" b8 X. M* U - import net.minecraft.client.renderer.RenderType;
4 `! \' C& |. A - import net.minecraft.resources.ResourceLocation;/ z, i$ `- P% @* b' d/ m
- 2 R1 N f/ E# G9 E
- import java.util.*;
1 f8 _8 ~, i2 \8 R# w, ?
+ J" ^9 E6 n$ {: J+ s0 k3 A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
D& w, h7 i, Z A# u - l1 f/ n% b U: ^2 U$ ^5 ?+ X* ~
- public class LineRender{
* o8 F: j& H0 B2 i. l' T, @3 P - private final PoseStack pose;" p: s; s4 t% B0 s& N# B
- private final MultiBufferSource source;6 ^- e5 n% ^% g. T2 i* [
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 t/ [( A: ^6 `+ q# ?1 i5 a# | - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 M3 @! P1 D0 B0 x3 S2 y
- , i% q5 f/ Q* K* j6 S
- + J( j, L5 Q2 \$ ?2 z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 y) T2 D, a7 _ - if(x1 == x2 && y1 == y2 && z1 == z2){
- r- J! P& n9 @" P - return;5 E4 a' [+ ?7 s. R
- }" C: b9 P; ]$ ^2 S; {9 Q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: I* l6 d/ E6 ~3 V& o0 l
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 R) }( h5 B" J) d |, k - }
- X8 _" n" V0 l# m! b - pose.pushPose(); S% _5 |5 N, o( s' D6 h8 Y. _
- final int newLight = convertLight(6);
; j0 t4 p# _7 u1 w5 z+ o - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" j9 l" w7 X( N. W& F# n# M
- final float lineHeightSmall = (y2 - y1);
# L% a! P) E3 f7 N+ C. ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);7 K) X: c% h. L$ z5 q
- pose.popPose();
5 D$ \: [& _6 A, ` - }
6 t+ [* O, X X3 [! n/ A1 V& p
' K u ?7 I0 Y2 l1 v- private RenderType getLayers(String texture, int light) {
/ X' N/ W0 a0 J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- b2 ~' \2 ?' V% k - }
2 `4 d- t! a. Z: y7 a4 V - / K+ r! |1 e& w3 F0 v7 ?/ ]( B; H
- private RenderType getLightTexture(ResourceLocation texture) {
8 x# h: d6 Y5 b - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 |5 t! ]# `+ f, W6 d8 ? - }
& W7 b& B. Y) n, p
$ m/ E; d/ u+ _/ q/ v- private RenderType getTexture(ResourceLocation texture) {
' O8 y, u- P: t2 v - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 s% r1 O5 V T7 \4 | - }
3 O2 q8 s D$ F/ h1 t9 ]
6 _) `, e% \- w5 v+ Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
( K1 S, Z- m) i - if (cache.containsKey(identifier)) {
& c0 w2 X2 C1 e+ z" m$ E: D8 {* c - return cache.get(identifier);
9 r9 a( m- q6 @ - } else {7 Y% A) w; s1 d6 X
- final RenderType renderLayer = supplier.get();* a, e1 A. i/ B# d' Z
- cache.put(identifier, renderLayer);
5 S/ O. {9 A* @$ J - return renderLayer;( X r, `# I. W; ^
- }% d& p8 c) n" n) d# x
- }
1 N; \. w( P/ J, o2 y - }
复制代码 |
|