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