use of net.minecraft.item.ItemFood in project minecolonies by Minecolonies.
the class EntityAIGoHome method handleSaturation.
/**
* Handle the saturation of the citizen.
*
* @param pos the position.
*/
private void handleSaturation(@NotNull final BlockPos pos) {
if (citizen.isWorkerAtSiteWithMove(pos, 2) && citizen.getColony() != null && citizen.getCitizenData() != null && citizen.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION) {
final double currentSaturation = citizen.getCitizenData().getSaturation();
boolean tookFood = false;
final AbstractBuilding home = citizen.getColony().getBuilding(pos);
if (home instanceof BuildingHome && currentSaturation < EntityCitizen.FULL_SATURATION) {
final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(home.getTileEntity(), itemStack -> itemStack.getItem() instanceof ItemFood);
if (slot != -1) {
final ItemStack stack = home.getTileEntity().getStackInSlot(slot);
if (!InventoryUtils.isItemStackEmpty(stack)) {
final int slotToSet = InventoryUtils.getFirstOpenSlotFromItemHandler(new InvWrapper(citizen.getInventoryCitizen()));
if (slotToSet == -1) {
InventoryUtils.forceItemStackToItemHandler(new InvWrapper(citizen.getInventoryCitizen()), new ItemStack(stack.getItem(), 1), stack1 -> citizen.getWorkBuilding() == null || !citizen.getWorkBuilding().neededForWorker(stack1));
} else {
citizen.getInventoryCitizen().setInventorySlotContents(slotToSet, new ItemStack(stack.getItem(), 1));
}
tookFood = true;
stack.setCount(stack.getCount() - 1);
}
((BuildingHome) home).setFoodNeeded(false);
}
}
if (!tookFood) {
requestFoodIfRequired(currentSaturation, home);
}
}
}
use of net.minecraft.item.ItemFood in project minecolonies by Minecolonies.
the class EntityCitizen method tryToEat.
/**
* Lets the citizen tryToEat to replentish saturation.
*/
public void tryToEat() {
final int slot = InventoryUtils.findFirstSlotInProviderWith(this, itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood);
if (slot == -1) {
return;
}
final ItemStack stack = inventory.getStackInSlot(slot);
if (!InventoryUtils.isItemStackEmpty(stack) && stack.getItem() instanceof ItemFood && citizenData != null) {
final int heal = ((ItemFood) stack.getItem()).getHealAmount(stack);
citizenData.increaseSaturation(heal);
inventory.decrStackSize(slot, 1);
citizenData.markDirty();
}
}
use of net.minecraft.item.ItemFood in project ClaySoldiersMod by SanAndreasP.
the class SoldierUpgrades method getFoodItems.
private static ItemStack[] getFoodItems() {
List<ItemStack> stackList = new ArrayList<>();
Iterator iter = Item.itemRegistry.iterator();
for (Object elem = null; iter.hasNext(); elem = iter.next()) {
if (elem instanceof ItemFood && !UpgradeFood.isFoodExcluded((ItemFood) elem)) {
stackList.add(new ItemStack((ItemFood) elem, 1, OreDictionary.WILDCARD_VALUE));
}
}
return stackList.toArray(new ItemStack[stackList.size()]);
}
use of net.minecraft.item.ItemFood in project DynamicSurroundings by OreCruncher.
the class ItemRegistry method initComplete.
@Override
public void initComplete() {
// Iterate through the list of registered Items to see
// if we know about them, or can infer based on class
// matching.
final Iterator<Item> iterator = Item.REGISTRY.iterator();
while (iterator.hasNext()) {
final Item item = iterator.next();
if (!this.items.containsKey(item)) {
if (doesBelong(this.swordItems, item)) {
this.items.put(item, ItemType.SWORD);
} else if (doesBelong(this.axeItems, item)) {
this.items.put(item, ItemType.AXE);
} else if (doesBelong(this.toolItems, item)) {
this.items.put(item, ItemType.TOOL);
} else if (doesBelong(this.shieldItems, item)) {
this.items.put(item, ItemType.SHIELD);
} else if (doesBelong(this.bowItems, item)) {
this.items.put(item, ItemType.BOW);
} else if (doesBelong(this.crystalItems, item)) {
this.items.put(item, ItemType.ARMOR);
this.armorMap.put(item, ArmorClass.CRYSTAL);
} else if (doesBelong(this.heavyItems, item)) {
this.items.put(item, ItemType.ARMOR);
this.armorMap.put(item, ArmorClass.HEAVY);
} else if (doesBelong(this.mediumItems, item)) {
this.items.put(item, ItemType.ARMOR);
this.armorMap.put(item, ArmorClass.MEDIUM);
} else if (doesBelong(this.lightItems, item)) {
this.items.put(item, ItemType.ARMOR);
this.armorMap.put(item, ArmorClass.LIGHT);
} else if (item instanceof ItemFood) {
this.items.put(item, ItemType.FOOD);
}
}
// Process sounds for Items that we are concerned with
final ItemType t = this.items.get(item);
if (t != null) {
SoundEffect se = this.getSwingSound(item, t);
if (se != null)
this.swings.put(item, se);
se = this.getUseSound(item, t);
if (se != null)
this.uses.put(item, se);
se = this.getEquipSound(item, t);
if (se != null)
this.equips.put(item, se);
}
}
// Free up resources that are no longer needed
this.swordItems = null;
this.axeItems = null;
this.bowItems = null;
this.toolItems = null;
this.shieldItems = null;
this.crystalItems = null;
this.heavyItems = null;
this.mediumItems = null;
this.lightItems = null;
}
use of net.minecraft.item.ItemFood in project BloodMagic by WayofTime.
the class RitualFullStomach method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
BlockPos pos = masterRitualStone.getBlockPos();
int maxEffects = currentEssence / getRefreshCost();
int totalEffects = 0;
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
if (tile == null || !tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
return;
IItemHandler inventory = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int lastSlot = 0;
AreaDescriptor fillingRange = getBlockRange(FILL_RANGE);
List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, fillingRange.getAABB(pos));
for (EntityPlayer player : playerList) {
FoodStats foodStats = player.getFoodStats();
float satLevel = foodStats.getSaturationLevel();
for (int i = lastSlot; i < inventory.getSlots(); i++) {
ItemStack stack = inventory.extractItem(i, 1, true);
if (!stack.isEmpty() && stack.getItem() instanceof ItemFood) {
ItemFood foodItem = (ItemFood) stack.getItem();
int healAmount = foodItem.getHealAmount(stack);
float saturationAmount = foodItem.getSaturationModifier(stack) * healAmount * 2.0f;
// Pam please stop being weird. Fix your mod.
if (saturationAmount + satLevel <= 20 || satLevel < 5) {
foodStats.addStats(foodItem, stack);
inventory.extractItem(i, 1, false);
totalEffects++;
lastSlot = i;
break;
}
}
}
if (totalEffects >= maxEffects) {
masterRitualStone.getOwnerNetwork().causeNausea();
break;
}
}
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * totalEffects);
}
Aggregations