#runCommand not firing

52 messages · Page 1 of 1 (latest)

hearty sinew
#

I'm trying to make things happen while under a certain y value but the execute command is not firing

forest marshBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hearty sinew
#

`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
}`
lapis leaf
#

Show the whole script.
Also, put your script between three backticks, like so:
```js
let x = "Hello world!"
```

let x = "Hello world!"
hearty sinew
#
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

lapis leaf
#

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;
  }
});
lapis leaf
hearty sinew
lapis leaf
#

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?

hearty sinew
#

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

lapis leaf
#

Mhm, I see

lapis leaf
#

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

hearty sinew
lapis leaf
hearty sinew
#

ah that makes sense in commands it's seconds

lapis leaf
#

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?)

hearty sinew
#

These are the nbt:
{NoGravity:1b,Silent:1b,Invulnerable:1b,Marker:1b,Tags:["IsPiercerPortal","IsPiercerPortalOverworld"],CustomName:'{"text":"PiercerPortalOverworld"}'}

lapis leaf
#

Thanks!

#

So far I see that getNearestEntity for some reason can't detect the entity with Marker set to true

hearty sinew
#

I don't think it will be a problem if I just take that out

#

Yep that works

#

very many thanks

lapis leaf
#

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
      );
    }
  }
});
hearty sinew
#

oh nice

lapis leaf
#

There

hearty sinew
#

would it be less intensive if I ran this every 10 ticks?

lapis leaf
#

It's your choice

#

Code inside the if won't run anyway if either condition isn't met

hearty sinew
#

Is there a way to make the event.player.teleportTo silent?

lapis leaf
#

What do you mean by "silent"?

hearty sinew
#

like runCommandSilent

lapis leaf
#

It is silent

hearty sinew
#

so it doesn't show up in chat

lapis leaf
#

Since that's not a command

hearty sinew
#

oh nvm those were just the ones from getting out of the nether

#

one last thing

#

what is this for? player.age % 4 == 0

lapis leaf
#

Runs every 4 ticks

hearty sinew
#

Thanks