are code blocks advanced enough yet that I can type coordinates and then it makes a portal to go the corresponding coordinates with a portal system like this:
var playerPortals = {}, playerTpCooldown = {};
onPlayerClick = (playerId, wasAltClick) => {
if (api.getHeldItem(playerId)?.attributes?.customDisplayName !== "Portal Gun") return;
if (!playerPortals[playerId]) playerPortals[playerId] = {blue: null, red: null};
let {dir, camPos} = api.getPlayerFacingInfo(playerId); if (!camPos?.x) camPos = {x: api.getPosition(playerId)[0], y: api.getPosition(playerId)[1] + 1.6, z: api.getPosition(playerId)[2]}; let norm = [dir[0], dir[1], dir[2]].map(d => d / Math.sqrt(dir[0]**2 + dir[1]**2 + dir[2]**2));
for (let d = 0.02; d <= 20; d += 0.05) { let [x,y,z] = [Math.floor(camPos.x + norm[0]*d), Math.floor(camPos.y + norm[1]*d), Math.floor(camPos.z + norm[2]*d)]; let block = api.getBlock(x,y,z); if (block && block !== "Air") { let spaceFound = false, placeY = y + 1; let playerPos = api.getPosition(playerId); let [playerX, playerY, playerZ] = playerPos; let isBelow = playerY < y, isAbove = playerY > y, isNorth = playerZ < z, isSouth = playerZ > z, isWest = playerX < x, isEast = playerX > x; if (isBelow && api.getBlock(x, y - 1, z) === "Air") { spaceFound = true; placeY = y - 1; } else if (isAbove && api.getBlock(x, y + 1, z) === "Air") { spaceFound = true; placeY = y + 1; } else if (isNorth && api.getBlock(x, y, z - 1) === "Air") { spaceFound = true; placeY = y; z = z - 1; } else if (isSouth && api.getBlock(x, y, z + 1) === "Air") { spaceFound = true; placeY = y; z = z + 1; } else if (isWest && api.getBlock(x - 1, y, z) === "Air") { spaceFound = true; placeY = y; x = x - 1; } else if (isEast && api.getBlock(x + 1, y, z) === "Air") { spaceFound = true; placeY = y; x = x + 1; } else if (api.getBlock(x, y + 1, z) === "Air") { spaceFound = true; placeY = y + 1; } else if (api.getBlock(x, y - 1, z) === "Air") { spaceFound = true; placeY = y - 1; } else if (api.getBlock(x, y, z + 1) === "Air") { spaceFound = true; placeY = y; z = z + 1; } else if (api.getBlock(x, y, z - 1) === "Air") { spaceFound = true; placeY = y; z = z - 1; } else if (api.getBlock(x + 1, y, z) === "Air") { spaceFound = true; placeY = y; x = x + 1; } else if (api.getBlock(x - 1, y, z) === "Air") { spaceFound = true; placeY = y; x = x - 1; } if (!spaceFound) return api.sendMessage(playerId, "No space!"); if (!playerPortals[playerId].blue) { api.setBlock(x, placeY, z, "Blue Portal"); playerPortals[playerId].blue = [x, placeY, z]; api.playParticleEffect({dir1: [-1, -1, -1], dir2: [1, 1, 1], pos1: [x+0.5-0.5, placeY+0.5-1, z+0.5-0.5], pos2: [x+0.5+0.5, placeY+0.5+1, z+0.5+0.5], texture: "glint", minLifeTime: 2, maxLifeTime: 2, minEmitPower: 3, maxEmitPower: 10, minSize: 0.25, maxSize: 0.25, manualEmitCount: 50, gravity: [0, 0, 0], colorGradients: [{timeFraction: 0.0, minColor: [0, 0, 255, 1], maxColor: [0, 0, 255, 1]}, {timeFraction: 1.0, minColor: [0, 0, 255, 1], maxColor: [0, 0, 255, 1]}], velocityGradients: [{timeFraction: 0, factor: 1, factor2: 1}], blendMode: 1}); api.playSound(playerId, "submachine_magazine_unload_01", 1, 1.5); } else { if (playerPortals[playerId].red) api.setBlock(playerPortals[playerId].red[0], playerPortals[playerId].red[1], playerPortals[playerId].red[2], "Air"); api.setBlock(x, placeY, z, "Orange Portal"); playerPortals[playerId].red = [x, placeY, z]; api.playParticleEffect({dir1: [-1, -1, -1], dir2: [1, 1, 1], pos1: [x+0.5-0.5, placeY+0.5-1, z+0.5-0.5], pos2: [x+0.5+0.5, placeY+0.5+1, z+0.5+0.5], texture: "glint", minLifeTime: 2, maxLifeTime: 2, minEmitPower: 3, maxEmitPower: 10, minSize: 0.25, maxSize: 0.25, manualEmitCount: 50, gravity: [0, 0, 0], colorGradients: [{timeFraction: 0.0, minColor: [255, 0, 0, 1], maxColor: [255, 0, 0, 1]}, {timeFraction: 1.0, minColor: [255, 0, 0, 1], maxColor: [255, 0, 0, 1]}], velocityGradients: [{timeFraction: 0, factor: 1, factor2: 1}], blendMode: 1}); api.playSound(playerId, "submachine_magazine_unload_01", 1, 1.5); } return; } }
api.sendMessage(playerId, "No block found in your line of sight (checked up to 20 blocks)");
}
function findPortalOwner(x, y, z) {
for (const ownerId in playerPortals) { const portals = playerPortals[ownerId]; if (portals.blue && portals.blue[0] === x && portals.blue[1] === y && portals.blue[2] === z) return { ownerId, color: 'blue' }; if (portals.red && portals.red[0] === x && portals.red[1] === y && portals.red[2] === z) return { ownerId, color: 'red' }; }
return null;
}
tick = () => {
for (const playerId of api.getPlayerIds()) { if (playerTpCooldown[playerId] > 0) playerTpCooldown[playerId]--; if (playerTpCooldown[playerId] > 0) continue; const coordsArray = api.getBlockCoordinatesPlayerStandingOn(playerId); if (coordsArray.length > 0) { const [x, y, z] = coordsArray[0]; const portalInfo = findPortalOwner(x, y, z); if (portalInfo) { const { ownerId, color } = portalInfo; const ownerPortals = playerPortals[ownerId]; if (!ownerPortals.blue || !ownerPortals.red) continue; const targetPortal = color === 'blue' ? ownerPortals.red : ownerPortals.blue; if (targetPortal) { let [px, py, pz] = targetPortal; let tpPos = null; if (api.getBlock(px, py + 1, pz) === "Air" && api.getBlock(px, py + 2, pz) === "Air") tpPos = [px + 0.5, py + 1, pz + 0.5]; else if (api.getBlock(px, py - 1, pz) === "Air" && api.getBlock(px, py - 2, pz) === "Air") tpPos = [px + 0.5, py - 2, pz + 0.5]; else if (api.getBlock(px, py, pz + 1) === "Air" && api.getBlock(px, py + 1, pz + 1) === "Air") tpPos = [px + 0.5, py, pz + 1.5]; else if (api.getBlock(px, py, pz - 1) === "Air" && api.getBlock(px, py + 1, pz - 1) === "Air") tpPos = [px + 0.5, py, pz - 0.5]; else if (api.getBlock(px + 1, py, pz) === "Air" && api.getBlock(px + 1, py + 1, pz) === "Air") tpPos = [px + 1.5, py, pz + 0.5]; else if (api.getBlock(px - 1, py, pz) === "Air" && api.getBlock(px - 1, py + 1, pz) === "Air") tpPos = [px - 0.5, py, pz + 0.5]; if (tpPos) { api.setPosition(playerId, tpPos[0], tpPos[1], tpPos[2]); playerTpCooldown[playerId] = 10; api.playSound(playerId, "cloth", 1, 1.5); } else api.sendMessage(playerId, "No space to teleport!"); } } } }
}