Search in sources :

Example 1 with ItemFood

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);
}
Also used : Utils(com.minecolonies.api.util.Utils) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Map(java.util.Map) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) Colony(com.minecolonies.coremod.colony.Colony) Collection(java.util.Collection) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) com.minecolonies.coremod.colony.buildings(com.minecolonies.coremod.colony.buildings) TextComponentString(net.minecraft.util.text.TextComponentString) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) InventoryUtils(com.minecolonies.api.util.InventoryUtils) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemFood

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemFood(net.minecraft.item.ItemFood) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemFood

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();
}
Also used : SaturationProperty(org.spongepowered.api.data.property.item.SaturationProperty) ItemFood(net.minecraft.item.ItemFood)

Example 4 with ItemFood

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();
}
Also used : Item(net.minecraft.item.Item) ItemFood(net.minecraft.item.ItemFood) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with ItemFood

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;
            }
        }
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ItemFood(net.minecraft.item.ItemFood) ItemScanTool(com.minecolonies.coremod.items.ItemScanTool) BlockContainer(net.minecraft.block.BlockContainer) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemFood (net.minecraft.item.ItemFood)23 ItemStack (net.minecraft.item.ItemStack)16 Item (net.minecraft.item.Item)7 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)4 TileEntity (net.minecraft.tileentity.TileEntity)3 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 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 ItemGem (biomesoplenty.common.item.ItemGem)1 ItemJarEmpty (biomesoplenty.common.item.ItemJarEmpty)1