From 2489907c41ce77376e1e100acc56aebc6948b115 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 8 Aug 2020 21:37:36 +0800 Subject: Improve ContainerInfo to allow non-vanilla slots or custom behaviour Signed-off-by: shedaniel --- .../me/shedaniel/rei/server/ContainerContext.java | 39 ++++++++++ .../me/shedaniel/rei/server/ContainerInfo.java | 82 +++++++++++++++++++++- .../java/me/shedaniel/rei/server/DumpHandler.java | 58 +++++++++++++++ .../me/shedaniel/rei/server/GridCleanHandler.java | 50 +++++++++++++ .../shedaniel/rei/server/GridStacksProvider.java | 31 ++++++++ .../rei/server/InventoryStackAccessor.java | 52 ++++++++++++++ .../java/me/shedaniel/rei/server/RecipeFinder.java | 26 +++---- .../rei/server/RecipeFinderPopulator.java | 35 +++++++++ .../me/shedaniel/rei/server/RecipeGridAligner.java | 48 ++----------- .../me/shedaniel/rei/server/SlotStackAccessor.java | 50 +++++++++++++ .../me/shedaniel/rei/server/StackAccessor.java | 34 +++++++++ 11 files changed, 447 insertions(+), 58 deletions(-) create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerContext.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/DumpHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridCleanHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridStacksProvider.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/InventoryStackAccessor.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinderPopulator.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/SlotStackAccessor.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/StackAccessor.java (limited to 'RoughlyEnoughItems-api/src/main/java') diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerContext.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerContext.java new file mode 100644 index 000000000..18158e673 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerContext.java @@ -0,0 +1,39 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.container.Container; +import net.minecraft.entity.player.PlayerEntity; + +public interface ContainerContext { + T getContainer(); + + PlayerEntity getPlayerEntity(); + + ContainerInfo getContainerInfo(); + + default StackAccessor getStack(int slotIndex) { + return getContainerInfo().getStack(this, slotIndex); + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java index 11c90064e..2a6649f3b 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java @@ -24,17 +24,95 @@ package me.shedaniel.rei.server; import net.minecraft.container.Container; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.collection.DefaultedList; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public interface ContainerInfo { Class getContainerClass(); + default StackAccessor getStack(ContainerContext context, int slotIndex) { + return new SlotStackAccessor(context.getContainer().getSlot(slotIndex)); + } + + default GridCleanHandler getGridCleanHandler() { + return context -> { + T container = context.getContainer(); + for (StackAccessor gridStack : getGridStacks(context)) { + GridCleanHandler.returnSlotToPlayerInventory(context, gridStack); + } + + clearCraftingSlots(container); + }; + } + + default DumpHandler getDumpHandler() { + return (context, stackToInsert) -> { + List inventoryStacks = context.getContainerInfo().getInventoryStacks(context); + + StackAccessor nextSlot = DumpHandler.getOccupiedSlotWithRoomForStack(stackToInsert, inventoryStacks); + if (nextSlot == null) { + nextSlot = DumpHandler.getEmptySlot(inventoryStacks); + } + if (nextSlot == null) { + return false; + } + + ItemStack stack = stackToInsert.copy(); + stack.setCount(nextSlot.getItemStack().getCount() + stack.getCount()); + nextSlot.setItemStack(stack); + return true; + }; + } + + default RecipeFinderPopulator getRecipeFinderPopulator() { + return context -> recipeFinder -> { + for (StackAccessor inventoryStack : getInventoryStacks(context)) { + recipeFinder.addNormalItem(inventoryStack.getItemStack()); + } + populateRecipeFinder(context.getContainer(), recipeFinder); + }; + } + + default List getGridStacks(ContainerContext context) { + return IntStream.range(0, getCraftingWidth(context.getContainer()) * getCraftingHeight(context.getContainer()) + 1) + .filter(value -> value != getCraftingResultSlotIndex(context.getContainer())) + .mapToObj(context::getStack) + .collect(Collectors.toList()); + } + + default List getInventoryStacks(ContainerContext context) { + PlayerInventory inventory = context.getPlayerEntity().inventory; + return IntStream.range(0, inventory.main.size()) + .mapToObj(index -> (StackAccessor) new InventoryStackAccessor(inventory, index)) + .collect(Collectors.toList()); + } + + default void markDirty(ContainerContext context) { + context.getPlayerEntity().inventory.markDirty(); + context.getContainer().sendContentUpdates(); + + DefaultedList defaultedList = DefaultedList.of(); + for (Slot slot : context.getPlayerEntity().container.slots) { + defaultedList.add(slot.getStack()); + } + + ((ServerPlayerEntity) context.getPlayerEntity()).onContainerRegistered(context.getPlayerEntity().container, defaultedList); + } + int getCraftingResultSlotIndex(T container); int getCraftingWidth(T container); int getCraftingHeight(T container); - void clearCraftingSlots(T container); + default void clearCraftingSlots(T container) {} - void populateRecipeFinder(T container, RecipeFinder var1); + default void populateRecipeFinder(T container, RecipeFinder var1) {} } diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/DumpHandler.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/DumpHandler.java new file mode 100644 index 000000000..c5e04e12b --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/DumpHandler.java @@ -0,0 +1,58 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.container.Container; +import net.minecraft.item.ItemStack; + +import java.util.List; + +@FunctionalInterface +public interface DumpHandler { + boolean dump(ContainerContext context, ItemStack stackToInsert); + + static StackAccessor getOccupiedSlotWithRoomForStack(ItemStack stack, List inventoryStacks) { + for (StackAccessor inventoryStack : inventoryStacks) { + if (canStackAddMore(inventoryStack.getItemStack(), stack)) { + return inventoryStack; + } + } + + return null; + } + + static StackAccessor getEmptySlot(List inventoryStacks) { + for (StackAccessor inventoryStack : inventoryStacks) { + if (inventoryStack.getItemStack().isEmpty()) { + return inventoryStack; + } + } + + return null; + } + + static boolean canStackAddMore(ItemStack existingStack, ItemStack stack) { + return !existingStack.isEmpty() && ItemStack.areItemsEqual(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() + stack.getCount() <= existingStack.getMaxCount(); + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridCleanHandler.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridCleanHandler.java new file mode 100644 index 000000000..557675533 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridCleanHandler.java @@ -0,0 +1,50 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.container.Container; +import net.minecraft.item.ItemStack; + +@FunctionalInterface +public interface GridCleanHandler { + void clean(ContainerContext context); + + static void error(String translationKey) { + throw new IllegalStateException(translationKey); + } + + static void returnSlotToPlayerInventory(ContainerContext context, StackAccessor stackAccessor) { + DumpHandler dumpHandler = context.getContainerInfo().getDumpHandler(); + ItemStack stackToReturn = stackAccessor.getItemStack(); + if (!stackToReturn.isEmpty()) { + for (; stackToReturn.getCount() > 0; stackAccessor.takeStack(1)) { + ItemStack stackToInsert = stackToReturn.copy(); + stackToInsert.setCount(1); + if (!dumpHandler.dump(context, stackToInsert)) { + error("rei.rei.no.slot.in.inv"); + } + } + } + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridStacksProvider.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridStacksProvider.java new file mode 100644 index 000000000..5d127aa34 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/GridStacksProvider.java @@ -0,0 +1,31 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.container.Container; + +@FunctionalInterface +public interface GridStacksProvider { + Iterable getStacks(ContainerContext context); +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/InventoryStackAccessor.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/InventoryStackAccessor.java new file mode 100644 index 000000000..71deced61 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/InventoryStackAccessor.java @@ -0,0 +1,52 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; + +public class InventoryStackAccessor implements StackAccessor { + protected Inventory inventory; + protected int index; + + public InventoryStackAccessor(Inventory inventory, int index) { + this.inventory = inventory; + this.index = index; + } + + @Override + public ItemStack getItemStack() { + return inventory.getInvStack(index); + } + + @Override + public void setItemStack(ItemStack stack) { + this.inventory.setInvStack(index, stack); + } + + @Override + public ItemStack takeStack(int amount) { + return this.inventory.takeInvStack(index, amount); + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java index d9e0d429d..f0d90f770 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java @@ -172,10 +172,10 @@ public class RecipeFinder { this.bitSet.clear(0, this.ingredientCount + this.usableIngredientSize + this.ingredientCount); int int_5 = 0; - List list_1 = ingredientsInput.stream().collect(Collectors.toList()); - - for (int int_6 = 0; int_6 < list_1.size(); ++int_6) { - if (boolean_2 && list_1.get(int_6).isEmpty()) { + List list_1 = new ArrayList<>(ingredientsInput); + + for (Ingredient ingredient : list_1) { + if (boolean_2 && ingredient.isEmpty()) { intList_1.add(0); } else { for (int int_7 = 0; int_7 < this.usableIngredientSize; ++int_7) { @@ -187,7 +187,7 @@ public class RecipeFinder { } } } - + ++int_5; } } @@ -198,10 +198,8 @@ public class RecipeFinder { private int[] getUsableIngredientItemIds() { IntCollection intCollection_1 = new IntAVLTreeSet(); - Iterator var2 = this.ingredients.iterator(); - - while (var2.hasNext()) { - Ingredient ingredient_1 = (Ingredient) var2.next(); + + for (Ingredient ingredient_1 : this.ingredients) { intCollection_1.addAll(ingredient_1.getIds()); } @@ -325,17 +323,15 @@ public class RecipeFinder { @SuppressWarnings("deprecation") private int method_7415() { int int_1 = Integer.MAX_VALUE; - Iterator var2 = this.ingredients.iterator(); - - while (var2.hasNext()) { - Ingredient ingredient_1 = (Ingredient) var2.next(); + + for (Ingredient ingredient_1 : this.ingredients) { int int_2 = 0; - + int int_3; for (IntListIterator var5 = ingredient_1.getIds().iterator(); var5.hasNext(); int_2 = Math.max(int_2, RecipeFinder.this.idToAmountMap.get(int_3))) { int_3 = var5.next(); } - + if (int_1 > 0) { int_1 = Math.min(int_1, int_2); } diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinderPopulator.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinderPopulator.java new file mode 100644 index 000000000..be785ebbd --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinderPopulator.java @@ -0,0 +1,35 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.container.Container; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +@FunctionalInterface +public interface RecipeFinderPopulator { + @NotNull + Consumer populate(ContainerContext context); +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java index e672d2015..80744de65 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java @@ -23,56 +23,22 @@ package me.shedaniel.rei.server; -import net.minecraft.recipe.Ingredient; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.ApiStatus; import java.util.Iterator; +import java.util.List; @ApiStatus.Internal public interface RecipeGridAligner { - default void alignRecipeToGrid(int int_1, int int_2, int int_3, DefaultedList recipe_1, Iterator iterator_1, int int_4) { - int int_7 = 0; - - for (int int_8 = 0; int_8 < int_2; ++int_8) { - if (int_7 == int_3) { - ++int_7; + default void alignRecipeToGrid(List gridStacks, Iterator iterator_1, int craftsAmount) { + for (StackAccessor gridStack : gridStacks) { + if (!iterator_1.hasNext()) { + return; } - boolean boolean_1 = (float) int_2 < (float) int_2 / 2.0F; - int int_9 = MathHelper.floor((float) int_2 / 2.0F - (float) int_2 / 2.0F); - if (boolean_1 && int_9 > int_8) { - int_7 += int_1; - ++int_8; - } - - for (int int_10 = 0; int_10 < int_1; ++int_10) { - if (!iterator_1.hasNext()) { - return; - } - - boolean_1 = (float) int_1 < (float) int_1 / 2.0F; - int_9 = MathHelper.floor((float) int_1 / 2.0F - (float) int_1 / 2.0F); - int int_11 = int_1; - boolean boolean_2 = int_10 < int_1; - if (boolean_1) { - int_11 = int_9 + int_1; - boolean_2 = int_9 <= int_10 && int_10 < int_9 + int_1; - } - - if (boolean_2) { - this.acceptAlignedInput(iterator_1, int_7, int_4, int_8, int_10); - } else if (int_11 == int_10) { - int_7 += int_1 - int_10; - break; - } - - ++int_7; - } + this.acceptAlignedInput(iterator_1, gridStack, craftsAmount); } - } - void acceptAlignedInput(Iterator var1, int var2, int var3, int var4, int var5); + void acceptAlignedInput(Iterator var1, StackAccessor gridSlot, int craftsAmount); } \ No newline at end of file diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/SlotStackAccessor.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/SlotStackAccessor.java new file mode 100644 index 000000000..46b4d7b8b --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/SlotStackAccessor.java @@ -0,0 +1,50 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; + +public class SlotStackAccessor implements StackAccessor { + protected Slot slot; + + public SlotStackAccessor(Slot slot) { + this.slot = slot; + } + + @Override + public ItemStack getItemStack() { + return slot.getStack(); + } + + @Override + public void setItemStack(ItemStack stack) { + this.slot.setStack(stack); + } + + @Override + public ItemStack takeStack(int amount) { + return slot.takeStack(amount); + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/StackAccessor.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/StackAccessor.java new file mode 100644 index 000000000..65b722a9e --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/StackAccessor.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.server; + +import net.minecraft.item.ItemStack; + +public interface StackAccessor { + ItemStack getItemStack(); + + void setItemStack(ItemStack stack); + + ItemStack takeStack(int amount); +} -- cgit