#distance issue

1 messages · Page 1 of 1 (latest)

full thistle
#

okay so i have a spawner block that has a entity inside to check distance and store information for the spawner.

anyways, i am having troubles with only checking the distance of each spawnrule. just the same concept of saying in command execute as @e at @e[type=mrleefy:spawnrule] unless entity @e[type=mrleefy:blazestill, r=50] run summon mrleefy:blazestill ~~1~

okay so this will check if any stackable entities are already nearby, unless there is one it will summon a new one. This is the spawning logic to get new one to show up if none is created already.

Now i need to do the same thing, but opposite with the api.

i need it like this somehow>>

execute as @e at @e[type=mrleefy:spawnrule] if entity @e[type=mrleefy:blazestill, r=50] run change nametag to +1.

this is essentially the logic im trying to follow for the api.

how do i do this?

attached is the latest code.

visual to explain:

they(spawnrule invisible entity inside block) shouldn't add +1 to the same stackable entity if they are further then 50 blocks away from itself. it should be local to itself like the commands are with execute as.

#

this runs most of the logic in the system.runInterval

system.runInterval(() => {
  const spawnruleEntities = world.getDimension("overworld").getEntities({ type: "mrleefy:spawnrule" });
  spawnruleEntities.forEach(spawnruleEntity => {
    if (!spawnruleEntity.isValid()) {
      return;
    }
    const intervalTicks = stackMap.get(spawnruleEntity);
    stackMap.set(spawnruleEntity, intervalTicks);
    const nearbyEntities = world.getDimension("minecraft:overworld").getEntities({
      type: `mrleefy:${entityType}`,
      maxDistance: radius,
      location: spawnruleEntity.location
    });
    const hurtEntities = nearbyEntities.filter(entity => entity.getComponent("health").currentValue <= 0);
    if (hurtEntities.length > 0) {
      return;
    }
    const stackedEntities = nearbyEntities.filter(entity => entity.nameTag.startsWith(`${entityType} x`));
    if (stackedEntities.length > 0 && stackedEntities[0].nameTag.includes(`x${maxStackSize}`)) {
      return;
    }
    world.getDimension("overworld").runCommandAsync(`execute as @e at @s[type=mrleefy:spawnrule,name="${spawnruleEntity.nameTag}"] unless entity @e[type=mrleefy:${entityType},r=50] run summon mrleefy:${entityType} ~~1~`);
    const dimension = world.getDimension("overworld");
    const entities = dimension.getEntities({ type: `mrleefy:${entityType}` });
    const entity = entities[0];
    let amount = Number(entity.nameTag?.substring(/(?<!!)#/g.exec(nameTagConfig)?.index ?? 0)?.replace(/,/g, '')?.match(/\d+/)?.shift() ?? 0);
    if (amount < maxStackSize) {
      amount += 1;
    }
    const entityValues = validMobs.find(v => v.typeId === entity.typeId);
    if (amount <= maxStackSize) {
      entity.nameTag = nameTagConfig
        .replace(/(?<!!)#/g, String(amount).replace(/\B(?=(\d{3})+(?!\d))/g, ','))
        .replace(/(?<!!)@/g, entityValues?.displayName)
        .replace(/!(?=@|#)/g, '');
    }
  });
}, intervalTicks);
#

this is the area you wanna look at, where the summoning and the add to name first if there is an entity stack nearby already, otherwise it summons the entity

ashen galleon
#

@full thistle what are you trying to make i dont get it ?

full thistle
#

Nvm then

#

Spawner systemi found an alt option anyways 🙂