|
|
0 [) {/ K6 E" u" \: ~. G
行,这个怎么样* |3 h) U6 @7 w! u
- package com.xhg78999.mtrfac.render;
2 B7 N1 p) d: {1 ?* M - * h6 H9 U& }1 `& U% h6 J3 O' G
- import com.mojang.blaze3d.vertex.PoseStack;( @& v" s" e% b8 i0 l/ _( C
- import com.mojang.blaze3d.vertex.VertexConsumer;
. L+ J) C) C4 Q. D0 y/ [ - import net.minecraft.client.renderer.RenderType;8 r' y9 t! T# l- {4 p0 O2 b
- import net.minecraft.resources.ResourceLocation;2 _1 v; O) Q8 k! j5 b4 E8 J2 p5 J
- - n L- q$ g& Q3 ?
- import java.util.*;
4 e- x( d5 q# N( s
$ m' F7 B, v/ o. ?+ V- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# A* L: E' s9 |; O* z6 ?; T( l - ! ^4 T* o2 J- {- o: y' b4 c% k
- public class LineRender{
1 h6 _( x% X% q- r - private final PoseStack pose;# F* J: ]* C- Z, f' X
- private final MultiBufferSource source;' _1 \8 M; t9 j. N. R
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 L5 {" }2 ?" d/ n! y/ V H
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 M7 Z7 i5 [; ~( d
/ n5 H) O. b% ]+ ~- ; W% U% D l9 K- {1 f
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 X! V" P- o C, M: @, t
- if(x1 == x2 && y1 == y2 && z1 == z2){
- c* z$ X' Z/ k$ ` - return;
, g$ N, r+ ]( e, \. T( _; @ - }: p$ {9 v/ o% R& E: t% ~! d4 B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, `" P8 E9 s% k2 p
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) W, k4 ?9 M2 ?0 Z2 @ - }* b" m& e( \+ }+ B
- pose.pushPose();6 d9 ~' [3 Y9 w: T" E; T; Z5 p
- final int newLight = convertLight(6);6 J4 @7 u' E$ ?5 v) Q5 y, t5 ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 S1 T9 u. O! w+ U& i3 | - final float lineHeightSmall = (y2 - y1);% h: M B- p; k) n9 r$ c% T
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);, n0 I( x/ {& c' I5 s% \9 e
- pose.popPose();
: |3 q* X6 {% T3 l% p1 S4 o - }
G- a4 J7 [1 ^0 ~$ p - 1 d, `$ z8 o5 B! W7 d& A
- private RenderType getLayers(String texture, int light) {, [! R# f( O* r% \9 S; ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' v" N7 B5 T' A: M: d% f
- }
, `: n i; O4 Y
! P5 ~; Z' Y) L e5 E' R4 ]- private RenderType getLightTexture(ResourceLocation texture) {
$ u7 _, q6 ^% G, ?& d l - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);% g# y2 [0 o/ }! L# I
- }
V0 }& J+ {6 }' z- Y. V5 M
) d9 E& |- p7 z: Q- k( m ?/ D- private RenderType getTexture(ResourceLocation texture) {
1 E4 l; _2 y8 w$ y% ~1 K7 X - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, p+ y+ C( n& b* c9 C! X, J- w, v0 z - }
/ z1 A4 m o' f6 `4 I0 b0 K5 q: z
8 V I7 T; C4 d9 L$ v- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 g, s# P( _9 B6 V9 z
- if (cache.containsKey(identifier)) {
0 r6 \8 \0 f8 |0 D - return cache.get(identifier);# `. i2 `" `2 h8 y
- } else {
9 p" ]' v( E* w - final RenderType renderLayer = supplier.get();
# L% {/ @7 k: `) k$ _/ \. P% V3 m - cache.put(identifier, renderLayer);% I; [# K- U; R5 f# q9 G
- return renderLayer;. k* G" ^1 f9 p6 M+ \
- }
% E, e; b; k4 p - }
0 M+ _, X; X- b' B - }
复制代码 |
|