Search in sources :

Example 1 with MushroomCow

use of org.bukkit.entity.MushroomCow in project modules-extra by CubeEngine.

the class ListenerPlayerEntity method onPlayerInteractEntityEvent.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof LivingEntity)) {
        return;
    }
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    ActionPlayerEntity action;
    if (player.getItemInHand().getType() == COAL && entity instanceof PoweredMinecart) {
        action = this.newAction(UseFurnaceMinecart.class, entity.getWorld());
    } else if (player.getItemInHand().getType() == INK_SACK && entity instanceof Sheep || entity instanceof Wolf) {
        action = this.newAction(EntityDye.class, entity.getWorld());
        if (action != null) {
            ((EntityDye) action).setColor(((Dye) player.getItemInHand().getData()).getColor());
        }
    } else if (player.getItemInHand().getType().equals(BOWL) && entity instanceof MushroomCow) {
        action = this.newAction(EntityFillSoup.class, entity.getWorld());
    } else {
        return;
    }
    if (action != null) {
        action.setEntity(entity);
        action.setPlayer(player);
        action.setLocation(entity.getLocation());
        this.logAction(action);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) Dye(org.bukkit.material.Dye) Player(org.spongepowered.api.entity.player.Player) MushroomCow(org.bukkit.entity.MushroomCow) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) Sheep(org.bukkit.entity.Sheep) Wolf(org.bukkit.entity.Wolf) EventHandler(org.bukkit.event.EventHandler)

Example 2 with MushroomCow

use of org.bukkit.entity.MushroomCow in project StackMob-2 by Nathat23.

the class ShearEvent method onSheepShear.

@EventHandler
public void onSheepShear(PlayerShearEntityEvent event) {
    if (!event.getEntity().hasMetadata(GlobalValues.METATAG)) {
        return;
    }
    if (event.getEntity().getMetadata(GlobalValues.METATAG).get(0).asInt() <= 1) {
        return;
    }
    Entity oldEntity = event.getEntity();
    int stackSize = event.getEntity().getMetadata(GlobalValues.METATAG).get(0).asInt();
    if (oldEntity instanceof Sheep) {
        Sheep oldSheep = (Sheep) oldEntity;
        if (sm.config.getCustomConfig().getBoolean("multiply.sheep-wool")) {
            Wool wool = new Wool(oldSheep.getColor());
            sm.dropTools.dropDrops(wool.toItemStack(1), sm.dropTools.calculateAmount(stackSize), oldEntity.getLocation());
            ItemStack item = event.getPlayer().getItemInHand();
            item.setDurability((short) (item.getDurability() + stackSize));
            event.getPlayer().setItemInHand(item);
        } else if (sm.config.getCustomConfig().getBoolean("divide-on.sheep-shear")) {
            Sheep newEntity = (Sheep) sm.tools.duplicate(oldEntity, true);
            newEntity.setSheared(false);
            newEntity.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, stackSize - 1));
            newEntity.setMetadata(GlobalValues.NO_SPAWN_STACK, new FixedMetadataValue(sm, true));
            oldEntity.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, 1));
            oldEntity.setCustomName(null);
        }
    }
    if (oldEntity instanceof MushroomCow) {
        if (sm.config.getCustomConfig().getBoolean("multiply.mooshroom-mushrooms")) {
            ItemStack mushrooms = new ItemStack(Material.RED_MUSHROOM, 1);
            sm.dropTools.dropDrops(mushrooms, (stackSize - 1) * 5, oldEntity.getLocation());
            // SpawnEvent cow for the rest of the cows that where sheared.
            Entity cow = oldEntity.getWorld().spawnEntity(oldEntity.getLocation(), EntityType.COW);
            cow.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, stackSize - 1));
            cow.setMetadata(GlobalValues.NO_SPAWN_STACK, new FixedMetadataValue(sm, true));
            ItemStack item = event.getPlayer().getItemInHand();
            item.setDurability((short) (item.getDurability() + stackSize));
            event.getPlayer().setItemInHand(item);
        } else if (sm.config.getCustomConfig().getBoolean("divide-on.mooshroom-shear")) {
            Entity mushroomCow = oldEntity.getWorld().spawnEntity(oldEntity.getLocation(), EntityType.MUSHROOM_COW);
            mushroomCow.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, stackSize - 1));
            mushroomCow.setMetadata(GlobalValues.NO_SPAWN_STACK, new FixedMetadataValue(sm, true));
            oldEntity.setCustomName(null);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) MushroomCow(org.bukkit.entity.MushroomCow) Sheep(org.bukkit.entity.Sheep) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Wool(org.bukkit.material.Wool) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 3 with MushroomCow

use of org.bukkit.entity.MushroomCow in project EliteMobs by MagmaGuy.

the class MushroomCowHandler method onShear.

@EventHandler
public void onShear(PlayerShearEntityEvent event) {
    if (event.getEntity() instanceof MushroomCow && EntityTracker.isSuperMob(event.getEntity())) {
        MushroomCow mushroomCow = (MushroomCow) event.getEntity();
        ItemStack mushroomStack = new ItemStack(RED_MUSHROOM, 5);
        for (int i = 0; i < 50; i++) {
            mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), mushroomStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
        }
    }
}
Also used : MushroomCow(org.bukkit.entity.MushroomCow) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 4 with MushroomCow

use of org.bukkit.entity.MushroomCow in project EliteMobs by MagmaGuy.

the class MushroomCowHandler method superDrops.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void superDrops(EntityDamageEvent event) {
    if (event.getFinalDamage() < 1)
        return;
    if (event.getEntity() instanceof MushroomCow && EntityTracker.isSuperMob(event.getEntity())) {
        Random random = new Random();
        MushroomCow mushroomCow = (MushroomCow) event.getEntity();
        double damage = event.getFinalDamage();
        // health is hardcoded here, maybe change it at some point?
        double dropChance = damage / 10;
        double dropRandomizer = random.nextDouble();
        // this rounds down
        int dropMinAmount = (int) dropChance;
        ItemStack beefStack = new ItemStack(BEEF, (random.nextInt(3) + 1));
        // leather can drop 0, meaning that it could create visual artifacts. Have to filter that out.
        ItemStack leatherStack = new ItemStack(LEATHER, (random.nextInt(2)));
        for (int i = 0; i < dropMinAmount; i++) {
            mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), beefStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
            ExperienceOrb xpDrop = mushroomCow.getWorld().spawn(mushroomCow.getLocation(), ExperienceOrb.class);
            xpDrop.setExperience(random.nextInt(3) + 1);
            if (leatherStack.getAmount() != 0) {
                mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), leatherStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
            }
        }
        if (dropChance > dropRandomizer) {
            mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), beefStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
            ExperienceOrb xpDrop = mushroomCow.getWorld().spawn(mushroomCow.getLocation(), ExperienceOrb.class);
            xpDrop.setExperience(random.nextInt(3) + 1);
            if (leatherStack.getAmount() != 0) {
                mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), leatherStack).setVelocity(ItemDropVelocity.ItemDropVelocity());
            }
        }
    }
}
Also used : MushroomCow(org.bukkit.entity.MushroomCow) Random(java.util.Random) ExperienceOrb(org.bukkit.entity.ExperienceOrb) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MushroomCow (org.bukkit.entity.MushroomCow)4 EventHandler (org.bukkit.event.EventHandler)4 ItemStack (org.bukkit.inventory.ItemStack)3 Sheep (org.bukkit.entity.Sheep)2 Random (java.util.Random)1 Entity (org.bukkit.entity.Entity)1 ExperienceOrb (org.bukkit.entity.ExperienceOrb)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Wolf (org.bukkit.entity.Wolf)1 PoweredMinecart (org.bukkit.entity.minecart.PoweredMinecart)1 Dye (org.bukkit.material.Dye)1 Wool (org.bukkit.material.Wool)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1 Entity (org.spongepowered.api.entity.Entity)1 Player (org.spongepowered.api.entity.player.Player)1