#runCommand not firing
52 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
`let player = event.player.getName().getString()
//if(event.player.block.id == 'kubejs:interdimensional_portal') {}
if(event.player.level.dimension == 'minecraft:overworld') {
if (event.player.y <= -64) {
event.server.runCommandSilent('effect give ' + player + ' minecraft:blindness 2 1 false')
//event.server.runCommandSilent('effect give ' + player + ' minecraft:slow_falling 1 1 false')
event.server.runCommand('execute as gattoh at @e[tag=IsPiercerPortalOverworld,sort=nearest,distance=0..50] in minecraft:the_nether run tp @s ~ 180 ~')
}
return
}`
Show the whole script.
Also, put your script between three backticks, like so:
```js
let x = "Hello world!"
```
let x = "Hello world!"
PlayerEvents.tick(event => {
let player = event.player.getName().getString()
//if(event.player.block.id == 'kubejs:interdimensional_portal') {}
if(event.player.level.dimension == 'minecraft:overworld') {
if (event.player.y <= -64) {
event.server.runCommandSilent('effect give ' + player + ' minecraft:blindness 2 1 false')
//event.server.runCommandSilent('effect give ' + player + ' minecraft:slow_falling 1 1 false')
event.server.runCommand('execute as gattoh at @e[tag=IsPiercerPortalOverworld,sort=nearest,distance=0..50] in minecraft:the_nether run tp @s ~ 180 ~')
}
return
}
})```
I have tried the execute command on its own with a command block and that works
the effect commands work so I'm not sure why that one doesn't
I have no idea what the nearest entity with the tag IsPiercerPortalOverworld and distance between 0 and 50 is, what's its purpose?
Maybe there's an easier way to get the thing you want to do working and without any commands.
@hearty sinew
So far, I have this:
PlayerEvents.tick((event) => {
const { player } = event;
// @ts-expect-error
if (player.level.dimension == "minecraft:overworld") {
if (player.y <= -64) {
event.player.potionEffects.add("minecraft:blindness", 2, 1, false, false);
event.player.teleportTo(
"minecraft:the_nether",
player.x,
180,
player.z,
player.yaw,
player.pitch
);
}
return;
}
});
But for the whole thing I am missing this piece of info
There is a stationary armorstand with that tag in the overworld and I'm trying to tp the player to the armorstand's coords in the nether
Hmm, so maybe this could be done more simply with JS and without armor stand, I'm trying to learn what's the purpose of the armor stand.
Does it have to move? What decides on armor stand's coords?
It's summoned from a Multiblocked2 machine that puts it at the machine's coords but always at y=-64
And it should always stay at the same position
It's used as a marker for a 'portal' and to replace the portal's blocks when a Create machine breaks it
basically
machine summons armorstand
armorstand creates and marks the portal
Mhm, I see
Check this out:
const $TargettingConditions = Java.loadClass(
"net.minecraft.world.entity.ai.targeting.TargetingConditions"
);
const $ArmorStand = Java.loadClass(
"net.minecraft.world.entity.decoration.ArmorStand"
);
const $AABB = Java.loadClass("net.minecraft.world.phys.AABB");
PlayerEvents.tick((event) => {
const { level, player } = event;
if (
player.level.dimension == "minecraft:overworld" &&
player.y <= -64 &&
player.age % 4 == 0
) {
event.player.potionEffects.add("minecraft:blindness", 2, 1, false, false);
// Dumb Rhino bug, yay!
let armorStands = level.getEntitiesOfClass(
$ArmorStand,
new $AABB([player.x, player.y, player.z]).inflate(50)
);
let targetting = $TargettingConditions
.forNonCombat()
.ignoreInvisibilityTesting()
.ignoreLineOfSight()
.range(50)
.selector((entity) => entity.tags.contains("IsPiercerPortalOverworld"));
let anchor = level.getNearestEntity(
armorStands,
targetting,
player,
player.x,
player.y,
player.z
);
if (anchor != null) {
event.player.teleportTo(
"minecraft:the_nether",
anchor.x,
180,
anchor.z,
player.yaw,
player.pitch
);
}
}
});
Due to dumb Rhino bug, the temporary variables have to be let despite not being changed later on
This one has the same issue of not teleporting but also the potion effect gets rapidly given for 0 seconds instead of 2
The potion effect is given for 2 ticks
ah that makes sense in commands it's seconds
And from my testing, I did get teleported to the location of armor stand
Any additional info about that armor stand?
(like, is it invisible, no AI, how did you create it, etc?)
These are the nbt:
{NoGravity:1b,Silent:1b,Invulnerable:1b,Marker:1b,Tags:["IsPiercerPortal","IsPiercerPortalOverworld"],CustomName:'{"text":"PiercerPortalOverworld"}'}
Thanks!
So far I see that getNearestEntity for some reason can't detect the entity with Marker set to true
I don't think it will be a problem if I just take that out
Yep that works
very many thanks
Wait
I made something that works even with Marker set
const $ArmorStand = Java.loadClass("net.minecraft.world.entity.decoration.ArmorStand");
const $AABB = Java.loadClass("net.minecraft.world.phys.AABB");
PlayerEvents.tick((event) => {
const SECOND = 20;
const { level, player } = event;
/**
* @template {Internal.LivingEntity} T
* @param {Internal.List<T>} entityList
* @param {[x: number, y: number, z: number]} playerPos
* @param {(entity: T) => boolean} predicate
*/
function getNearestEntity(entityList, playerPos, predicate) {
var maxDistance = -1;
var distance = 0;
/** @type {T} */
var nearestEntity = null;
entityList.forEach((entity) => {
if (predicate(entity)) {
distance = entity.distanceToSqr(playerPos);
if (maxDistance == -1 || distance < maxDistance) {
maxDistance = distance;
nearestEntity = entity;
}
}
});
return nearestEntity;
}
if (player.level.dimension == "minecraft:overworld" && player.y <= -64 && player.age % 4 == 0) {
event.player.potionEffects.add("minecraft:blindness", 2 * SECOND, 1, false, false);
// Dumb Rhino bug, yay!
let armorStands = level.getEntitiesOfClass(
$ArmorStand,
new $AABB([player.x, player.y, player.z]).inflate(50)
);
let anchor = getNearestEntity(
armorStands,
[player.x, player.y, player.z],
(entity) => entity.tags.contains("IsPiercerPortalOverworld")
);
if (anchor != null) {
event.player.teleportTo(
"minecraft:the_nether",
anchor.x,
180,
anchor.z,
player.yaw,
player.pitch
);
}
}
});
oh nice
forgot the last parenthesis
There
would it be less intensive if I ran this every 10 ticks?
Is there a way to make the event.player.teleportTo silent?
What do you mean by "silent"?
like runCommandSilent
It is silent
so it doesn't show up in chat
Since that's not a command
oh nvm those were just the ones from getting out of the nether
one last thing
what is this for? player.age % 4 == 0
Runs every 4 ticks
Thanks