|
|
6 N9 ]: }$ o& W! `8 F! `5 j行,这个怎么样
2 z( c4 v6 `! r. g" [4 E9 E- package com.xhg78999.mtrfac.render;
! |; ?8 s- W. e% `# H - 7 x- q0 C$ |$ N9 O: y
- import com.mojang.blaze3d.vertex.PoseStack;
, v" x2 R& L* s+ v: C& ? - import com.mojang.blaze3d.vertex.VertexConsumer;
& F; U; T7 r3 U, v9 v9 t3 |$ l - import net.minecraft.client.renderer.RenderType;
4 c6 c! |$ o1 c8 y. R/ p1 I, }* m - import net.minecraft.resources.ResourceLocation;* n8 x1 l) E' M( P' I O* _' i/ M6 ]
- ) J6 t" `7 `# C' \1 c5 i" ?
- import java.util.*;4 E. p- @) L7 L
. n* Z6 l$ S" R" P( k: [2 F- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(- W/ i& n* R" @
- 6 f: Q" L8 n3 E2 \% y, V/ @9 v2 S
- public class LineRender{$ @( o2 M( E4 `1 f' m
- private final PoseStack pose;% v% t& ?0 u* _2 \ ^
- private final MultiBufferSource source;
$ e5 d ~* U7 u2 X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();( O% |$ J" Z3 h% |9 r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 U* m6 ~' g& K- \! g
$ n5 i3 H( B/ ~0 s- Q( k7 _1 m3 e5 ^1 ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 z# c# s) F( ?7 L0 ]: s8 [ - if(x1 == x2 && y1 == y2 && z1 == z2){/ S; Q; K1 p0 D$ m# ]$ f
- return;
_( ?0 O8 p- g) N3 R/ z - }& `/ _7 H7 `; o, H6 ~- J
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
Y6 l% Q) V2 m- G# G - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 s& T- O3 `* R- `' J
- }
. n( O. S! `0 h! \3 D! R7 E5 j$ e7 J% x - pose.pushPose();# x9 b u2 z7 o- k
- final int newLight = convertLight(6);7 A7 J2 @2 B. }5 h; W
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));- S1 ^1 \2 p( u9 S; D6 \
- final float lineHeightSmall = (y2 - y1);
$ H9 `4 R. r2 @. R6 M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) v0 [# g9 q) M! N+ C - pose.popPose();
3 |- V% A& w# `2 [+ X' z - }
0 e- Z5 y; a0 w8 R/ V. S+ E* _% p9 d - * h( l: l6 ~ q: ]
- private RenderType getLayers(String texture, int light) {$ I) H0 M- @. J3 j3 \! x4 e
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* ]( U$ R1 D0 I/ A3 o& l+ x - }
2 `) c" S( E8 E+ Q+ I
) e% U- S$ S' p# f2 U( l- private RenderType getLightTexture(ResourceLocation texture) {
# ^" A7 d) a) r+ K7 ?1 N( j- i" v - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; M& T4 @, U& a$ I5 z" z# G- z: ] - }, q* q2 W; c5 B5 W) f( ~
- ) I& H; b: z4 I7 r7 [! f
- private RenderType getTexture(ResourceLocation texture) {
; G( r' R5 F+ v1 S U; L - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ `- R S2 Y }0 x8 Q - }0 V. R# S2 ]- _! e2 ]* O% \7 s2 |
- 5 X9 \" y$ p. F$ Q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' l* A* C0 \+ K7 I z# N" I - if (cache.containsKey(identifier)) {+ [2 N" N0 Y* Y9 o$ T, v8 u1 k2 o
- return cache.get(identifier);* L0 B( p a# P8 g! R& O5 N" [
- } else {9 m, B9 p" q# }+ _7 k8 f6 O4 M
- final RenderType renderLayer = supplier.get();
2 u9 S* X B, h8 z6 z* \4 k/ \ - cache.put(identifier, renderLayer);
$ E% f1 R8 p* z - return renderLayer;# H6 @, h5 ]: \& s& I- k1 E
- }" s" ~( y2 ^; m2 t: L' b
- }6 d- j4 l3 g' x2 i
- }
复制代码 |
|