Search in sources :

Example 26 with FurnaceTileEntity

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

the class AbstractEntityAIRequestSmelter method retrieveUsedFuel.

/**
 * Retrieve used fuel from the furnaces. If no position has been set return. Else navigate to the position of the furnace. On arrival execute the extract method of the
 * specialized worker.
 *
 * @return the next state to go to.
 */
private IAIState retrieveUsedFuel() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
    if (walkTo == null) {
        return START_WORKING;
    }
    if (walkToBlock(walkTo)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(walkTo);
    if (!(entity instanceof FurnaceTileEntity) || (ItemStackUtils.isEmpty(((FurnaceTileEntity) entity).getItem(FUEL_SLOT)))) {
        walkTo = null;
        return START_WORKING;
    }
    walkTo = null;
    extractFromFurnaceSlot((FurnaceTileEntity) entity, FUEL_SLOT);
    return START_WORKING;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity)

Example 27 with FurnaceTileEntity

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

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 28 with FurnaceTileEntity

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

the class AbstractEntityAIRequestSmelter method getRecipe.

@Override
protected IAIState getRecipe() {
    final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
    if (currentTask == null) {
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        return START_WORKING;
    }
    job.setMaxCraftingCount(currentTask.getRequest().getCount());
    final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
    if (furnacePosWithUsedFuel != null) {
        currentRequest = currentTask;
        walkTo = furnacePosWithUsedFuel;
        return RETRIEVING_USED_FUEL_FROM_FURNACE;
    }
    final BlockPos furnacePos = getPositionOfOvenToRetrieveFrom();
    if (furnacePos != null) {
        currentRequest = currentTask;
        walkTo = furnacePos;
        return RETRIEVING_END_PRODUCT_FROM_FURNACE;
    }
    if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (furnace.isLit() || !isEmpty(furnace.getItem(RESULT_SLOT)) || !isEmpty(furnace.getItem(SMELTABLE_SLOT))) {
                    if (furnace.isLit()) {
                        setDelay(TICKS_20);
                    }
                    return CRAFT;
                }
            }
        }
    }
    final IAIState newState = super.getRecipe();
    final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
    // This should only happen in the stonesmelter, but it could potentially happen with multiple fuels.
    if (newState == QUERY_ITEMS && currentRecipeStorage != null && module.isItemInList(new ItemStorage(currentRecipeStorage.getPrimaryOutput()))) {
        job.setCraftCounter(0);
    }
    return newState;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 29 with FurnaceTileEntity

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

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 30 with FurnaceTileEntity

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

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