Search in sources :

Example 31 with ItemFood

use of net.minecraft.item.ItemFood in project BloodMagic by WayofTime.

the class EntityBileDemon method interact.

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
@Override
public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
    if (this.isTamed()) {
        if (itemstack != null) {
            if (itemstack.getItem() instanceof ItemFood) {
                ItemFood itemfood = (ItemFood) itemstack.getItem();
                if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < maxTamedHealth) {
                    if (!par1EntityPlayer.capabilities.isCreativeMode) {
                        --itemstack.stackSize;
                    }
                    this.heal((float) itemfood.func_150905_g(itemstack));
                    if (itemstack.stackSize <= 0) {
                        par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
                    }
                    return true;
                }
            }
        }
        if (this.getOwner() instanceof EntityPlayer && SpellHelper.getUsername(par1EntityPlayer).equalsIgnoreCase(SpellHelper.getUsername((EntityPlayer) this.getOwner())) && !this.isBreedingItem(itemstack)) {
            if (!this.worldObj.isRemote) {
                this.aiSit.setSitting(!this.isSitting());
                this.isJumping = false;
                this.setPathToEntity(null);
                this.setTarget(null);
                this.setAttackTarget(null);
            }
            this.sendSittingMessageToPlayer(par1EntityPlayer, !this.isSitting());
        }
    } else if (itemstack != null && itemstack.getItem().equals(ModItems.weakBloodOrb) && !this.isAngry()) {
        if (!par1EntityPlayer.capabilities.isCreativeMode) {
            --itemstack.stackSize;
        }
        if (itemstack.stackSize <= 0) {
            par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
        }
        if (!this.worldObj.isRemote) {
            if (this.rand.nextInt(1) == 0) {
                this.setTamed(true);
                this.setPathToEntity(null);
                this.setAttackTarget(null);
                this.aiSit.setSitting(true);
                this.setHealth(maxTamedHealth);
                this.func_152115_b(par1EntityPlayer.getUniqueID().toString());
                this.playTameEffect(true);
                this.worldObj.setEntityState(this, (byte) 7);
            } else {
                this.playTameEffect(false);
                this.worldObj.setEntityState(this, (byte) 6);
            }
        }
        return true;
    }
    return super.interact(par1EntityPlayer);
}
Also used : ItemFood(net.minecraft.item.ItemFood) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 32 with ItemFood

use of net.minecraft.item.ItemFood in project BloodMagic by WayofTime.

the class EntityLowerGuardian method interact.

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
@Override
public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
    if (this.isTamed()) {
        if (itemstack != null) {
            if (itemstack.getItem() instanceof ItemFood) {
                ItemFood itemfood = (ItemFood) itemstack.getItem();
                if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < maxTamedHealth) {
                    if (!par1EntityPlayer.capabilities.isCreativeMode) {
                        --itemstack.stackSize;
                    }
                    this.heal((float) itemfood.func_150905_g(itemstack));
                    if (itemstack.stackSize <= 0) {
                        par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
                    }
                    return true;
                }
            }
        }
        if (this.getOwner() instanceof EntityPlayer && SpellHelper.getUsername(par1EntityPlayer).equalsIgnoreCase(SpellHelper.getUsername((EntityPlayer) this.getOwner())) && !this.isBreedingItem(itemstack)) {
            if (!this.worldObj.isRemote) {
                this.aiSit.setSitting(!this.isSitting());
                this.isJumping = false;
                this.setPathToEntity(null);
                this.setTarget(null);
                this.setAttackTarget(null);
            }
            this.sendSittingMessageToPlayer(par1EntityPlayer, !this.isSitting());
        }
    } else if (itemstack != null && itemstack.getItem().equals(ModItems.weakBloodOrb) && !this.isAngry()) {
        if (!par1EntityPlayer.capabilities.isCreativeMode) {
            --itemstack.stackSize;
        }
        if (itemstack.stackSize <= 0) {
            par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
        }
        if (!this.worldObj.isRemote) {
            if (this.rand.nextInt(1) == 0) {
                this.setTamed(true);
                this.setPathToEntity(null);
                this.setAttackTarget(null);
                this.aiSit.setSitting(true);
                this.setHealth(maxTamedHealth);
                this.func_152115_b(par1EntityPlayer.getUniqueID().toString());
                this.playTameEffect(true);
                this.worldObj.setEntityState(this, (byte) 7);
            } else {
                this.playTameEffect(false);
                this.worldObj.setEntityState(this, (byte) 6);
            }
        }
        return true;
    }
    return super.interact(par1EntityPlayer);
}
Also used : ItemFood(net.minecraft.item.ItemFood) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 33 with ItemFood

use of net.minecraft.item.ItemFood in project BloodMagic by WayofTime.

the class EntityWingedFireDemon method interact.

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
@Override
public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
    if (this.isTamed()) {
        if (itemstack != null) {
            if (itemstack.getItem() instanceof ItemFood) {
                ItemFood itemfood = (ItemFood) itemstack.getItem();
                if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < maxTamedHealth) {
                    if (!par1EntityPlayer.capabilities.isCreativeMode) {
                        --itemstack.stackSize;
                    }
                    this.heal((float) itemfood.func_150905_g(itemstack));
                    if (itemstack.stackSize <= 0) {
                        par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
                    }
                    return true;
                }
            }
        }
        if (this.getOwner() instanceof EntityPlayer && SpellHelper.getUsername(par1EntityPlayer).equalsIgnoreCase(SpellHelper.getUsername((EntityPlayer) this.getOwner())) && !this.isBreedingItem(itemstack)) {
            if (!this.worldObj.isRemote) {
                this.aiSit.setSitting(!this.isSitting());
                this.isJumping = false;
                this.setPathToEntity(null);
                this.setTarget(null);
                this.setAttackTarget(null);
            }
            this.sendSittingMessageToPlayer(par1EntityPlayer, !this.isSitting());
        }
    } else if (itemstack != null && itemstack.getItem().equals(ModItems.weakBloodOrb) && !this.isAngry()) {
        if (!par1EntityPlayer.capabilities.isCreativeMode) {
            --itemstack.stackSize;
        }
        if (itemstack.stackSize <= 0) {
            par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
        }
        if (!this.worldObj.isRemote) {
            if (this.rand.nextInt(1) == 0) {
                this.setTamed(true);
                this.setPathToEntity(null);
                this.setAttackTarget(null);
                this.aiSit.setSitting(true);
                this.setHealth(maxTamedHealth);
                this.func_152115_b(par1EntityPlayer.getUniqueID().toString());
                this.playTameEffect(true);
                this.worldObj.setEntityState(this, (byte) 7);
            } else {
                this.playTameEffect(false);
                this.worldObj.setEntityState(this, (byte) 6);
            }
        }
        return true;
    }
    return super.interact(par1EntityPlayer);
}
Also used : ItemFood(net.minecraft.item.ItemFood) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemFood (net.minecraft.item.ItemFood)33 ItemStack (net.minecraft.item.ItemStack)26 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 Item (net.minecraft.item.Item)7 TileEntity (net.minecraft.tileentity.TileEntity)4 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)4 BlockPos (net.minecraft.util.math.BlockPos)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)2 ItemBlock (net.minecraft.item.ItemBlock)2 ItemSoup (net.minecraft.item.ItemSoup)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 ItemAmbrosia (biomesoplenty.common.item.ItemAmbrosia)1 ItemBOPBoat (biomesoplenty.common.item.ItemBOPBoat)1 ItemBOPFood (biomesoplenty.common.item.ItemBOPFood)1 ItemBOPRecord (biomesoplenty.common.item.ItemBOPRecord)1 ItemBiomeEssence (biomesoplenty.common.item.ItemBiomeEssence)1 ItemBiomeFinder (biomesoplenty.common.item.ItemBiomeFinder)1 ItemFlowerBasket (biomesoplenty.common.item.ItemFlowerBasket)1