Skip to content

Commit

Permalink
Fix alchemist potion teaching (#10554)
Browse files Browse the repository at this point in the history
Fix alchemist potion crafting, teaching, and JEI display
  • Loading branch information
uecasm authored Dec 24, 2024
1 parent 5756219 commit 380625d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ else if (slot >= 0 && slot < 3)
this.playerInventory = inv;
this.buildingPos = pos;

this.addSlot(new SlotItemHandler(brewingStandInventory, 3, 79, 17));

this.addSlot(new InputItemHandler(brewingStandInventory, 0, 56, 51));
this.addSlot(new InputItemHandler(brewingStandInventory, 1, 79, 58));
this.addSlot(new InputItemHandler(brewingStandInventory, 2, 102, 51));

this.addSlot(new SlotItemHandler(brewingStandInventory, 3, 79, 17));

// Player inventory slots
// Note: The slot numbers are within the player inventory and may be the same as the field inventory.
int i;
Expand Down Expand Up @@ -273,7 +273,7 @@ public void clicked(final int slotId, final int clickedButton, final ClickType m
*/
public void setInput(final ItemStack stack)
{
handleSlotClick(getSlot(0), stack);
handleSlotClick(getSlot(3), stack);
}

/**
Expand All @@ -283,9 +283,9 @@ public void setInput(final ItemStack stack)
*/
public void setContainer(final ItemStack stack)
{
handleSlotClick(getSlot(0), stack);
handleSlotClick(getSlot(1), stack);
handleSlotClick(getSlot(2), stack);
handleSlotClick(getSlot(3), stack);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.minecolonies.core.colony.buildings.moduleviews.CraftingModuleView;
import com.minecolonies.core.colony.buildings.views.AbstractBuildingView;
import com.minecolonies.core.network.messages.server.colony.building.worker.AddRemoveRecipeMessage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
Expand All @@ -16,7 +17,6 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -112,19 +112,18 @@ public void onPress(@NotNull final Button button)
{
if (module.canLearn(ModCraftingTypes.BREWING.get()))
{
final ItemStack potion = container.getSlot(0).getItem();
final ItemStack ingredient = container.getSlot(3).getItem();

final List<ItemStorage> input = new ArrayList<>();
input.add(new ItemStorage(container.slots.get(0).getItem()));
input.add(new ItemStorage(container.slots.get(1).getItem()));
input.add(new ItemStorage(container.slots.get(2).getItem()));
input.add(new ItemStorage(container.slots.get(3).getItem()));
input.add(new ItemStorage(potion, 3, false));
input.add(new ItemStorage(ingredient));

final ItemStack
primaryOutput = PotionBrewing.EMPTY.mix(container.slots.get(3).getItem(), container.slots.get(0).getItem()).copy();
primaryOutput.setCount(3);
final ItemStack primaryOutput = Minecraft.getInstance().level.potionBrewing().mix(ingredient, potion);

if (!ItemStackUtils.isEmpty(primaryOutput))
if (!ItemStackUtils.isEmpty(primaryOutput) && primaryOutput != potion)
{
new AddRemoveRecipeMessage(building, input, 1, primaryOutput, false, Blocks.BREWING_STAND, module.getProducer().getRuntimeID()).sendToServer();
new AddRemoveRecipeMessage(building, input, 1, primaryOutput.copyWithCount(3), false, Blocks.BREWING_STAND, module.getProducer().getRuntimeID()).sendToServer();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
import com.minecolonies.api.crafting.registry.CraftingType;
import com.minecolonies.api.equipment.ModEquipmentTypes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.common.brewing.IBrewingRecipe;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* A crafting type for brewing recipes
Expand All @@ -39,31 +34,23 @@ public List<IGenericRecipe> findRecipes(@NotNull RecipeManager recipeManager, @N
final List<IGenericRecipe> recipes = new ArrayList<>();
final ICompatibilityManager compatibilityManager = MinecoloniesAPIProxy.getInstance().getColonyManager().getCompatibilityManager();

for (final IBrewingRecipe recipe : PotionBrewing.EMPTY.getRecipes())
{
final List<ItemStack> inputs = compatibilityManager.getListOfAllItems().stream()
.filter(recipe::isInput)
.collect(Collectors.toList());
final List<ItemStack> ingredients = compatibilityManager.getListOfAllItems().stream()
.filter(recipe::isIngredient)
.collect(Collectors.toList());
final List<ItemStack> containers = compatibilityManager.getListOfAllItems().stream()
.filter(world.potionBrewing()::isInput)
.toList();
final List<ItemStack> ingredients = compatibilityManager.getListOfAllItems().stream()
.filter(world.potionBrewing()::isIngredient)
.toList();

for (final ItemStack input : inputs)
for (final ItemStack container : containers)
{
for (final ItemStack ingredient : ingredients)
{
for (final ItemStack ingredient : ingredients)
final ItemStack output = world.potionBrewing().mix(ingredient, container);
if (!output.isEmpty() && output != container)
{
final ItemStack output = recipe.getOutput(input, ingredient);
if (!output.isEmpty())
{
final ItemStack actualInput = input.copy();
actualInput.setCount(3);
final ItemStack actualOutput = output.copy();
actualOutput.setCount(3);

recipes.add(new GenericRecipe(null, actualOutput, Collections.emptyList(),
Arrays.asList(Collections.singletonList(ingredient), Collections.singletonList(actualInput)),
1, Blocks.BREWING_STAND, null, ModEquipmentTypes.none.get(), Collections.emptyList(), -1));
}
recipes.add(new GenericRecipe(null, output.copyWithCount(3), List.of(),
List.of(List.of(ingredient), List.of(container.copyWithCount(3))),
1, Blocks.BREWING_STAND, null, ModEquipmentTypes.none.get(), List.of(), -1));
}
}
}
Expand Down

0 comments on commit 380625d

Please sign in to comment.