Search in sources :

Example 16 with ItemFood

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

the class EntityShade 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, (ItemStack) 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 17 with ItemFood

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

the class EntitySmallEarthGolem 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, (ItemStack) 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 18 with ItemFood

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

the class EntityBoulderFist 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 19 with ItemFood

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

the class EntityFallenAngel 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 20 with ItemFood

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

the class RitualEffectFullStomach method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (world.getWorldTime() % 20 != 0) {
        return;
    }
    double horizRange = 16;
    double vertRange = 16;
    List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, horizRange, vertRange);
    if (playerList == null) {
        return;
    }
    if (currentEssence < this.getCostPerRefresh() * playerList.size()) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        TileEntity tile = world.getTileEntity(x, y + 1, z);
        IInventory inventory = null;
        if (tile instanceof IInventory) {
            inventory = (IInventory) tile;
        } else {
            tile = world.getTileEntity(x, y - 1, z);
            if (tile instanceof IInventory) {
                inventory = (IInventory) tile;
            }
        }
        int count = 0;
        if (inventory != null) {
            for (EntityPlayer player : playerList) {
                FoodStats foodStats = player.getFoodStats();
                float satLevel = foodStats.getSaturationLevel();
                for (int i = 0; i < inventory.getSizeInventory(); i++) {
                    ItemStack stack = inventory.getStackInSlot(i);
                    if (stack != null && stack.getItem() instanceof ItemFood) {
                        ItemFood foodItem = (ItemFood) stack.getItem();
                        int regularHeal = foodItem.func_150905_g(stack);
                        float saturatedHeal = foodItem.func_150906_h(stack) * regularHeal * 2.0f;
                        if (saturatedHeal + satLevel <= 20) {
                            NBTTagCompound nbt = new NBTTagCompound();
                            foodStats.writeNBT(nbt);
                            nbt.setFloat("foodSaturationLevel", saturatedHeal + satLevel);
                            foodStats.readNBT(nbt);
                            inventory.decrStackSize(i, 1);
                            count++;
                            break;
                        }
                    }
                }
            }
        }
        SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * count);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) ItemFood(net.minecraft.item.ItemFood) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats) 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