diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-08-06 22:35:12 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-08-06 22:35:12 +0800 |
| commit | 70417f41613ae30582cd48708fe43ce9a3e6ae86 (patch) | |
| tree | 7a0b8286005568237e894662a9c40bfdb42550d7 /src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java | |
| parent | cbf03f9c2625b0f336ae86a916fe77db2ee4a420 (diff) | |
| download | RoughlyEnoughItems-70417f41613ae30582cd48708fe43ce9a3e6ae86.tar.gz RoughlyEnoughItems-70417f41613ae30582cd48708fe43ce9a3e6ae86.tar.bz2 RoughlyEnoughItems-70417f41613ae30582cd48708fe43ce9a3e6ae86.zip | |
These days are great days to completely scrap an api
Diffstat (limited to 'src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java b/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java index 100b20317..530d884d1 100644 --- a/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java +++ b/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java @@ -9,7 +9,6 @@ import com.google.common.collect.Lists; import net.minecraft.container.CraftingContainer; import net.minecraft.container.CraftingTableContainer; import net.minecraft.container.PlayerContainer; -import net.minecraft.container.Slot; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; @@ -17,7 +16,6 @@ import net.minecraft.recipe.RecipeFinder; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.DefaultedList; -import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -37,49 +35,65 @@ public class InputSlotCrafter<C extends Inventory> { } private void fillInputSlots(ServerPlayerEntity player, Map<Integer, List<ItemStack>> map, boolean hasShift) { + /* + * Steps: + * Return the already placed items on the grid + * Check if the player have the enough resource to even craft one + * Calculate how many items the player is going to craft + * Move the best suited items for the player to use + * Send container updates to the player + * Profit?? + */ this.inventory = player.inventory; if (this.canReturnInputs() || player.isCreative()) { // Return the already placed items on the grid this.returnInputs(); + // Check if the player have the enough resource to even craft one if (!isPossibleToCraft(map)) { craftingContainer.sendContentUpdates(); player.inventory.markDirty(); throw new NullPointerException(); } + // Calculate how many items the player is going to craft + int amountCrafting = hasShift ? 0 : 1; + if (hasShift) { + + } + // TODO: Rewrite most parts of this - map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> { - int id = entry.getKey().intValue(); - List<ItemStack> possibleStacks = entry.getValue(); - boolean done = false; - for (ItemStack possibleStack : possibleStacks) { - int requiredCount = possibleStack.getCount(); - int invCount = 0; - for (ItemStack stack : inventory.main) { - if (ItemStack.areItemsEqualIgnoreDamage(possibleStack, stack)) - invCount += stack.getCount(); - } - if (invCount >= requiredCount) { - for (ItemStack stack : inventory.main) { - if (ItemStack.areItemsEqualIgnoreDamage(possibleStack, stack)) { - Slot containerSlot = craftingContainer.getSlot(id + craftingContainer.getCraftingResultSlotIndex() + 1); - while (containerSlot.getStack().getCount() < requiredCount && !stack.isEmpty()) { - if (containerSlot.getStack().isEmpty()) { - containerSlot.setStack(new ItemStack(stack.getItem(), 1)); - } else { - containerSlot.getStack().setCount(containerSlot.getStack().getCount() + 1); - } - stack.setCount(stack.getCount() - 1); - } - if (containerSlot.getStack().getCount() >= requiredCount) - break; - } - } - break; - } - } - }); + // map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> { + // int id = entry.getKey().intValue(); + // List<ItemStack> possibleStacks = entry.getValue(); + // boolean done = false; + // for (ItemStack possibleStack : possibleStacks) { + // int requiredCount = possibleStack.getCount(); + // int invCount = 0; + // for (ItemStack stack : inventory.main) { + // if (ItemStack.areItemsEqualIgnoreDamage(possibleStack, stack)) + // invCount += stack.getCount(); + // } + // if (invCount >= requiredCount) { + // for (ItemStack stack : inventory.main) { + // if (ItemStack.areItemsEqualIgnoreDamage(possibleStack, stack)) { + // Slot containerSlot = craftingContainer.getSlot(id + craftingContainer.getCraftingResultSlotIndex() + 1); + // while (containerSlot.getStack().getCount() < requiredCount && !stack.isEmpty()) { + // if (containerSlot.getStack().isEmpty()) { + // containerSlot.setStack(new ItemStack(stack.getItem(), 1)); + // } else { + // containerSlot.getStack().setCount(containerSlot.getStack().getCount() + 1); + // } + // stack.setCount(stack.getCount() - 1); + // } + // if (containerSlot.getStack().getCount() >= requiredCount) + // break; + // } + // } + // break; + // } + // } + // }); craftingContainer.sendContentUpdates(); player.inventory.markDirty(); |
