org.bukkit.entity.Ageable Java Examples

The following examples show how to use org.bukkit.entity.Ageable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DropTools.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
private Collection<ItemStack> generateLoot(LivingEntity dead, List<ItemStack> drops){
    if(sm.getHookManager().isHookRegistered(PluginCompat.CUSTOMDROPS)){
        CustomDropsHook cdh = (CustomDropsHook) sm.getHookManager().getHook(PluginCompat.CUSTOMDROPS);
        if(cdh.hasCustomDrops(dead)){
            return cdh.getDrops(dead);
        }
    }
    if(dead instanceof Ageable){
        if(!((Ageable) dead).isAdult()){
            return Collections.emptySet();
        }
    }

    // Default to true to keep the usual behaviour
    if (sm.getConfig().getBoolean("use-loot-table-for-drops", true)) {
        LootContext lootContext = new LootContext.Builder(dead.getLocation()).lootedEntity(dead).killer(dead.getKiller()).build();
        return ((Mob) dead).getLootTable().populateLoot(ThreadLocalRandom.current(), lootContext);
    } else
        return drops;
}
 
Example #2
Source File: AnimalGrowthAccelerator.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected void tick(Block b) {
    BlockMenu inv = BlockStorage.getInventory(b);

    for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 3.0, 3.0, 3.0, n -> n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult())) {
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
                if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
                    return;
                }

                ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
                inv.consumeItem(slot);
                ((Ageable) n).setAge(((Ageable) n).getAge() + 2000);

                if (((Ageable) n).getAge() > 0) {
                    ((Ageable) n).setAge(0);
                }

                n.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, ((LivingEntity) n).getEyeLocation(), 8, 0.2F, 0.2F, 0.2F);
                return;
            }
        }
    }
}
 
Example #3
Source File: DefaultHumanoidBoundingBox.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean intersectsHead(Location check, Entity base) {
	if (base instanceof Ageable && !((Ageable) base).isAdult() ){
		return BoundingBoxUtil.within2DHeight(base,check,(headTopHeight_baby-bodyheight_baby),bodyheight_baby);
	}
	return BoundingBoxUtil.within2DHeight(base,check,(headTopHeight-bodyheight), bodyheight);
}
 
Example #4
Source File: DefaultHumanoidBoundingBox.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean intersectsBody(Location check, Entity base) {
	if (base instanceof Ageable && !((Ageable) base).isAdult() ){
		return BoundingBoxUtil.within2DHeight(base,check,bodyheight_baby);
	}
	return BoundingBoxUtil.within2DHeight(base,check,headTopHeight);
}
 
Example #5
Source File: AgeableTrait.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkTrait(Entity original, Entity nearby) {
    if(original instanceof Ageable){
        return (((Ageable) original).isAdult() != ((Ageable) nearby).isAdult());
    }
    return false;
}
 
Example #6
Source File: EntityData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public final boolean isInstance(final @Nullable Entity e) {
	if (e == null)
		return false;
	if (!baby.isUnknown() && e instanceof Ageable && ((Ageable) e).isAdult() != baby.isFalse())
		return false;
	return getType().isInstance(e) && match((E) e);
}
 
Example #7
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityKilled(EntityDeathEvent e) {
    if (e.getEntity().getType() != EntityType.SHEEP || !plugin.getConfig().getBoolean("options.sheep.dropMutton", true) || !e.getEntity().getWorld().isGameRule("doMobLoot") || !(e.getEntity() instanceof Ageable)) {
        return;
    }
    Ageable entity = (Ageable) e.getEntity();
    if (!entity.isAdult()) {
        return;
    }
    boolean fireaspect = false;
    int looting = 1;
    if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent dEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
        if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Player) {
            ItemStack hand = ((Player) dEvent.getDamager()).getItemInHand();
            fireaspect = hand.containsEnchantment(Enchantment.FIRE_ASPECT);
            if (hand.containsEnchantment(Enchantment.LOOT_BONUS_MOBS))
                looting += hand.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
            if (looting < 1) //Incase a plugin sets an enchantment level to be negative
                looting = 1;
        } else if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Arrow) {
            Arrow a = (Arrow) dEvent.getDamager();
            if (a.getFireTicks() > 0)
                fireaspect = true;
        }
    }
    if (entity.getLastDamageCause().getCause() == DamageCause.FIRE_TICK || entity.getLastDamageCause().getCause() == DamageCause.FIRE
            || entity.getLastDamageCause().getCause() == DamageCause.LAVA || fireaspect)
        e.getDrops().add(new ItemStack(Carbon.injector().cookedMuttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
    else
        e.getDrops().add(new ItemStack(Carbon.injector().muttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
}
 
Example #8
Source File: AgeableTrait.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void applyTrait(Entity original, Entity spawned) {
    if(original instanceof Ageable){
        ((Ageable) spawned).setAge(((Ageable) original).getAge());
    }
}
 
Example #9
Source File: EntityAgeablePet.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Ageable getBukkitEntity() {
    return (Ageable) super.getBukkitEntity();
}