Search in sources :

Example 1 with IRecipeStorage

use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.

the class AbstractCraftingRequestResolver method resolveForBuilding.

@Override
public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Stack> request, @NotNull final AbstractBuilding building) {
    final AbstractBuildingWorker buildingWorker = (AbstractBuildingWorker) building;
    final IRecipeStorage storage = buildingWorker.getFirstFullFillableRecipe(request.getRequest().getStack());
    if (storage == null) {
        Log.getLogger().error("Failed to craft a crafting recipe of: " + request.getRequest().getStack().toString() + ". Its ingredients are missing.");
        return;
    }
    final int craftingCount = calculateMaxCraftingCount(request.getRequest().getStack(), storage);
    for (int i = 0; i < craftingCount; i++) {
        buildingWorker.fullFillRecipe(storage);
    }
    manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage)

Example 2 with IRecipeStorage

use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.

the class EntityAIWorkBaker method kneadTheDough.

/**
 * Prepares the baker for baking and requests ingredients.
 *
 * @return the next AIState
 */
private AIState kneadTheDough() {
    if (walkToBuilding()) {
        return getState();
    }
    if (currentBakingProduct == null) {
        return createNewProduct();
    }
    final IRecipeStorage storage = BakerRecipes.getRecipes().get(currentBakingProduct.getRecipeId());
    if (currentBakingProduct.getState() == ProductState.UNCRAFTED) {
        return craftNewProduct(storage);
    }
    if (currentBakingProduct.getState() != ProductState.RAW) {
        return PREPARING;
    }
    worker.setHeldItem(EnumHand.MAIN_HAND, storage.getInput().get(worker.getRandom().nextInt(storage.getInput().size())).copy());
    worker.hitBlockWithToolInHand(getOwnBuilding().getLocation());
    if (progress >= getRequiredProgressForKneading()) {
        worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
        progress = 0;
        currentBakingProduct.nextState();
        getOwnBuilding().removeFromTasks(ProductState.RAW, currentBakingProduct);
        getOwnBuilding().addToTasks(ProductState.PREPARED, currentBakingProduct);
        currentBakingProduct = null;
        return PREPARING;
    }
    progress++;
    setDelay(HIT_DELAY);
    return getState();
}
Also used : IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage)

Example 3 with IRecipeStorage

use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.

the class EntityAIWorkBaker method finishing.

private AIState finishing() {
    if (currentBakingProduct == null || currentBakingProduct.getState() != ProductState.BAKED) {
        progress = 0;
        final List<BakingProduct> bakingProducts = getOwnBuilding().getTasks().get(ProductState.BAKED);
        if (bakingProducts == null || bakingProducts.isEmpty()) {
            getOwnBuilding().removeFromTasks(ProductState.BAKED, null);
            return PREPARING;
        }
        currentBakingProduct = bakingProducts.get(0);
    }
    if (currentBakingProduct.getState() != ProductState.BAKED) {
        return PREPARING;
    }
    worker.setHeldItem(EnumHand.MAIN_HAND, currentBakingProduct.getEndProduct());
    worker.hitBlockWithToolInHand(getOwnBuilding().getLocation());
    if (progress >= getRequiredProgressForKneading()) {
        worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
        getOwnBuilding().removeFromTasks(ProductState.BAKED, currentBakingProduct);
        InventoryUtils.addItemStackToItemHandler(new InvWrapper(worker.getInventoryCitizen()), currentBakingProduct.getEndProduct());
        final IRecipeStorage storage = BakerRecipes.getRecipes().get(currentBakingProduct.getRecipeId());
        for (final ItemStack stack : storage.getInput()) {
            final ItemStack returnStack = stack.getItem().getContainerItem(stack);
            if (returnStack != null) {
                InventoryUtils.addItemStackToItemHandler(new InvWrapper(worker.getInventoryCitizen()), returnStack);
            }
        }
        worker.addExperience(XP_PER_PRODUCT);
        incrementActionsDoneAndDecSaturation();
        progress = 0;
        currentBakingProduct = null;
        return PREPARING;
    }
    progress++;
    setDelay(HIT_DELAY);
    return getState();
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IRecipeStorage

use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.

the class WindowListRecipes method onButtonClicked.

/**
 * Called when any button has been clicked.
 *
 * @param button the clicked button.
 */
@Override
public void onButtonClicked(@NotNull final Button button) {
    final int row = recipeList.getListElementIndexByPane(button) - 1;
    if (button.getID().equals(BUTTON_REMOVE)) {
        final IRecipeStorage data = recipes.get(row + 1);
        building.removeRecipe(row + 1);
        MineColonies.getNetwork().sendToServer(new AddRemoveRecipeMessage(data, building, true));
    } else if (button.getID().equals(BUTTON_UP)) {
        building.switchIndex(row, row + 1);
        MineColonies.getNetwork().sendToServer(new ChangeRecipePriorityMessage(building, row, true));
    } else if (button.getID().equals(BUTTON_DOWN)) {
        building.switchIndex(row, row - 1);
        MineColonies.getNetwork().sendToServer(new ChangeRecipePriorityMessage(building, row, false));
    } else if (button.getID().equals(BUTTON_CANCEL)) {
        building.openGui(false);
    }
}
Also used : ChangeRecipePriorityMessage(com.minecolonies.coremod.network.messages.ChangeRecipePriorityMessage) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) AddRemoveRecipeMessage(com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage)

Example 5 with IRecipeStorage

use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.

the class AbstractBuildingWorker method serializeToView.

@Override
public void serializeToView(@NotNull final ByteBuf buf) {
    super.serializeToView(buf);
    buf.writeInt(workers.size());
    for (final CitizenData data : workers) {
        buf.writeInt(data == null ? 0 : data.getId());
    }
    final List<IRecipeStorage> storages = new ArrayList<>();
    for (final IToken token : new ArrayList<>(recipes)) {
        final IRecipeStorage storage = ColonyManager.getRecipeManager().getRecipes().get(token);
        if (storage == null) {
            removeRecipe(token);
        } else {
            storages.add(storage);
        }
    }
    buf.writeInt(storages.size());
    for (final IRecipeStorage storage : storages) {
        ByteBufUtils.writeTag(buf, StandardFactoryController.getInstance().serialize(storage));
    }
}
Also used : IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Aggregations

IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)7 ItemStack (net.minecraft.item.ItemStack)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 AddRemoveRecipeMessage (com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage)1 ChangeRecipePriorityMessage (com.minecolonies.coremod.network.messages.ChangeRecipePriorityMessage)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1