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);
}
}
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);
});
}
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();
}
}
Aggregations