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);
}
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();
}
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();
}
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);
}
}
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));
}
}
Aggregations