Search in sources :

Example 1 with BrewingStandTileEntity

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

the class EntityAIWorkAlchemist method retrieveUsedFuel.

/**
 * Retrieve used fuel from the brewingStand. If no position has been set return. Else navigate to the position of the brewingStand. 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 BrewingStandTileEntity) || (ItemStackUtils.isEmpty(((BrewingStandTileEntity) entity).getItem(BREWING_FUEL_SLOT)))) {
        walkTo = null;
        return START_WORKING;
    }
    walkTo = null;
    extractFromBrewingStandSlot((BrewingStandTileEntity) entity, BREWING_FUEL_SLOT);
    return START_WORKING;
}
Also used : BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity)

Example 2 with BrewingStandTileEntity

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

the class EntityAIWorkAlchemist method addFuelToBrewingStand.

/**
 * Add brewing stand fuel when necessary
 * @return
 */
private IAIState addFuelToBrewingStand() {
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BLAZE_POWDER)) {
        if (InventoryUtils.hasItemInProvider(building, Items.BLAZE_POWDER)) {
            needsCurrently = new Tuple<>(item -> item.getItem() == Items.BLAZE_POWDER, STACKSIZE);
            return GATHERING_REQUIRED_MATERIALS;
        }
        // We shouldn't get here, unless something changed between the checkBrewingStandFuel and the addFueltoBrewingStand 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 BrewingStandTileEntity) {
            final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
            // Stoke the brewing stands
            if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BLAZE_POWDER) && (hasBrewableAndNoFuel(brewingStand) || hasNeitherFuelNorBrewable(brewingStand))) {
                InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() == Items.BLAZE_POWDER, BREWING_MIN_FUEL_COUNT, new InvWrapper(brewingStand), BREWING_FUEL_SLOT);
                if (preFuelState != null && preFuelState != ADD_FUEL_TO_BREWINGSTAND) {
                    IAIState returnState = preFuelState;
                    preFuelState = null;
                    fuelPos = null;
                    return returnState;
                }
            }
        }
    }
    // Fueling is confused, start over.
    preFuelState = null;
    fuelPos = null;
    return START_WORKING;
}
Also used : 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) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AbstractAdvancedPathNavigate(com.minecolonies.api.entity.pathfinding.AbstractAdvancedPathNavigate) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) ModItems(com.minecolonies.api.items.ModItems) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) Network(com.minecolonies.coremod.Network) SoundCategory(net.minecraft.util.SoundCategory) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) Constants(com.minecolonies.api.util.constant.Constants) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ShearsItem(net.minecraft.item.ShearsItem) 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) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) JobAlchemist(com.minecolonies.coremod.colony.jobs.JobAlchemist) TileEntity(net.minecraft.tileentity.TileEntity) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BuildingAlchemist(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingAlchemist) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity)

Example 3 with BrewingStandTileEntity

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

the class EntityAIWorkAlchemist method getPositionOfBrewingStandToRetrieveFrom.

/**
 * Get the brewingStand which has finished smeltables. For this check each brewingStand which has been registered to the building. Check if the brewingStand is turned off and has something in
 * the result slot or check if the brewingStand has more than x results.
 *
 * @return the position of the brewingStand.
 */
private BlockPos getPositionOfBrewingStandToRetrieveFrom() {
    if (currentRecipeStorage == null || currentRecipeStorage.getIntermediate() != Blocks.BREWING_STAND) {
        return null;
    }
    for (final BlockPos pos : building.getAllBrewingStandPositions()) {
        final TileEntity entity = world.getBlockEntity(pos);
        if (entity instanceof BrewingStandTileEntity) {
            final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
            int countInResultSlot = 0;
            for (int slot = 0; slot < 3; slot++) {
                if (!isEmpty(brewingStand.getItem(slot)) && ItemStackUtils.compareItemStacksIgnoreStackSize(currentRecipeStorage.getPrimaryOutput(), brewingStand.getItem(slot))) {
                    countInResultSlot = brewingStand.getItem(slot).getCount();
                }
            }
            if (brewingStand.brewTime <= 0 && countInResultSlot > 0 && isEmpty(brewingStand.getItem(INGREDIENT_SLOT))) {
                worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
                return pos;
            }
        }
    }
    return null;
}
Also used : BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity)

Example 4 with BrewingStandTileEntity

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

the class EntityAIWorkAlchemist method fillUpBrewingStand.

/**
 * Brew the ingredient after the required items are in the inv.
 *
 * @return the next state to go to.
 */
private IAIState fillUpBrewingStand() {
    if (building.getAllBrewingStandPositions().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;
    }
    if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.BREWING_STAND) {
        walkTo = null;
        setDelay(STANDARD_DELAY);
        return START_WORKING;
    }
    final int burningCount = countOfBubblingBrewingStands();
    final TileEntity entity = world.getBlockEntity(walkTo);
    if (entity instanceof BrewingStandTileEntity && currentRecipeStorage != null) {
        final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
        final int maxBrewingStands = getMaxUsableBrewingStands();
        final int resultInBrewingStand = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
        final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
        if (isEmpty(((BrewingStandTileEntity) entity).getItem(0)) || isEmpty(((BrewingStandTileEntity) entity).getItem(1)) || isEmpty(((BrewingStandTileEntity) entity).getItem(2))) {
            final ItemStack potionStack = currentRecipeStorage.getCleanedInput().get(1).getItemStack();
            final Predicate<ItemStack> potion = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(potionStack, stack);
            final int potionInBrewingStand = getExtendedCount(potionStack);
            final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - potionInBrewingStand - resultInBrewingStand - resultInCitizenInv;
            if (targetCount <= 0) {
                return START_WORKING;
            }
            final int amountOfPotionInBuilding = InventoryUtils.getCountFromBuilding(building, potion);
            final int amountOfPotionInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), potion);
            if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
                worker.setItemInHand(Hand.MAIN_HAND, potionStack.copy());
            }
            if (amountOfPotionInInv > 0) {
                if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
                    for (int slot = 0; slot < 3; slot++) {
                        if (!isEmpty(((BrewingStandTileEntity) entity).getItem(slot))) {
                            continue;
                        }
                        int toTransfer = 0;
                        if (burningCount < maxBrewingStands) {
                            toTransfer = 1;
                        }
                        if (toTransfer > 0) {
                            if (walkToBlock(walkTo)) {
                                return getState();
                            }
                            worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
                            InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), potion, toTransfer, new InvWrapper(brewingStand), slot);
                        }
                    }
                }
            } else if (amountOfPotionInBuilding >= targetCount - amountOfPotionInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
                needsCurrently = new Tuple<>(potion, targetCount);
                return GATHERING_REQUIRED_MATERIALS;
            } else {
                // This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
                job.finishRequest(false);
                resetValues();
                walkTo = null;
                return IDLE;
            }
        } else if (isEmpty(((BrewingStandTileEntity) entity).getItem(INGREDIENT_SLOT))) {
            final ItemStack ingredientStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
            final Predicate<ItemStack> ingredient = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(ingredientStack, stack);
            final int ingredientInBrewingStand = getExtendedCount(ingredientStack);
            final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - ingredientInBrewingStand * 3 - resultInBrewingStand - resultInCitizenInv;
            if (targetCount <= 0) {
                return START_WORKING;
            }
            final int amountOfIngredientInBuilding = InventoryUtils.getCountFromBuilding(building, ingredient);
            final int amountOfIngredientInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), ingredient);
            if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
                worker.setItemInHand(Hand.MAIN_HAND, ingredientStack.copy());
            }
            if (amountOfIngredientInInv > 0) {
                if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
                    int toTransfer = 0;
                    if (burningCount < maxBrewingStands) {
                        toTransfer = 1;
                    }
                    if (toTransfer > 0) {
                        if (walkToBlock(walkTo)) {
                            return getState();
                        }
                        worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
                        InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), ingredient, toTransfer, new InvWrapper(brewingStand), INGREDIENT_SLOT);
                    }
                }
            } else if (amountOfIngredientInBuilding >= targetCount - amountOfIngredientInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
                needsCurrently = new Tuple<>(ingredient, targetCount);
                return GATHERING_REQUIRED_MATERIALS;
            } else {
                // This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
                job.finishRequest(false);
                resetValues();
                walkTo = null;
                return IDLE;
            }
        }
    } else if (!(world.getBlockState(walkTo).getBlock() instanceof BrewingStandBlock)) {
        building.removeBrewingStand(walkTo);
    }
    walkTo = null;
    setDelay(STANDARD_DELAY);
    return START_WORKING;
}
Also used : 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) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AbstractAdvancedPathNavigate(com.minecolonies.api.entity.pathfinding.AbstractAdvancedPathNavigate) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) ModItems(com.minecolonies.api.items.ModItems) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) Network(com.minecolonies.coremod.Network) SoundCategory(net.minecraft.util.SoundCategory) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) Constants(com.minecolonies.api.util.constant.Constants) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ShearsItem(net.minecraft.item.ShearsItem) 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) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) JobAlchemist(com.minecolonies.coremod.colony.jobs.JobAlchemist) TileEntity(net.minecraft.tileentity.TileEntity) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BuildingAlchemist(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingAlchemist) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) Predicate(java.util.function.Predicate) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 5 with BrewingStandTileEntity

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

the class EntityAIWorkAlchemist method accelerateBrewingStand.

/**
 * Actually accelerate the brewingStand
 */
private boolean accelerateBrewingStand() {
    final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getSecondarySkill()) / 10) * 2;
    final World world = building.getColony().getWorld();
    for (final BlockPos pos : building.getAllBrewingStandPositions()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof BrewingStandTileEntity) {
                final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
                for (int i = 0; i < accelerationTicks; i++) {
                    if (brewingStand.brewTime > 0) {
                        brewingStand.tick();
                    }
                }
            }
        }
    }
    return false;
}
Also used : BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) BrewingStandTileEntity(net.minecraft.tileentity.BrewingStandTileEntity) World(net.minecraft.world.World)

Aggregations

BrewingStandTileEntity (net.minecraft.tileentity.BrewingStandTileEntity)10 TileEntity (net.minecraft.tileentity.TileEntity)10 BlockPos (net.minecraft.util.math.BlockPos)9 World (net.minecraft.world.World)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)5 TypeToken (com.google.common.reflect.TypeToken)4 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)4 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)4 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)4 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)4 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)4 PublicCrafting (com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting)4 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 AIEventTarget (com.minecolonies.api.entity.ai.statemachine.AIEventTarget)4 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIBlockingEventType (com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 VisibleCitizenStatus (com.minecolonies.api.entity.citizen.VisibleCitizenStatus)4