-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtdtp.ts
78 lines (70 loc) · 3.58 KB
/
tdtp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//------------------------------------------------------------------------------//
// Transdimenstion Teleport //
// script for BDSX //
// (tdtp.ts/tdtp.js) //
// by randommouse/madeofstown //
//------------------------------------------------------------------------------//
// Use/Function: //
// Teleport Players Across Dimensions //
//------------------------------------------------------------------------------//
// Required Custom Scripts: //
// plyerlist.ts/playerlist.js //
// Recommended Custom Scripts: //
// index.ts/index.js //
//------------------------------------------------------------------------------//
// Thansks to P Jai Rjlin and their work @ //
// https://github.com/Rjlintkh/bdsx-scripts/blob/main/scripts/minecraftFunctions.ts //
//------------------------------------------------------------------------------//
import { command } from "bdsx/command";
import { Actor } from "bdsx/bds/actor";
import { RelativeFloat, Vec3 } from "bdsx/bds/blockpos";
import { ActorWildcardCommandSelector } from "bdsx/bds/command";
import { int32_t, void_t } from "bdsx/nativetype";
// Get "tdtp" command permission
const perms = require(`${__dirname}/perms.json`);
// Teleport function
/**
* @description Trans-dimension teleportation with relative coordinates
* @example tdTeleport(playerActor, { value: 10 }, { value: -10, is_relative: true }, new RelPos(10, false), 1 )
*/
export function tdTeleport(actor: Actor, x: RelPos, y: RelPos, z: RelPos, dimensionId?: number): void {
let pos = new Vec3(true);
if (x.is_relative == true) {
pos.x = actor.getPosition().x + x.value
} else {pos.x = x.value}
if (y.is_relative == true) {
pos.y = actor.getPosition().y + y.value - 1.62
} else {pos.y = y.value}
if (z.is_relative == true) {
pos.z = actor.getPosition().z + z.value
} else {pos.z = z.value}
let dimId: number
if (dimensionId != undefined && dimensionId <= 2 && dimensionId >= 0) {
dimId = parseInt(dimensionId.toFixed(0))
} else { dimId = actor.getDimensionId()}
// console.log(`Teleporting *${actor.getName()}* TO *${DimensionId[dimId]} @ ${pos.x} ${pos.y} ${pos.z}`)
actor.teleport(pos, dimId);
}
/**
* @description Reltive position
* @example let x = new RelPos(0)
* let y = new RelPos(20, true)
* let z = new RelPos(100)
*/
export class RelPos {
value: number
is_relative?: boolean
constructor(value: number, is_relative?: boolean){
this.value = value
if (is_relative != undefined) {
this.is_relative = is_relative
}
}
}
// Register Command: '/tdtp <target> <x> <y> <z> <dimensionID>
command.register('tdtp', 'Trans-dimension teleportation', perms.tdtp).overload((param, origin, output) => {
// console.log(origin);
for (const actor of param.target.newResults(origin)) {
tdTeleport(actor, param.x, param.y, param.z, param.dimensionID);
}
}, {target: ActorWildcardCommandSelector, x: RelativeFloat, y: RelativeFloat, z: RelativeFloat, dimensionID: int32_t});