|
|
1 Y3 T: A, J3 U7 L. U行,这个怎么样
, \5 m2 z P. V- package com.xhg78999.mtrfac.render;# E5 ^( N5 P7 ?" K; R* G/ S
- 7 G% T- b& j' A$ B1 D- R
- import com.mojang.blaze3d.vertex.PoseStack;
) n6 t L: K/ E# B9 D - import com.mojang.blaze3d.vertex.VertexConsumer;) y: Y5 G# S3 |3 X
- import net.minecraft.client.renderer.RenderType;
4 s) o" s5 d; l1 @+ o' e; {3 U - import net.minecraft.resources.ResourceLocation;" Y7 P$ h2 Z! w
$ ?8 f+ _( z0 D2 C6 P; }- import java.util.*;
) n+ m) W8 E% L! i0 d
5 g5 x* I: b" U _0 O- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 r( e: w/ N+ R% V% `/ ~5 K5 k
& w5 }) J1 ~2 i `2 C( X: U- public class LineRender{
, s% A7 z; h/ a0 _7 E' _8 _ Z& g. U4 g - private final PoseStack pose;3 q+ q; t. _% F, O" Q
- private final MultiBufferSource source;
/ Q) D3 |5 ^" o/ n5 o* Q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 ]& I; ?8 ^% l, \+ K. @
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 R' q( a* D3 ~, Y) f; [ - - p" Y& [2 |! `; Y5 s+ h, i
, ^ N& L% P2 G! [8 v- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( K: R6 v* B" m
- if(x1 == x2 && y1 == y2 && z1 == z2){; \# z: \8 V+ r) F, _& {: y' l
- return;
( g8 o8 f1 R0 x! a - }+ E }% i U2 @' E5 `) h2 o
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 A0 o- |& Y+ }+ `8 z: v$ A f - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");: N3 e5 g* o8 x$ m1 f
- }
1 {% l( p, v/ T - pose.pushPose();
. F9 e+ U7 x G& [7 H0 H - final int newLight = convertLight(6);
. k9 J n+ t' a: P- N! w - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* [3 s! p3 p! x4 k7 L9 f3 |; i# _' ? - final float lineHeightSmall = (y2 - y1);- Y& ?( Y H `2 i8 e
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 |: O! a% Z0 ~4 h - pose.popPose();
\% A$ ]" C. g) [# N6 q - }& u8 M2 x/ a# e" R% c* r# |* m* @
- ' E* o9 \2 |0 O4 J( @
- private RenderType getLayers(String texture, int light) {
& d' ?9 K; Q) Y# e0 F - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- L. d/ w$ t/ J, _: J2 R7 Z
- }
1 D& j- t) a1 D: J3 j! ^
) P. R- C: m E$ R# C1 m3 q. W/ R- private RenderType getLightTexture(ResourceLocation texture) {7 M8 r* U0 M2 X* u% k
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; L2 s, a0 y- ^- Y# ~ - }
% ~$ ~# [' P& ^! p1 X
, `- B! B8 Z# K% x- private RenderType getTexture(ResourceLocation texture) {# M' z4 ]8 \! | T3 f* ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 l: d* H% L: {7 T - }$ `% F% ~1 U: D
_: h% B- y; d G5 U. A- `- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 L) q, A5 Q7 d+ v5 H - if (cache.containsKey(identifier)) {4 h' ~% V: O5 o
- return cache.get(identifier);
3 D3 G/ e: k% x: c$ [5 i% c - } else {
6 ~2 [& |3 V+ f! ~/ N- h - final RenderType renderLayer = supplier.get();
2 H2 X- {' X" t6 u, P! m - cache.put(identifier, renderLayer);. u$ Q5 t* }( v# s7 y/ y4 p! \, i
- return renderLayer;
3 G6 w7 _' ?1 D6 U% T1 t- A - }1 T( M4 e1 o7 ?' v- t; B
- }0 _5 _! Y7 D, C8 S9 V' F+ j/ T! W
- }
复制代码 |
|