aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-08-08 18:12:31 +0800
committershedaniel <daniel@shedaniel.me>2020-08-08 18:12:31 +0800
commitf50acefb5712a3d838ade2f89520282cb0bc4fa9 (patch)
tree6803e4e20d8bac482c1051ad7e8c5d14bcd17f15 /src/main/java/me
parent62cc7966d70898bcc024e81d619dab55246f7203 (diff)
downloadRoughlyEnoughItems-f50acefb5712a3d838ade2f89520282cb0bc4fa9.tar.gz
RoughlyEnoughItems-f50acefb5712a3d838ade2f89520282cb0bc4fa9.tar.bz2
RoughlyEnoughItems-f50acefb5712a3d838ade2f89520282cb0bc4fa9.zip
Improve auto crafting, now able to detect things on the grid
Diffstat (limited to 'src/main/java/me')
-rw-r--r--src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java2
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java33
-rw-r--r--src/main/java/me/shedaniel/rei/server/RecipeFinder.java4
3 files changed, 20 insertions, 19 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
index 0945283dd..55de81ce3 100644
--- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
@@ -382,7 +382,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
}
public static class Appearance {
- @UseSpecialRecipeTypeScreen private RecipeScreenType recipeScreenType = RecipeScreenType.UNSET;
+ @UseSpecialRecipeTypeScreen private RecipeScreenType recipeScreenType = RecipeScreenType.ORIGINAL;
@Comment("Declares the appearance of REI windows.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
private AppearanceTheme theme = AppearanceTheme.LIGHT;
@ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
diff --git a/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
index 31ee4024e..68950e9c0 100644
--- a/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
+++ b/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
@@ -32,6 +32,7 @@ import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.TransferRecipeDisplay;
import me.shedaniel.rei.server.ContainerInfo;
import me.shedaniel.rei.server.ContainerInfoHandler;
+import me.shedaniel.rei.server.RecipeFinder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
@@ -44,6 +45,7 @@ import net.minecraft.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.collection.DefaultedList;
+import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -69,7 +71,7 @@ public class DefaultCategoryHandler implements AutoTransferHandler {
if (recipe.getHeight() > containerInfo.getCraftingHeight(container) || recipe.getWidth() > containerInfo.getCraftingWidth(container))
return Result.createFailed(I18n.translate("error.rei.transfer.too_small", containerInfo.getCraftingWidth(container), containerInfo.getCraftingHeight(container)));
List<List<EntryStack>> input = recipe.getOrganisedInputEntries(containerInfo, container);
- IntList intList = hasItems(input);
+ IntList intList = hasItems(container, containerInfo, input);
if (!intList.isEmpty())
return Result.createFailed("error.rei.not.enough.materials", intList);
if (!canUseMovePackets())
@@ -103,11 +105,12 @@ public class DefaultCategoryHandler implements AutoTransferHandler {
return -10;
}
- public IntList hasItems(List<List<EntryStack>> inputs) {
+ public IntList hasItems(Container container, ContainerInfo<Container> containerInfo, List<List<EntryStack>> inputs) {
// Create a clone of player's inventory, and count
- DefaultedList<ItemStack> copyMain = DefaultedList.of();
+ RecipeFinder recipeFinder = new RecipeFinder();
+ containerInfo.populateRecipeFinder(container, recipeFinder);
for (ItemStack stack : MinecraftClient.getInstance().player.inventory.main) {
- copyMain.add(stack.copy());
+ recipeFinder.addNormalItem(stack.copy());
}
IntList intList = new IntArrayList();
for (int i = 0; i < inputs.size(); i++) {
@@ -115,19 +118,17 @@ public class DefaultCategoryHandler implements AutoTransferHandler {
boolean done = possibleStacks.isEmpty();
for (EntryStack possibleStack : possibleStacks) {
if (!done) {
- int invRequiredCount = possibleStack.getAmount();
- for (ItemStack stack : copyMain) {
- EntryStack entryStack = EntryStack.create(stack);
- if (entryStack.equals(possibleStack)) {
- while (invRequiredCount > 0 && !stack.isEmpty()) {
- invRequiredCount--;
- stack.decrement(1);
- }
+ if (possibleStack.getType() == EntryStack.Type.ITEM) {
+ int invRequiredCount = possibleStack.getAmount();
+ int key = Registry.ITEM.getRawId(possibleStack.getItem());
+ while (invRequiredCount > 0 && recipeFinder.contains(key)) {
+ invRequiredCount--;
+ recipeFinder.take(key, 1);
+ }
+ if (invRequiredCount <= 0) {
+ done = true;
+ break;
}
- }
- if (invRequiredCount <= 0) {
- done = true;
- break;
}
}
}
diff --git a/src/main/java/me/shedaniel/rei/server/RecipeFinder.java b/src/main/java/me/shedaniel/rei/server/RecipeFinder.java
index fb792805e..d9e0d429d 100644
--- a/src/main/java/me/shedaniel/rei/server/RecipeFinder.java
+++ b/src/main/java/me/shedaniel/rei/server/RecipeFinder.java
@@ -71,7 +71,7 @@ public class RecipeFinder {
}
- private boolean contains(int itemId) {
+ public boolean contains(int itemId) {
return this.idToAmountMap.get(itemId) > 0;
}
@@ -80,7 +80,7 @@ public class RecipeFinder {
*
* @return the amount taken
*/
- private int take(int itemId, int amount) {
+ public int take(int itemId, int amount) {
int mapAmount = this.idToAmountMap.get(itemId);
if (mapAmount >= amount) {
this.idToAmountMap.put(itemId, mapAmount - amount);