Search in sources :

Example 21 with FurnaceTileEntity

use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.

the class AbstractEntityAIRequestSmelter method getPositionOfOvenToRetrieveFrom.

/**
 * Get the furnace which has finished smeltables. For this check each furnace which has been registered to the building. Check if the furnace is turned off and has something in
 * the result slot or check if the furnace has more than x results.
 *
 * @return the position of the furnace.
 */
private BlockPos getPositionOfOvenToRetrieveFrom() {
    for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
        final TileEntity entity = world.getBlockEntity(pos);
        if (entity instanceof FurnaceTileEntity) {
            final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
            int countInResultSlot = 0;
            boolean fullResult = false;
            if (!isEmpty(furnace.getItem(RESULT_SLOT))) {
                countInResultSlot = furnace.getItem(RESULT_SLOT).getCount();
                fullResult = countInResultSlot >= furnace.getItem(RESULT_SLOT).getMaxStackSize();
            }
            if (fullResult || (!furnace.isLit() && countInResultSlot > 0 && isEmpty(furnace.getItem(SMELTABLE_SLOT)))) {
                worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
                return pos;
            }
        }
    }
    return null;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 22 with FurnaceTileEntity

use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.

the class AbstractEntityAIRequestSmelter method addFuelToFurnace.

/**
 * Add furnace fuel when necessary
 * @return
 */
private IAIState addFuelToFurnace() {
    final List<ItemStack> possibleFuels = getActivePossibleFuels();
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
        if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
            needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
            return GATHERING_REQUIRED_MATERIALS;
        }
        // We shouldn't get here, unless something changed between the checkFurnaceFuel and the addFueltoFurnace calls
        preFuelState = null;
        fuelPos = null;
        return START_WORKING;
    }
    if (fuelPos == null || walkToBlock(fuelPos)) {
        return getState();
    }
    if (WorldUtil.isBlockLoaded(world, fuelPos)) {
        final TileEntity entity = world.getBlockEntity(fuelPos);
        if (entity instanceof FurnaceTileEntity) {
            final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
            // Stoke the furnaces
            if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
                InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
                if (preFuelState != null && preFuelState != ADD_FUEL_TO_FURNACE) {
                    IAIState returnState = preFuelState;
                    preFuelState = null;
                    fuelPos = null;
                    return returnState;
                }
            }
        }
    }
    // Fueling is confused, start over.
    preFuelState = null;
    fuelPos = null;
    return START_WORKING;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 23 with FurnaceTileEntity

use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.

the class AbstractEntityAIRequestSmelter method countOfBurningFurnaces.

/**
 * Check to see how many furnaces are still processing
 * @return the count.
 */
private int countOfBurningFurnaces() {
    int count = 0;
    final World world = getOwnBuilding().getColony().getWorld();
    for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (furnace.isLit()) {
                    count += 1;
                }
            }
        }
    }
    return count;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) World(net.minecraft.world.World) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 24 with FurnaceTileEntity

use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.

the class AbstractEntityAIRequestSmelter method getExtendedCount.

@Override
protected int getExtendedCount(final ItemStack stack) {
    if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        int count = 0;
        for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
            if (WorldUtil.isBlockLoaded(world, pos)) {
                final TileEntity entity = world.getBlockEntity(pos);
                if (entity instanceof FurnaceTileEntity) {
                    final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                    final ItemStack smeltableSlot = furnace.getItem(SMELTABLE_SLOT);
                    final ItemStack resultSlot = furnace.getItem(RESULT_SLOT);
                    if (ItemStackUtils.compareItemStacksIgnoreStackSize(stack, smeltableSlot)) {
                        count += smeltableSlot.getCount();
                    } else if (ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resultSlot)) {
                        count += resultSlot.getCount();
                    }
                }
            }
        }
        return count;
    }
    return 0;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 25 with FurnaceTileEntity

use of net.minecraft.tileentity.FurnaceTileEntity 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)

Aggregations

FurnaceTileEntity (net.minecraft.tileentity.FurnaceTileEntity)34 TileEntity (net.minecraft.tileentity.TileEntity)34 FurnaceUserModule (com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)26 BlockPos (net.minecraft.util.math.BlockPos)26 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)16 World (net.minecraft.world.World)14 ItemStack (net.minecraft.item.ItemStack)12 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)10 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)8 ItemStorage (com.minecolonies.api.crafting.ItemStorage)8 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)8 FurnaceBlock (net.minecraft.block.FurnaceBlock)8 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)8 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)6 AIEventTarget (com.minecolonies.api.entity.ai.statemachine.AIEventTarget)6 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)6 AIBlockingEventType (com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType)6 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)6 InventoryUtils (com.minecolonies.api.util.InventoryUtils)6 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)6