|
|
8 X B: F% m4 ]: u- E: l4 t' G
行,这个怎么样
4 P0 V- u* N9 h3 Z* R$ H- package com.xhg78999.mtrfac.render;
4 w t% ?/ r( _, i5 Q; p% I - 2 m T/ P k6 W4 C+ |! G+ u* A# R. q0 C6 R
- import com.mojang.blaze3d.vertex.PoseStack; [' u# _4 Y3 G: R2 G: }
- import com.mojang.blaze3d.vertex.VertexConsumer;3 _3 [9 t. N+ W( \ j" R+ s j
- import net.minecraft.client.renderer.RenderType;
( {: N* H; g: S; N) u& N# U0 I - import net.minecraft.resources.ResourceLocation;
9 m( k% }) c& |) B- h( {6 \+ r2 N
0 c4 m! b- U5 u5 P, k1 d: m, S- import java.util.*;3 u' ^$ T' j4 [4 I
- 1 [4 b* h6 n! z; L Y. Y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& R. W) l- F7 V; b# _
- ! P2 }3 j1 ~; r
- public class LineRender{
0 E; ]& r7 l* z D* z+ \# H8 |6 B - private final PoseStack pose;
2 m- Z' [: }$ h6 V1 b7 N' I - private final MultiBufferSource source;7 y- k" B) p7 u+ e8 A4 O
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* X1 |/ U* }8 y* d% Z" b" A) C2 S% w - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" i8 s5 D9 Z3 C- }) V
- 6 h4 |) ?' }4 f6 N& y: j
- ; b" K+ t* a6 d+ R. g3 ], |6 O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ ^/ K2 `% C5 ^: G - if(x1 == x2 && y1 == y2 && z1 == z2){" H( W# m. t/ W( s" u8 p4 z
- return;7 X- d8 @# }: r4 M0 i
- }
0 ?* d; g% R1 G; A( J - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
( J- I7 G. k3 m& J" g% p7 O" r - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
$ A1 r; Y$ E( ~$ `* o% B, j/ l4 f - }
# h: t" F! K: g7 I; x5 ?" { - pose.pushPose();
9 Q3 N9 N% y, y6 c - final int newLight = convertLight(6);4 j4 i4 D/ g; n& f' P' |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ m, K! L2 l% x+ f - final float lineHeightSmall = (y2 - y1);
* e& |, [, I7 `, } - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 u) ^9 \6 k2 s8 B+ n0 y - pose.popPose();: Y* x) t& C) E9 ?& v! Z
- }3 O+ G1 t8 T9 X2 _* A; l: M
% }" K* r; k! H1 k: {" `! ~- private RenderType getLayers(String texture, int light) {
* u9 L3 M/ L0 Q - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- }& V" ], q2 D
- }
$ u- H' ]$ V6 [
) i% a$ b. o0 a* g! l- private RenderType getLightTexture(ResourceLocation texture) {
% X7 E U" t3 t) Q! S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. A* |& Y7 m% O; R$ U. J/ m
- }8 D9 Z( p! H4 ?
0 x+ z2 i+ `+ i; A! E- private RenderType getTexture(ResourceLocation texture) {- F! F" T0 J* ^# E n4 c" d8 W
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% N* l0 \) o1 s6 i8 W7 Q - }* p% `' z6 L# s: p6 v# R
- ' }* P' [3 C; E) M3 H
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# A0 L& d3 P; L9 K$ f9 Q - if (cache.containsKey(identifier)) {
& v6 q3 ?+ Y I X - return cache.get(identifier);
! Q) b3 t/ c. j6 T - } else {
5 W/ o4 x* y. n3 h: M. I - final RenderType renderLayer = supplier.get();& i; n7 {( \# `' \- N0 X& }' W
- cache.put(identifier, renderLayer);$ S. t! o2 t5 w: u- u) L% G
- return renderLayer;
! C3 |- _ d T. @2 P - }
. d6 R3 t7 y* U+ q! J: I: x! g$ V - }& I1 ]; A: f( T, b E. ~* K* \
- }
复制代码 |
|