Search in sources :

Example 21 with InvWrapper

use of net.minecraftforge.items.wrapper.InvWrapper in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method plantCrop.

/**
     * Plants the crop at a given location.
     *
     * @param item     the crop.
     * @param position the location.
     */
private boolean plantCrop(final ItemStack item, @NotNull final BlockPos position) {
    final int slot = worker.findFirstSlotInInventoryWith(item.getItem(), item.getItemDamage());
    if (slot == -1) {
        return false;
    } else {
        @NotNull final IPlantable seed = (IPlantable) item.getItem();
        world.setBlockState(position.up(), seed.getPlant(world, position));
        new InvWrapper(getInventory()).extractItem(slot, 1, false);
        requestSeeds = false;
        //Flag 1+2 is needed for updates
        return true;
    }
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IPlantable(net.minecraftforge.common.IPlantable) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with InvWrapper

use of net.minecraftforge.items.wrapper.InvWrapper in project minecolonies by Minecolonies.

the class EntityAIWorkDeliveryman method deliver.

/**
     * Deliver the items to the hut.
     *
     * @return the next state.
     */
private AIState deliver() {
    final BuildingDeliveryman deliveryHut = (getOwnBuilding() instanceof BuildingDeliveryman) ? (BuildingDeliveryman) getOwnBuilding() : null;
    final AbstractBuilding buildingToDeliver = deliveryHut == null ? null : deliveryHut.getBuildingToDeliver();
    if (deliveryHut == null || buildingToDeliver == null) {
        return START_WORKING;
    }
    if (!worker.isWorkerAtSiteWithMove(buildingToDeliver.getLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
        return DELIVERY;
    }
    final InvWrapper workerInventory = new InvWrapper(worker.getInventoryCitizen());
    for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
        final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
        if (InventoryUtils.isItemStackEmpty(stack)) {
            continue;
        }
        final ItemStack insertionResultStack = buildingToDeliver.forceTransferStack(stack, world);
        if (!InventoryUtils.isItemStackEmpty(insertionResultStack)) {
            if (ItemStack.areItemStacksEqual(insertionResultStack, stack)) {
                //same stack, we could not deliver ?
                if (buildingToDeliver instanceof AbstractBuildingWorker) {
                    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, ((AbstractBuildingWorker) buildingToDeliver).getWorker().getName());
                } else {
                    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(" :" + buildingToDeliver.getSchematicName()));
                }
            }
            //Insert the result back into the inventory so we do not loose it.
            workerInventory.insertItem(i, insertionResultStack, false);
        }
    }
    worker.addExperience(1.0D);
    worker.setHeldItem(SLOT_HAND);
    buildingToDeliver.setOnGoingDelivery(false);
    deliveryHut.setBuildingToDeliver(null);
    if (buildingToDeliver instanceof BuildingHome) {
        ((BuildingHome) buildingToDeliver).setFoodNeeded(false);
    }
    gatherTarget = buildingToDeliver.getLocation();
    return GATHERING;
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)22 ItemStack (net.minecraft.item.ItemStack)15 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)4 TileEntity (net.minecraft.tileentity.TileEntity)4 TileEntityChest (net.minecraft.tileentity.TileEntityChest)4 BlockPos (net.minecraft.util.math.BlockPos)4 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)3 Block (net.minecraft.block.Block)3 ItemFood (net.minecraft.item.ItemFood)3 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 ItemStorage (com.minecolonies.coremod.entity.ai.item.handling.ItemStorage)2 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)2 ArrayList (java.util.ArrayList)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemArmor (net.minecraft.item.ItemArmor)2 com.minecolonies.api.util (com.minecolonies.api.util)1 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1