Search in sources :

Example 6 with FurnaceUserModule

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

the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.

/**
 * Check Fuel levels in the furnace
 */
private IAIState checkFurnaceFuel() {
    final World world = getOwnBuilding().getColony().getWorld();
    final List<ItemStack> possibleFuels = getActivePossibleFuels();
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
        return getState();
    }
    for (final BlockPos pos : module.getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
                    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
                        if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
                            needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
                            // This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
                            walkTo = null;
                            return GATHERING_REQUIRED_MATERIALS;
                        }
                        // We need to wait for Fuel to arrive
                        return getState();
                    }
                    fuelPos = pos;
                    if (preFuelState == null) {
                        preFuelState = getState();
                    }
                    return ADD_FUEL_TO_FURNACE;
                }
            }
        }
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 7 with FurnaceUserModule

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

the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.

/**
 * Check Fuel levels in the furnace
 */
private IAIState checkFurnaceFuel() {
    final World world = getOwnBuilding().getColony().getWorld();
    final List<ItemStack> possibleFuels = getActivePossibleFuels();
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
        return getState();
    }
    for (final BlockPos pos : module.getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
                    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
                        if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
                            needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
                            // This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
                            walkTo = null;
                            return GATHERING_REQUIRED_MATERIALS;
                        }
                        // We need to wait for Fuel to arrive
                        return getState();
                    }
                    fuelPos = pos;
                    if (preFuelState == null) {
                        preFuelState = getState();
                    }
                    return ADD_FUEL_TO_FURNACE;
                }
            }
        }
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 8 with FurnaceUserModule

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

the class AbstractEntityAIRequestSmelter method checkIfAbleToSmelt.

/**
 * Checks if the furnaces are ready to start smelting.
 *
 * @return START_USING_FURNACE if enough, else check for additional worker specific jobs.
 */
private IAIState checkIfAbleToSmelt() {
    // We're fully committed currently, try again later.
    final int burning = countOfBurningFurnaces();
    if (burning > 0 && (burning >= getMaxUsableFurnaces() || (job.getCraftCounter() + job.getProgress()) >= job.getMaxCraftingCount())) {
        setDelay(TICKS_SECOND);
        return getState();
    }
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    for (final BlockPos pos : module.getFurnaces()) {
        final TileEntity entity = world.getBlockEntity(pos);
        if (entity instanceof FurnaceTileEntity) {
            if (isEmpty(((FurnaceTileEntity) entity).getItem(SMELTABLE_SLOT))) {
                walkTo = pos;
                return START_USING_FURNACE;
            }
        } else {
            if (!(world.getBlockState(pos).getBlock() instanceof FurnaceBlock)) {
                module.removeFromFurnaces(pos);
            }
        }
    }
    if (burning > 0) {
        setDelay(TICKS_SECOND);
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) FurnaceBlock(net.minecraft.block.FurnaceBlock) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 9 with FurnaceUserModule

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

the class AbstractEntityAIRequestSmelter method craft.

@Override
protected IAIState craft() {
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    final List<ItemStack> possibleFuels = getAllowedFuel();
    if (possibleFuels.isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
        }
        return getState();
    }
    if (currentRecipeStorage != null) {
        possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
        // There is always only one input.
        possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getCleanedInput().get(0).getItemStack()));
    }
    if (walkToBuilding()) {
        setDelay(STANDARD_DELAY);
        return getState();
    }
    if (currentRecipeStorage != null && currentRequest == null) {
        currentRequest = job.getCurrentTask();
    }
    if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() != Blocks.FURNACE) {
        return super.craft();
    }
    if (module.getFurnaces().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
        }
        setDelay(STANDARD_DELAY);
        return START_WORKING;
    }
    final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
    if (furnacePosWithUsedFuel != null) {
        walkTo = furnacePosWithUsedFuel;
        worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
        return RETRIEVING_USED_FUEL_FROM_FURNACE;
    }
    final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
    if (posOfOven != null) {
        walkTo = posOfOven;
        worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
        return RETRIEVING_END_PRODUCT_FROM_FURNACE;
    }
    // Safety net, should get caught removing things from the furnace.
    if (currentRequest != null && job.getMaxCraftingCount() > 0 && job.getCraftCounter() >= job.getMaxCraftingCount()) {
        job.finishRequest(true);
        currentRecipeStorage = null;
        currentRequest = null;
        resetValues();
        return INVENTORY_FULL;
    }
    if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
        incrementActionsDone(getActionRewardForCraftingSuccess());
        currentRecipeStorage = null;
        currentRequest = null;
        resetValues();
        return START_WORKING;
    }
    return checkIfAbleToSmelt();
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 10 with FurnaceUserModule

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

the class AbstractEntityAIRequestSmelter method checkIfAbleToSmelt.

/**
 * Checks if the furnaces are ready to start smelting.
 *
 * @return START_USING_FURNACE if enough, else check for additional worker specific jobs.
 */
private IAIState checkIfAbleToSmelt() {
    // We're fully committed currently, try again later.
    final int burning = countOfBurningFurnaces();
    if (burning > 0 && (burning >= getMaxUsableFurnaces() || (job.getCraftCounter() + job.getProgress()) >= job.getMaxCraftingCount())) {
        setDelay(TICKS_SECOND);
        return getState();
    }
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    for (final BlockPos pos : module.getFurnaces()) {
        final TileEntity entity = world.getBlockEntity(pos);
        if (entity instanceof FurnaceTileEntity) {
            if (isEmpty(((FurnaceTileEntity) entity).getItem(SMELTABLE_SLOT))) {
                walkTo = pos;
                return START_USING_FURNACE;
            }
        } else {
            if (!(world.getBlockState(pos).getBlock() instanceof FurnaceBlock)) {
                module.removeFromFurnaces(pos);
            }
        }
    }
    if (burning > 0) {
        setDelay(TICKS_SECOND);
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) FurnaceBlock(net.minecraft.block.FurnaceBlock) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Aggregations

FurnaceUserModule (com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)12 BlockPos (net.minecraft.util.math.BlockPos)12 FurnaceTileEntity (net.minecraft.tileentity.FurnaceTileEntity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)6 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)6 ItemStack (net.minecraft.item.ItemStack)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 Tuple (com.minecolonies.api.util.Tuple)4 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)4 FurnaceBlock (net.minecraft.block.FurnaceBlock)4 World (net.minecraft.world.World)4 ImmutableList (com.google.common.collect.ImmutableList)2 TypeToken (com.google.common.reflect.TypeToken)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)2 PublicCrafting (com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting)2