Search in sources :

Example 1 with SheepRegrowWoolEvent

use of org.bukkit.event.entity.SheepRegrowWoolEvent in project Glowstone by GlowstoneMC.

the class GlowSheep method pulse.

@Override
public void pulse() {
    super.pulse();
    // wool regrowth
    final int rand = ThreadLocalRandom.current().nextInt(1000);
    if ((isAdult() && rand == 1) || (!isAdult() && rand < 20)) {
        // Check that the block underneath the sheep is grass
        final Block block = getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (block.getType() != Material.GRASS_BLOCK) {
            return;
        }
        SheepRegrowWoolEvent event = new SheepRegrowWoolEvent(this);
        event = EventFactory.getInstance().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        // Make the entity animate
        playEffect(EntityEffect.SHEEP_EAT);
        // After 40 ticks (the animation duration) make the wool regrow
        getServer().getScheduler().runTaskLater(null, () -> {
            // Replace the grass with dirt
            block.setType(Material.DIRT);
            // Make the wool regrow
            if (isSheared()) {
                setSheared(false);
            }
        }, 40);
    }
}
Also used : SheepRegrowWoolEvent(org.bukkit.event.entity.SheepRegrowWoolEvent) Block(org.bukkit.block.Block)

Example 2 with SheepRegrowWoolEvent

use of org.bukkit.event.entity.SheepRegrowWoolEvent in project RoseStacker by Rosewood-Development.

the class EntityListener method onSheepRegrowWool.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSheepRegrowWool(SheepRegrowWoolEvent event) {
    if (this.stackManager.isWorldDisabled(event.getEntity().getWorld()))
        return;
    if (!this.stackManager.isEntityStackingEnabled())
        return;
    Sheep sheepEntity = event.getEntity();
    StackedEntity stackedEntity = this.stackManager.getStackedEntity(sheepEntity);
    if (stackedEntity == null || stackedEntity.getStackSize() == 1)
        return;
    SheepStackSettings sheepStackSettings = (SheepStackSettings) stackedEntity.getStackSettings();
    double regrowPercentage = sheepStackSettings.getPercentageOfWoolToRegrowPerGrassEaten() / 100D;
    int regrowAmount = Math.max(1, (int) Math.round(stackedEntity.getStackSize() * regrowPercentage));
    if (sheepEntity.isSheared()) {
        sheepEntity.setSheared(false);
        regrowAmount--;
    }
    if (regrowAmount < 1)
        return;
    int fRegrowAmount = regrowAmount;
    Bukkit.getScheduler().runTaskAsynchronously(this.rosePlugin, () -> {
        int remaining = fRegrowAmount;
        List<Sheep> sheepList = StackerUtils.deconstructStackedEntities(stackedEntity).stream().map(x -> (Sheep) x).collect(Collectors.toList());
        for (Sheep sheep : sheepList) {
            if (sheep.isSheared()) {
                sheep.setSheared(false);
                remaining--;
                if (remaining <= 0)
                    break;
            }
        }
        StackerUtils.reconstructStackedEntities(stackedEntity, sheepList);
    });
}
Also used : StackedEntityDataEntry(dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry) TransformReason(org.bukkit.event.entity.EntityTransformEvent.TransformReason) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) AttributeInstance(org.bukkit.attribute.AttributeInstance) Slime(org.bukkit.entity.Slime) RoseStacker(dev.rosewood.rosestacker.RoseStacker) Statistic(org.bukkit.Statistic) Animals(org.bukkit.entity.Animals) Projectile(org.bukkit.entity.Projectile) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) Player(org.bukkit.entity.Player) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) ItemUtils(dev.rosewood.rosestacker.utils.ItemUtils) EventHandler(org.bukkit.event.EventHandler) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Enderman(org.bukkit.entity.Enderman) Sheep(org.bukkit.entity.Sheep) PigZapEvent(org.bukkit.event.entity.PigZapEvent) PersistentDataUtils(dev.rosewood.rosestacker.utils.PersistentDataUtils) ItemStackSettings(dev.rosewood.rosestacker.stack.settings.ItemStackSettings) Material(org.bukkit.Material) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Bukkit(org.bukkit.Bukkit) Setting(dev.rosewood.rosestacker.manager.ConfigurationManager.Setting) NPC(org.bukkit.entity.NPC) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) Blaze(org.bukkit.entity.Blaze) EntityEvent(org.bukkit.event.entity.EntityEvent) PlayerShearEntityEvent(org.bukkit.event.player.PlayerShearEntityEvent) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) EntityCacheManager(dev.rosewood.rosestacker.manager.EntityCacheManager) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) ChickenStackSettings(dev.rosewood.rosestacker.stack.settings.entity.ChickenStackSettings) ItemStack(org.bukkit.inventory.ItemStack) StackManager(dev.rosewood.rosestacker.manager.StackManager) List(java.util.List) Guardian(org.bukkit.entity.Guardian) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) StackerUtils(dev.rosewood.rosestacker.utils.StackerUtils) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Item(org.bukkit.entity.Item) Variant(org.bukkit.entity.MushroomCow.Variant) Wither(org.bukkit.entity.Wither) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) SpawnerSpawnEvent(org.bukkit.event.entity.SpawnerSpawnEvent) ArrayList(java.util.ArrayList) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) EntityTransformEvent(org.bukkit.event.entity.EntityTransformEvent) GameMode(org.bukkit.GameMode) GuiUtil(dev.rosewood.guiframework.framework.util.GuiUtil) AsyncEntityDeathEvent(dev.rosewood.rosestacker.event.AsyncEntityDeathEvent) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) SheepRegrowWoolEvent(org.bukkit.event.entity.SheepRegrowWoolEvent) MushroomCow(org.bukkit.entity.MushroomCow) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Listener(org.bukkit.event.Listener) Attribute(org.bukkit.attribute.Attribute) EntityCombustEvent(org.bukkit.event.entity.EntityCombustEvent) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) MushroomCowStackSettings(dev.rosewood.rosestacker.stack.settings.entity.MushroomCowStackSettings) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Bat(org.bukkit.entity.Bat) Vector(org.bukkit.util.Vector) Chicken(org.bukkit.entity.Chicken) EventPriority(org.bukkit.event.EventPriority) EntityCombustByBlockEvent(org.bukkit.event.entity.EntityCombustByBlockEvent) EntityDropItemEvent(org.bukkit.event.entity.EntityDropItemEvent) Golem(org.bukkit.entity.Golem) NMSAdapter(dev.rosewood.rosestacker.nms.NMSAdapter) Collections(java.util.Collections) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) Sheep(org.bukkit.entity.Sheep) EventHandler(org.bukkit.event.EventHandler)

Example 3 with SheepRegrowWoolEvent

use of org.bukkit.event.entity.SheepRegrowWoolEvent in project Arclight by IzzelAliz.

the class SheepEntityMixin method arclight$regrow.

@Inject(method = "eatGrassBonus", cancellable = true, at = @At("HEAD"))
private void arclight$regrow(CallbackInfo ci) {
    SheepRegrowWoolEvent event = new SheepRegrowWoolEvent((Sheep) this.getBukkitEntity());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        ci.cancel();
    }
}
Also used : SheepRegrowWoolEvent(org.bukkit.event.entity.SheepRegrowWoolEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SheepRegrowWoolEvent (org.bukkit.event.entity.SheepRegrowWoolEvent)3 GuiUtil (dev.rosewood.guiframework.framework.util.GuiUtil)1 RosePlugin (dev.rosewood.rosegarden.RosePlugin)1 RoseStacker (dev.rosewood.rosestacker.RoseStacker)1 AsyncEntityDeathEvent (dev.rosewood.rosestacker.event.AsyncEntityDeathEvent)1 Setting (dev.rosewood.rosestacker.manager.ConfigurationManager.Setting)1 EntityCacheManager (dev.rosewood.rosestacker.manager.EntityCacheManager)1 StackManager (dev.rosewood.rosestacker.manager.StackManager)1 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)1 NMSAdapter (dev.rosewood.rosestacker.nms.NMSAdapter)1 NMSHandler (dev.rosewood.rosestacker.nms.NMSHandler)1 StackedEntityDataEntry (dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry)1 StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)1 StackedItem (dev.rosewood.rosestacker.stack.StackedItem)1 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)1 ItemStackSettings (dev.rosewood.rosestacker.stack.settings.ItemStackSettings)1 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)1 ChickenStackSettings (dev.rosewood.rosestacker.stack.settings.entity.ChickenStackSettings)1 MushroomCowStackSettings (dev.rosewood.rosestacker.stack.settings.entity.MushroomCowStackSettings)1 SheepStackSettings (dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings)1