filler

Banana Hammer

Like the potato Hammer in minecraft, but it drops bananas on hit with a 30% chance

← Back to main

Code Block:


api.giveItem(playerId, "Gold Spade", 1, {
  customDisplayName: "Banana Hammer",
  customAttributes: {
    enchantments: {
      "Horizontal Knockback": 10
      ,"Vertical Knockback": 5
    },
    enchantmentTier: "Tier 5"
  }
});
      

World Code:


onPlayerDamagingOtherPlayer = (attackingPlayer, damagedPlayer, damageDealt, withItem, bodyPartHit, damagerDbId) => {
  const held = api.getHeldItem(attackingPlayer);
  const pos = api.getPosition(attackingPlayer);

  // Check if holding Potato Hammer
  if (!held || held.name !== "Gold Spade" || held.attributes?.customDisplayName !== "Potato Hammer") return;

  // 30% chance to trigger banana drop
  if (Math.random() < 0.3) {
    const bananaCount = Math.floor(Math.random() * 11) + 5; // Random number from 5 to 10

    for (let i = 0; i < bananaCount; i++) {
      const offsetX = Math.floor(Math.random() * 9) - 4; // -1 to 1
      const offsetZ = Math.floor(Math.random() * 9) - 4; // -1 to 1
      const dropX = pos[0] + offsetX;
      const dropY = pos[1] + 1;
      const dropZ = pos[2] + offsetZ;

      api.createItemDrop(dropX, dropY, dropZ, "Banana", 1, false);
    }
  }
};