Skip to content

Commit

Permalink
only look up when actually transferring
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkere committed Jun 13, 2021
1 parent 193547a commit d797804
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public IRecipeTransferError transferRecipe(@Nonnull GridContainer container, Obj
}

private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContainer container, IRecipeLayout recipeLayout, PlayerEntity player, boolean doTransfer) {
IngredientTracker tracker = createTracker(container, recipeLayout, player);
IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer);

if (doTransfer) {
if (tracker.hasMissingButAutocraftingAvailable() && Screen.hasControlDown()) {
Expand All @@ -84,7 +84,7 @@ private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContai
}

private IRecipeTransferError transferRecipeForPatternGrid(GridContainer container, IRecipeLayout recipeLayout, PlayerEntity player, boolean doTransfer) {
IngredientTracker tracker = createTracker(container, recipeLayout, player);
IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer);

if (doTransfer) {
moveItems(container, recipeLayout, tracker);
Expand All @@ -97,8 +97,8 @@ private IRecipeTransferError transferRecipeForPatternGrid(GridContainer containe
return null;
}

private IngredientTracker createTracker(GridContainer container, IRecipeLayout recipeLayout, PlayerEntity player) {
IngredientTracker tracker = new IngredientTracker(recipeLayout);
private IngredientTracker createTracker(GridContainer container, IRecipeLayout recipeLayout, PlayerEntity player, boolean doTransfer) {
IngredientTracker tracker = new IngredientTracker(recipeLayout, doTransfer);

// Using IGridView#getStacks will return a *filtered* list of items in the view,
// which will cause problems - especially if the user uses JEI synchronised searching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
public class IngredientTracker {
private final List<Ingredient> ingredients = new ArrayList<>();
private final Map<ResourceLocation, Integer> storedItems = new HashMap<>();
private boolean doTransfer;

public IngredientTracker(IRecipeLayout recipeLayout) {
public IngredientTracker(IRecipeLayout recipeLayout, boolean doTransfer) {
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
if (guiIngredient.isInput() && !guiIngredient.getAllIngredients().isEmpty()) {
ingredients.add(new Ingredient(guiIngredient));
}
}
this.doTransfer = doTransfer;
}

public Collection<Ingredient> getIngredients() {
Expand All @@ -32,13 +34,15 @@ public Collection<Ingredient> getIngredients() {

public void addAvailableStack(ItemStack stack, @Nullable IGridStack gridStack) {
int available = stack.getCount();
if (stack.getItem() instanceof PatternItem) {
NonNullList<ItemStack> outputStacks = PatternItem.fromCache(Minecraft.getInstance().world,stack).getOutputs();
for (ItemStack outputStack : outputStacks) {
storedItems.merge(outputStack.getItem().getRegistryName(), outputStack.getCount(), Integer::sum);
if (doTransfer) {
if (stack.getItem() instanceof PatternItem) {
NonNullList<ItemStack> outputStacks = PatternItem.fromCache(Minecraft.getInstance().world, stack).getOutputs();
for (ItemStack outputStack : outputStacks) {
storedItems.merge(outputStack.getItem().getRegistryName(), outputStack.getCount(), Integer::sum);
}
} else {
storedItems.merge(stack.getItem().getRegistryName(), available, Integer::sum);
}
} else {
storedItems.merge(stack.getItem().getRegistryName(), available, Integer::sum);
}

for (Ingredient ingredient : ingredients) {
Expand Down

0 comments on commit d797804

Please sign in to comment.