use of net.minecraft.item.ItemFood in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method tryToGatherItems.
/**
* Gather item from chest.
* Gathers only one stack of the item.
*
* @param buildingToDeliver building to deliver to.
*/
private AIState tryToGatherItems(@NotNull final AbstractBuilding buildingToDeliver) {
final BlockPos position;
if (buildingToDeliver instanceof BuildingHome) {
position = wareHouse.getTileEntity().getPositionOfChestWithItemStack(itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood);
} else if (itemsToDeliver.isEmpty()) {
final String tool = buildingToDeliver.getRequiredTool();
position = wareHouse.getTileEntity().getPositionOfChestWithTool(tool, Utils.PICKAXE.equals(tool) ? buildingToDeliver.getNeededPickaxeLevel() : buildingToDeliver.getBuildingLevel(), buildingToDeliver);
} else {
final ItemStack stack = itemsToDeliver.get(0);
position = wareHouse.getTileEntity().getPositionOfChestWithItemStack(stack);
}
if (position == null) {
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
}
if (!worker.isWorkerAtSiteWithMove(position, MIN_DISTANCE_TO_CHEST)) {
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
return gatherItems(buildingToDeliver, position);
}
use of net.minecraft.item.ItemFood in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method gatherItems.
/**
* Gather item from chest.
* Gathers only one stack of the item.
*
* @param buildingToDeliver building to deliver to.
*/
private AIState gatherItems(@NotNull final AbstractBuilding buildingToDeliver, @NotNull final BlockPos position) {
final TileEntity tileEntity = world.getTileEntity(position);
if (tileEntity instanceof TileEntityChest) {
if (!(tileEntity instanceof TileEntityColonyBuilding)) {
if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 1);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 0);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
}
if (buildingToDeliver instanceof BuildingHome) {
final int extraFood = worker.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION ? 1 : 0;
//Tries to extract a certain amount of the item of the chest.
if (InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood, buildingToDeliver.getBuildingLevel() + extraFood, new InvWrapper(worker.getInventoryCitizen()))) {
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (itemsToDeliver.isEmpty() && !isToolInTileEntity((TileEntityChest) tileEntity, buildingToDeliver.getRequiredTool(), buildingToDeliver.getBuildingLevel())) {
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (!itemsToDeliver.isEmpty()) {
final ItemStack stack = itemsToDeliver.get(0);
if (isInTileEntity((TileEntityChest) tileEntity, stack)) {
itemsToDeliver.remove(0);
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
}
}
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
use of net.minecraft.item.ItemFood in project SpongeCommon by SpongePowered.
the class SaturationPropertyStore method getFor.
@Override
protected Optional<SaturationProperty> getFor(ItemStack itemStack) {
if (itemStack.getItem() instanceof ItemFood) {
final ItemFood food = (ItemFood) itemStack.getItem();
// Translate's Minecraft's weird internal value to the actual saturation value
final double saturationModifier = food.getSaturationModifier(itemStack) * food.getHealAmount(itemStack) * 2.0;
return Optional.of(new SaturationProperty(saturationModifier));
}
return Optional.empty();
}
use of net.minecraft.item.ItemFood in project Nutrition by WesCook.
the class EventEatFood method startUsingItem.
// Allow food to be consumed regardless of hunger level
@SubscribeEvent
public void startUsingItem(PlayerInteractEvent.RightClickItem event) {
// Only run on server
EntityPlayer player = (EntityPlayer) event.getEntity();
if (player.getEntityWorld().isRemote)
return;
// Interacting with item?
ItemStack itemStack = event.getItemStack();
if (itemStack == null)
return;
// Is item food?
Item item = itemStack.getItem();
if (!(item instanceof ItemFood))
return;
// If config allows, mark food as edible
if (Config.allowOverEating)
((ItemFood) item).setAlwaysEdible();
}
use of net.minecraft.item.ItemFood in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block.
* Deny if:
* - If the block is in colony
* - block is AbstractBlockHut
* - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (Configurations.gameplay.enableColonyProtection) {
if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && block != null && block != Blocks.AIR) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.RIGHTCLICK_BLOCK, event.getPos());
return;
}
if (block instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.RIGHTCLICK_ENTITY, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem() instanceof ItemFood) {
return;
}
if (stack.getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.THROW_POTION, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
return;
}
}
}
}
Aggregations