|
|
/ W) |/ o9 ^- B+ @" t行,这个怎么样
0 R" \$ n/ F& Y/ V- package com.xhg78999.mtrfac.render;
% z. @0 l" F F7 U8 J
/ O) p5 k; B9 @" y$ r/ J; R: m- import com.mojang.blaze3d.vertex.PoseStack;
$ {5 a! K' |( k! Y! Y$ Z- m T1 w" s - import com.mojang.blaze3d.vertex.VertexConsumer;& b) L, l9 d5 m/ p
- import net.minecraft.client.renderer.RenderType;$ a2 ]7 F3 Q5 l' H
- import net.minecraft.resources.ResourceLocation;
1 |5 o0 c, s) t8 Z - / Q# C$ q" w/ Q! A S% M) |! d
- import java.util.*;
" k8 F" q s! h7 l/ `$ C - ]& }7 x b( D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' ~* O$ J F7 K7 ?; x) o
9 z6 ?0 s7 j" `1 i# a8 S) z- public class LineRender{
4 C; o7 s% z/ p* ~8 p - private final PoseStack pose;$ v! K# g3 |: e& O
- private final MultiBufferSource source;
. [9 u) O) \$ J. z/ {8 y/ z. O - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ j+ x( w' Q$ L! L - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% A. v D8 g: o- D) c" x
) J8 a8 R" t7 s7 ^. N# R- : m& o& |' P( V* D
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 C. q. V9 n+ U3 r7 p5 m7 S: D
- if(x1 == x2 && y1 == y2 && z1 == z2){$ w% X h ^" h. ]
- return;
# ~0 _# S* K6 s7 v) \% `5 [) W; P - }' @9 M1 _- D4 C+ M* d$ |
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( k1 v. O8 V% l1 M- v
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) Y; z. W' t4 X V- n
- }
: c* k9 A6 [; A: d - pose.pushPose();
6 a. d* ]" A# S; i2 l - final int newLight = convertLight(6);1 f4 q5 S- u4 L9 ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 t4 q/ s# f: q3 _: \% a" ~ - final float lineHeightSmall = (y2 - y1);: ^3 t, {7 X6 p3 Z& ?! B
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ B+ a* C. s# Q - pose.popPose();5 ]# v" j% c' R4 u; y
- }1 [2 T) I8 W( @/ z7 `: U1 C
- 1 p6 ]# t' Q; g. l) E
- private RenderType getLayers(String texture, int light) {
- w) I! r) ]5 F' Y! v! O" k - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; R3 p; A1 N* O! H
- }& B+ p) M+ H/ m# F6 l- k
8 X" L! y$ w& O$ h' e% a9 O6 S: `- private RenderType getLightTexture(ResourceLocation texture) {' y5 o; d \! x9 h
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ _/ n/ g( W. H# f2 V) Y# f; N
- }
+ M" i3 B+ h! Z) g5 ^: u4 T
9 j) U w5 Z' s. e7 y. l- private RenderType getTexture(ResourceLocation texture) {0 t) \& q6 J1 u. X. T5 R; L$ Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);( |" ?* U' A7 c& u% T: E
- }
( ]2 \, C- r3 f) N$ u4 F3 | - T1 H8 V3 E4 e1 }. Q- o
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 l' B- ]3 b/ H; X u6 k+ W7 d0 w+ g5 F
- if (cache.containsKey(identifier)) {% y, J! I. t# ~, ?% p
- return cache.get(identifier);
% U% y" n2 S1 ^/ z. t# _5 R - } else {4 [3 g X v& g
- final RenderType renderLayer = supplier.get();, b" E( Z+ n% D
- cache.put(identifier, renderLayer);
6 w1 s$ H& `/ C6 d+ ]& l - return renderLayer;
9 r: O1 o0 m, v# G- |# ? - }
( |( J& d' J' m5 I$ [" Z - }
t7 _* R5 X0 ]9 G+ t - }
复制代码 |
|