Search in sources :

Example 1 with FarmerFieldModule

use of com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule in project minecolonies by Minecolonies.

the class BuildingFarmer method getRequiredItemsAndAmount.

/**
 * Override this method if you want to keep an amount of items in inventory. When the inventory is full, everything get's dumped into the building chest. But you can use this
 * method to hold some stacks back.
 *
 * @return a list of objects which should be kept.
 */
@Override
public Map<Predicate<ItemStack>, Tuple<Integer, Boolean>> getRequiredItemsAndAmount() {
    final Map<Predicate<ItemStack>, Tuple<Integer, Boolean>> toKeep = new HashMap<>(super.getRequiredItemsAndAmount());
    for (FarmerFieldModule module : getModules(FarmerFieldModule.class)) {
        for (final BlockPos field : module.getFarmerFields()) {
            final TileEntity scareCrow = getColony().getWorld().getBlockEntity(field);
            if (scareCrow instanceof ScarecrowTileEntity && !ItemStackUtils.isEmpty(((ScarecrowTileEntity) scareCrow).getSeed())) {
                final ItemStack seedStack = ((ScarecrowTileEntity) scareCrow).getSeed();
                toKeep.put(seedStack::sameItem, new Tuple<>(64, true));
            }
        }
    }
    return toKeep;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) ItemStack(net.minecraft.item.ItemStack) Tuple(net.minecraft.util.Tuple) OptionalPredicate(com.minecolonies.api.util.OptionalPredicate) Predicate(java.util.function.Predicate)

Example 2 with FarmerFieldModule

use of com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method searchAndAddFields.

/**
 * Searches and adds a field that has not been taken yet for the farmer and then adds it to the list.
 */
private void searchAndAddFields() {
    final IColony colony = worker.getCitizenColonyHandler().getColony();
    if (colony != null) {
        @Nullable final AbstractScarecrowTileEntity newField = colony.getBuildingManager().getFreeField(worker.getCitizenData().getId(), world);
        if (newField != null) {
            newField.setOwner(worker.getCitizenData().getId());
            newField.setTaken(true);
            newField.setChanged();
            final FarmerFieldModule module = getOwnBuilding().getFirstModuleOccurance(FarmerFieldModule.class);
            module.addFarmerFields(newField.getPosition());
        }
    }
}
Also used : AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) IColony(com.minecolonies.api.colony.IColony) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with FarmerFieldModule

use of com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule in project minecolonies by ldtteam.

the class BuildingFarmer method getRequiredItemsAndAmount.

/**
 * Override this method if you want to keep an amount of items in inventory. When the inventory is full, everything get's dumped into the building chest. But you can use this
 * method to hold some stacks back.
 *
 * @return a list of objects which should be kept.
 */
@Override
public Map<Predicate<ItemStack>, Tuple<Integer, Boolean>> getRequiredItemsAndAmount() {
    final Map<Predicate<ItemStack>, Tuple<Integer, Boolean>> toKeep = new HashMap<>(super.getRequiredItemsAndAmount());
    for (FarmerFieldModule module : getModules(FarmerFieldModule.class)) {
        for (final BlockPos field : module.getFarmerFields()) {
            final TileEntity scareCrow = getColony().getWorld().getBlockEntity(field);
            if (scareCrow instanceof ScarecrowTileEntity && !ItemStackUtils.isEmpty(((ScarecrowTileEntity) scareCrow).getSeed())) {
                final ItemStack seedStack = ((ScarecrowTileEntity) scareCrow).getSeed();
                toKeep.put(seedStack::sameItem, new Tuple<>(64, true));
            }
        }
    }
    return toKeep;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) ItemStack(net.minecraft.item.ItemStack) Tuple(net.minecraft.util.Tuple) OptionalPredicate(com.minecolonies.api.util.OptionalPredicate) Predicate(java.util.function.Predicate)

Example 4 with FarmerFieldModule

use of com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule in project minecolonies by ldtteam.

the class EntityAIWorkFarmer method canGoPlanting.

/**
 * Checks if the farmer is ready to plant.
 *
 * @param currentField   the field to plant.
 * @param buildingFarmer the farmer building.
 * @return true if he is ready.
 */
private IAIState canGoPlanting(@NotNull final ScarecrowTileEntity currentField, @NotNull final BuildingFarmer buildingFarmer) {
    if (currentField.getSeed() == null || currentField.getSeed().isEmpty()) {
        worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(NO_SEED_SET, currentField.getBlockPos()), ChatPriority.BLOCKING, new TranslationTextComponent(NO_SEED_SET), currentField.getBlockPos()));
        final FarmerFieldModule module = buildingFarmer.getFirstModuleOccurance(FarmerFieldModule.class);
        module.setCurrentField(null);
        worker.getCitizenData().setIdleAtJob(true);
        return PREPARING;
    }
    worker.getCitizenData().setIdleAtJob(false);
    final ItemStack seeds = currentField.getSeed().copy();
    final int slot = worker.getCitizenInventoryHandler().findFirstSlotInInventoryWith(seeds.getItem());
    if (slot != -1) {
        return FARMER_PLANT;
    }
    if (walkToBuilding()) {
        return PREPARING;
    }
    seeds.setCount(seeds.getMaxStackSize());
    checkIfRequestForItemExistOrCreateAsynch(seeds, seeds.getMaxStackSize(), 1);
    currentField.nextState();
    return PREPARING;
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ItemStack(net.minecraft.item.ItemStack)

Example 5 with FarmerFieldModule

use of com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule in project minecolonies by ldtteam.

the class EntityAIWorkFarmer method searchAndAddFields.

/**
 * Searches and adds a field that has not been taken yet for the farmer and then adds it to the list.
 */
private void searchAndAddFields() {
    final IColony colony = worker.getCitizenColonyHandler().getColony();
    if (colony != null) {
        @Nullable final AbstractScarecrowTileEntity newField = colony.getBuildingManager().getFreeField(worker.getCitizenData().getId(), world);
        if (newField != null) {
            newField.setOwner(worker.getCitizenData().getId());
            newField.setTaken(true);
            newField.setChanged();
            final FarmerFieldModule module = getOwnBuilding().getFirstModuleOccurance(FarmerFieldModule.class);
            module.addFarmerFields(newField.getPosition());
        }
    }
}
Also used : AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) IColony(com.minecolonies.api.colony.IColony) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FarmerFieldModule (com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule)10 AbstractScarecrowTileEntity (com.minecolonies.api.tileentities.AbstractScarecrowTileEntity)6 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)6 BlockPos (net.minecraft.util.math.BlockPos)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 Nullable (org.jetbrains.annotations.Nullable)6 IColony (com.minecolonies.api.colony.IColony)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 BuildingFarmer (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer)4 PosBasedInteraction (com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction)4 TypeToken (com.google.common.reflect.TypeToken)2 AdvancementTriggers (com.minecolonies.api.advancements.AdvancementTriggers)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)2 Compatibility (com.minecolonies.api.compatibility.Compatibility)2 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)2 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2