#Any way to make a delay so that the player doesn't pick up the item again? Or can't I pick it up?

1 messages · Page 1 of 1 (latest)

tidal cave
#

I already made a code so that the item moves if it is in a certain slot, but I wanted that when the inventory would be full, that item would be spawned and removed from the inventory, but it loops

import { world } from '@minecraft/server';
const moveToEmptySlot = (inventory, itemIndex) => {
  for (let i = 0; i < 29; i++) {
    const emptySlot = inventory.getItem(i);
    if (emptySlot === undefined) {
      inventory.transferItem(itemIndex, i, inventory);
      return true;
    }
  }
  return false;
};

world.events.tick.subscribe(async () => {
  try {
    const players = world.getAllPlayers();
    for (const player of players) {
      const inventory = player.getComponent("inventory").container;
      for (let i = 29; i < 36; i++) {
        const item = inventory.getItem(i);
        const itemId = item?.typeId;
        if (itemId === undefined) continue;
        
        const accessory = Object.values(accessories).find(a => a.id_name === itemId);
        if (accessory === undefined) {
          if (!moveToEmptySlot(inventory, i)) {
            // No hay slots disponibles, ejecutar función
            // ...
            //await player.dimension.runCommandAsync("say si sirve bro")
            try {
              player.dimension.spawnItem(item, player.headLocation);
              inventory.clearItem(i);
            } catch (err) {
              world.say("" + err)
            }
          }
        } else {
          console.warn("Senyu  " + accessory.id_name);
          console.warn("MC " + itemId);
        }
      }
    }
  } catch (err) {
    console.warn(err);
  }
});
#

extra code: (the message was too long to send it all together)


const accessories = {
  senyu_brute_brazalet: {
    id_item: 1,
    id_name: "senyu:brute_brazalet"
  },
  senyu_eternal_meat: {
    id_item: 2,
    id_name: "senyu:eternal_meat"
  },
  senyu_life_necklace: {
    id_item: 3,
    id_name: "senyu:life_necklace"
  },
  senyu_ultimate_shield: {
    id_item: 4,
    id_name: "senyu:ultimate_shield"
  },
  senyu_diving_goggles: {
    id_item: 5,
    id_name: "senyu:diving_goggles"
  }
};

tidal cave
#

Any way to make a delay so that the player doesn't pick up the item again? Or can't I pick it up?

potent prawn
#

There is no good way how to do it

#

u can only check for inventory, and if he pick up item u can place it back

night dagger
#

I had a method of spawning it a few blocks in front of the player with starting velocity

#

search "force drop"

potent prawn
#

ya, but this is not problem problem is u must search in inventory for newly addet items

tidal cave
potent prawn
#

idk, u must throw it longer distance

#

there is no actualy other way

nocturne ivy
#

so you need to save the player.dimension.spawnItem(...) returned entity object into a variable