/** * Begins Tree Feller * * @param player Player using Shake Mob * @param mob Targeted entity * @param skillLevel Fishing level of the player */ public static void process(Player player, LivingEntity mob, int skillLevel) { int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player)); if (getShakeProbability(skillLevel) <= Misc.getRandom().nextInt(activationChance)) { return; } Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>(); findPossibleDrops(mob, possibleDrops); if (possibleDrops.isEmpty()) { return; } ItemStack drop = chooseDrop(possibleDrops); // It's possible that chooseDrop returns null if the sum of probability in possibleDrops is // inferior than 100 if (drop == null) { return; } // Extra processing depending on the mob and drop type switch (mob.getType()) { case SHEEP: Sheep sheep = (Sheep) mob; if (drop.getType() == Material.WOOL) { if (sheep.isSheared()) { return; } // TODO: Find a cleaner way to do this, maybe by using Sheep.getColor().getWoolData() // (available since 1.4.7-R0.1) Wool wool = (Wool) drop.getData(); wool.setColor(sheep.getColor()); drop.setDurability(wool.getData()); sheep.setSheared(true); } break; case SKELETON: Skeleton skeleton = (Skeleton) mob; if (skeleton.getSkeletonType() == SkeletonType.WITHER) { switch (drop.getType()) { case SKULL_ITEM: drop.setDurability((short) 1); break; case ARROW: drop.setType(Material.COAL); break; default: break; } } default: break; } Misc.dropItem(mob.getLocation(), drop); CombatTools.dealDamage(mob, 1); // We may want to base the damage on the entity max health }
/** * Shake a mob, have them drop an item. * * @param event The event to modify */ public static void shakeMob(PlayerFishEvent event) { final int DROP_NUMBER = random.nextInt(100); LivingEntity le = (LivingEntity) event.getCaught(); EntityType type = le.getType(); Location loc = le.getLocation(); switch (type) { case BLAZE: m.mcDropItem(loc, new ItemStack(Material.BLAZE_ROD)); break; case CAVE_SPIDER: if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.SPIDER_EYE)); } else { m.mcDropItem(loc, new ItemStack(Material.STRING)); } break; case CHICKEN: if (DROP_NUMBER > 66) { m.mcDropItem(loc, new ItemStack(Material.FEATHER)); } else if (DROP_NUMBER > 33) { m.mcDropItem(loc, new ItemStack(Material.RAW_CHICKEN)); } else { m.mcDropItem(loc, new ItemStack(Material.EGG)); } break; case COW: if (DROP_NUMBER > 99) { m.mcDropItem(loc, new ItemStack(Material.MILK_BUCKET)); } else if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.LEATHER)); } else { m.mcDropItem(loc, new ItemStack(Material.RAW_BEEF)); } break; case CREEPER: m.mcDropItem(loc, new ItemStack(Material.SULPHUR)); break; case ENDERMAN: m.mcDropItem(loc, new ItemStack(Material.ENDER_PEARL)); break; case GHAST: if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.SULPHUR)); } else { m.mcDropItem(loc, new ItemStack(Material.GHAST_TEAR)); } break; case MAGMA_CUBE: m.mcDropItem(loc, new ItemStack(Material.MAGMA_CREAM)); break; case MUSHROOM_COW: if (DROP_NUMBER > 99) { m.mcDropItem(loc, new ItemStack(Material.MILK_BUCKET)); } else if (DROP_NUMBER > 98) { m.mcDropItem(loc, new ItemStack(Material.MUSHROOM_SOUP)); } else if (DROP_NUMBER > 66) { m.mcDropItem(loc, new ItemStack(Material.LEATHER)); } else if (DROP_NUMBER > 33) { m.mcDropItem(loc, new ItemStack(Material.RAW_BEEF)); } else { m.mcDropItems(loc, new ItemStack(Material.RED_MUSHROOM), 3); } break; case PIG: m.mcDropItem(loc, new ItemStack(Material.PORK)); break; case PIG_ZOMBIE: if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.ROTTEN_FLESH)); } else { m.mcDropItem(loc, new ItemStack(Material.GOLD_NUGGET)); } break; case SHEEP: Sheep sheep = (Sheep) le; if (!sheep.isSheared()) { Wool wool = new Wool(); wool.setColor(sheep.getColor()); ItemStack theWool = wool.toItemStack(); theWool.setAmount(1 + random.nextInt(6)); m.mcDropItem(loc, theWool); sheep.setSheared(true); } break; case SKELETON: if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.BONE)); } else { m.mcDropItems(loc, new ItemStack(Material.ARROW), 3); } break; case SLIME: m.mcDropItem(loc, new ItemStack(Material.SLIME_BALL)); break; case SNOWMAN: if (DROP_NUMBER > 99) { m.mcDropItem(loc, new ItemStack(Material.PUMPKIN)); } else { m.mcDropItems(loc, new ItemStack(Material.SNOW_BALL), 5); } break; case SPIDER: if (DROP_NUMBER > 50) { m.mcDropItem(loc, new ItemStack(Material.SPIDER_EYE)); } else { m.mcDropItem(loc, new ItemStack(Material.STRING)); } break; case SQUID: m.mcDropItem(loc, new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x0)); break; case ZOMBIE: m.mcDropItem(loc, new ItemStack(Material.ROTTEN_FLESH)); break; default: break; } Combat.dealDamage(le, 1); }