diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java b/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java index 942b865af..cca9da0ab 100644 --- a/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java +++ b/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java @@ -26,13 +26,13 @@ package me.shedaniel.rei.server; import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import net.minecraft.container.Container; -import net.minecraft.container.Slot; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Ingredient; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.DefaultedList; import net.minecraft.util.Identifier; @@ -41,17 +41,17 @@ import java.util.*; public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<Integer> { - protected Container craftingContainer; + protected ScreenHandler screenHandler; protected ContainerInfo containerInfo; protected PlayerInventory inventory; - private InputSlotCrafter(Container craftingContainer, ContainerInfo<? extends Container> containerInfo) { - this.craftingContainer = craftingContainer; + private InputSlotCrafter(ScreenHandler screenHandler, ContainerInfo<? extends ScreenHandler> containerInfo) { + this.screenHandler = screenHandler; this.containerInfo = containerInfo; } - public static <C extends Inventory> void start(Identifier category, Container craftingContainer_1, ServerPlayerEntity player, Map<Integer, List<ItemStack>> map, boolean hasShift) { - ContainerInfo<? extends Container> containerInfo = Objects.requireNonNull(ContainerInfoHandler.getContainerInfo(category, craftingContainer_1.getClass()), "Container Info does not exist on the server!"); + public static <C extends Inventory> void start(Identifier category, ScreenHandler craftingContainer_1, ServerPlayerEntity player, Map<Integer, List<ItemStack>> map, boolean hasShift) { + ContainerInfo<? extends ScreenHandler> containerInfo = Objects.requireNonNull(ContainerInfoHandler.getContainerInfo(category, craftingContainer_1.getClass()), "Container Info does not exist on the server!"); new InputSlotCrafter<C>(craftingContainer_1, containerInfo).fillInputSlots(player, map, hasShift); } @@ -66,7 +66,7 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< for (ItemStack stack : player.inventory.main) { recipeFinder.addNormalItem(stack); } - this.containerInfo.populateRecipeFinder(craftingContainer, recipeFinder); + this.containerInfo.populateRecipeFinder(screenHandler, recipeFinder); DefaultedList<Ingredient> ingredients = DefaultedList.of(); map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> { ingredients.add(Ingredient.ofItems(entry.getValue().stream().map(ItemStack::getItem).toArray(Item[]::new))); @@ -85,7 +85,7 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< @Override public void acceptAlignedInput(Iterator<Integer> iterator_1, int int_1, int int_2, int int_3, int int_4) { - Slot slot_1 = this.craftingContainer.getSlot(int_1); + Slot slot_1 = this.screenHandler.getSlot(int_1); ItemStack itemStack_1 = RecipeFinder.getStackFromId(iterator_1.next()); if (!itemStack_1.isEmpty()) { for (int int_5 = 0; int_5 < int_2; ++int_5) { @@ -116,16 +116,15 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< } } - @SuppressWarnings("deprecation") protected void fillInputSlots(RecipeFinder recipeFinder, DefaultedList<Ingredient> ingredients, boolean hasShift) { // boolean boolean_2 = this.craftingContainer.matches(recipe_1); boolean boolean_2 = false; int int_1 = recipeFinder.countRecipeCrafts(ingredients, null); int int_2; if (boolean_2) { - for (int_2 = 0; int_2 < this.containerInfo.getCraftingHeight(craftingContainer) * this.containerInfo.getCraftingWidth(craftingContainer) + 1; ++int_2) { - if (int_2 != this.containerInfo.getCraftingResultSlotIndex(craftingContainer)) { - ItemStack itemStack_1 = this.craftingContainer.getSlot(int_2).getStack(); + for (int_2 = 0; int_2 < this.containerInfo.getCraftingHeight(screenHandler) * this.containerInfo.getCraftingWidth(screenHandler) + 1; ++int_2) { + if (int_2 != this.containerInfo.getCraftingResultSlotIndex(screenHandler)) { + ItemStack itemStack_1 = this.screenHandler.getSlot(int_2).getStack(); if (!itemStack_1.isEmpty() && Math.min(int_1, itemStack_1.getMaxCount()) < itemStack_1.getCount() + 1) { return; } @@ -147,7 +146,7 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< if (recipeFinder.findRecipe(ingredients, intList_1, int_4)) { this.returnInputs(); - this.alignRecipeToGrid(this.containerInfo.getCraftingWidth(craftingContainer), this.containerInfo.getCraftingHeight(craftingContainer), this.containerInfo.getCraftingResultSlotIndex(craftingContainer), ingredients, intList_1.iterator(), int_4); + this.alignRecipeToGrid(this.containerInfo.getCraftingWidth(screenHandler), this.containerInfo.getCraftingHeight(screenHandler), this.containerInfo.getCraftingResultSlotIndex(screenHandler), ingredients, intList_1.iterator(), int_4); } } @@ -159,9 +158,9 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< int_2 = int_1; } else if (boolean_2) { int_2 = 64; - for (int int_3 = 0; int_3 < this.containerInfo.getCraftingWidth(craftingContainer) * this.containerInfo.getCraftingHeight(craftingContainer) + 1; ++int_3) { - if (int_3 != this.containerInfo.getCraftingResultSlotIndex(craftingContainer)) { - ItemStack itemStack_1 = this.craftingContainer.getSlot(int_3).getStack(); + for (int int_3 = 0; int_3 < this.containerInfo.getCraftingWidth(screenHandler) * this.containerInfo.getCraftingHeight(screenHandler) + 1; ++int_3) { + if (int_3 != this.containerInfo.getCraftingResultSlotIndex(screenHandler)) { + ItemStack itemStack_1 = this.screenHandler.getSlot(int_3).getStack(); if (!itemStack_1.isEmpty() && int_2 > itemStack_1.getCount()) { int_2 = itemStack_1.getCount(); } @@ -175,19 +174,19 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< } protected void returnInputs() { - for (int int_1 = 0; int_1 < this.containerInfo.getCraftingWidth(craftingContainer) * this.containerInfo.getCraftingHeight(craftingContainer) + 1; ++int_1) { - if (int_1 != this.containerInfo.getCraftingResultSlotIndex(craftingContainer)) { + for (int int_1 = 0; int_1 < this.containerInfo.getCraftingWidth(screenHandler) * this.containerInfo.getCraftingHeight(screenHandler) + 1; ++int_1) { + if (int_1 != this.containerInfo.getCraftingResultSlotIndex(screenHandler)) { this.returnSlot(int_1); } } - this.containerInfo.clearCraftingSlots(craftingContainer); + this.containerInfo.clearCraftingSlots(screenHandler); } protected void returnSlot(int int_1) { - ItemStack itemStack_1 = this.craftingContainer.getSlot(int_1).getStack(); + ItemStack itemStack_1 = this.screenHandler.getSlot(int_1).getStack(); if (!itemStack_1.isEmpty()) { - for (; itemStack_1.getCount() > 0; this.craftingContainer.getSlot(int_1).takeStack(1)) { + for (; itemStack_1.getCount() > 0; this.screenHandler.getSlot(int_1).takeStack(1)) { int int_2 = this.inventory.getOccupiedSlotWithRoomForStack(itemStack_1); if (int_2 == -1) { int_2 = this.inventory.getEmptySlot(); @@ -206,9 +205,9 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner< List<ItemStack> list_1 = Lists.newArrayList(); int int_1 = this.getFreeInventorySlots(); - for (int int_2 = 0; int_2 < this.containerInfo.getCraftingWidth(craftingContainer) * this.containerInfo.getCraftingHeight(craftingContainer) + 1; ++int_2) { - if (int_2 != this.containerInfo.getCraftingResultSlotIndex(craftingContainer)) { - ItemStack itemStack_1 = this.craftingContainer.getSlot(int_2).getStack().copy(); + for (int int_2 = 0; int_2 < this.containerInfo.getCraftingWidth(screenHandler) * this.containerInfo.getCraftingHeight(screenHandler) + 1; ++int_2) { + if (int_2 != this.containerInfo.getCraftingResultSlotIndex(screenHandler)) { + ItemStack itemStack_1 = this.screenHandler.getSlot(int_2).getStack().copy(); if (!itemStack_1.isEmpty()) { int int_3 = this.inventory.getOccupiedSlotWithRoomForStack(itemStack_1); if (int_3 == -1 && list_1.size() <= int_1) { |
