Search in sources :

Example 16 with FurnaceTileEntity

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

the class AbstractEntityAIUsesFurnace method accelerateFurnaces.

/**
 * Actually accelerate the furnaces
 */
private IAIState accelerateFurnaces() {
    final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getPrimarySkill()) / 10) * 2;
    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;
                for (int i = 0; i < accelerationTicks; i++) {
                    if (furnace.isLit()) {
                        furnace.tick();
                    }
                }
            }
        }
    }
    return null;
}
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 17 with FurnaceTileEntity

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

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)

Example 18 with FurnaceTileEntity

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

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

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

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

the class AbstractEntityAIRequestSmelter 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 || currentRequest == null) {
        return START_WORKING;
    }
    final TileEntity entity = world.getBlockEntity(walkTo);
    if (!(entity instanceof FurnaceTileEntity) || (isEmpty(((FurnaceTileEntity) entity).getItem(RESULT_SLOT)))) {
        walkTo = null;
        return START_WORKING;
    }
    if (walkToBlock(walkTo)) {
        return getState();
    }
    walkTo = null;
    final int preExtractCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRequest.getRequest().getStack(), stack));
    extractFromFurnaceSlot((FurnaceTileEntity) entity, RESULT_SLOT);
    // Do we have the requested item in the inventory now?
    final int resultCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRequest.getRequest().getStack(), stack)) - preExtractCount;
    if (resultCount > 0) {
        final ItemStack stack = currentRequest.getRequest().getStack().copy();
        stack.setCount(resultCount);
        currentRequest.addDelivery(stack);
        job.setCraftCounter(job.getCraftCounter() + resultCount);
        job.setProgress(job.getProgress() - resultCount);
        if (job.getMaxCraftingCount() == 0) {
            job.setMaxCraftingCount(currentRequest.getRequest().getCount());
        }
        if (job.getCraftCounter() >= job.getMaxCraftingCount() && job.getProgress() <= 0) {
            job.finishRequest(true);
            resetValues();
            currentRecipeStorage = null;
            incrementActionsDoneAndDecSaturation();
            return INVENTORY_FULL;
        }
    }
    setDelay(STANDARD_DELAY);
    return START_WORKING;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) TypeToken(com.google.common.reflect.TypeToken) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) 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) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) Hand(net.minecraft.util.Hand) 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) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) 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) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Blocks(net.minecraft.block.Blocks) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) 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) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStack(net.minecraft.item.ItemStack)

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