Search in sources :

Example 31 with FurnaceTileEntity

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

the class AbstractEntityAIRequestSmelter method isFuelNeeded.

/**
 * Quick check to see if there is a furnace that needs fuel
 */
private boolean isFuelNeeded() {
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    for (final BlockPos pos : module.getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (!(entity instanceof FurnaceTileEntity)) {
                module.removeFromFurnaces(pos);
                continue;
            }
            final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
            if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
                // We only want to return true if we're not already gathering materials.
                return getState() != GATHERING_REQUIRED_MATERIALS;
            }
        }
    }
    return false;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 32 with FurnaceTileEntity

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

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

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

the class AbstractEntityAIUsesFurnace method fillUpFurnace.

/**
 * Smelt the smeltable after the required items are in the inv.
 *
 * @return the next state to go to.
 */
private IAIState fillUpFurnace() {
    if (getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
        }
        return START_WORKING;
    }
    if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
        walkTo = null;
        return START_WORKING;
    }
    if (walkToBlock(walkTo)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(walkTo);
    if (entity instanceof FurnaceTileEntity) {
        final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
        if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), this::isSmeltable) && (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
            InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), this::isSmeltable, STACKSIZE, new InvWrapper(furnace), SMELTABLE_SLOT);
        }
        final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
        if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack))) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
            InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack)), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
        }
    }
    walkTo = null;
    return START_WORKING;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Blocks(net.minecraft.block.Blocks) List(java.util.List) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) FurnaceBlock(net.minecraft.block.FurnaceBlock) NotNull(org.jetbrains.annotations.NotNull) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 34 with FurnaceTileEntity

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

the class AbstractEntityAIUsesFurnace method retrieveSmeltableFromFurnace.

/**
 * Retrieve ready bars 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 retrieveSmeltableFromFurnace() {
    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(RESULT_SLOT)))) {
        walkTo = null;
        return START_WORKING;
    }
    walkTo = null;
    extractFromFurnace((FurnaceTileEntity) entity);
    incrementActionsDoneAndDecSaturation();
    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)

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