diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-08-05 17:14:07 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-08-05 17:14:07 +0800 |
| commit | 8a2df51193fd3db145f3b1ace974e9e0a0bc09a5 (patch) | |
| tree | 894244ea7e84d9bd78748e4e295e528cfc9e7979 /RoughlyEnoughItems-runtime/src/main/java | |
| parent | 1ce5ca77bc2f98df6cc370c96547c2c39c1fd897 (diff) | |
| download | RoughlyEnoughItems-8a2df51193fd3db145f3b1ace974e9e0a0bc09a5.tar.gz RoughlyEnoughItems-8a2df51193fd3db145f3b1ace974e9e0a0bc09a5.tar.bz2 RoughlyEnoughItems-8a2df51193fd3db145f3b1ace974e9e0a0bc09a5.zip | |
REI 5.1.0:
- Improve auto crafting, now able to detect things on the grid
- Introduce getResultingEntries as a replacement for getOutputEntries, it can now handle lists of lists of stacks
- Caching for fluid hashing
- Full fractions support for simple recipe display
- Made searchFavorites defaulted false
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main/java')
6 files changed, 60 insertions, 37 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java index 8def60f1a..91dafd936 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java @@ -62,7 +62,7 @@ public class EntryListEntryWidget extends EntryWidget { return super.mouseReleased(mouseX, mouseY, button); if (containsMouse(mouseX, mouseY) && ClientHelper.getInstance().isCheating()) { EntryStack entry = getCurrentEntry().copy(); - if (!entry.isEmpty()) { + if (!entry.isEmpty() && wasClicked()) { if (entry.getType() == EntryStack.Type.FLUID) { Item bucketItem = entry.getFluid().getBucketItem(); if (bucketItem != null) { diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java index 40fd116f0..eec55c54f 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java @@ -29,7 +29,6 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; -import me.shedaniel.rei.api.fractions.Fraction; import me.shedaniel.rei.api.widgets.Slot; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.ContainerScreenOverlay; @@ -65,6 +64,7 @@ public class EntryWidget extends Slot { protected boolean background = true; protected boolean interactable = true; protected boolean interactableFavorites = true; + protected boolean wasClicked = false; private Rectangle bounds; private List<EntryStack> entryStacks; @@ -350,11 +350,24 @@ public class EntryWidget extends Slot { return Collections.emptyList(); } + protected boolean wasClicked() { + boolean b = this.wasClicked; + this.wasClicked = false; + return b; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (containsMouse(mouseX, mouseY)) + this.wasClicked = true; + return super.mouseClicked(mouseX, mouseY, button); + } + @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { if (!interactable) return false; - if (containsMouse(mouseX, mouseY)) { + if (wasClicked() && containsMouse(mouseX, mouseY)) { if (interactableFavorites && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.ofMouse()) && !getCurrentEntry().isEmpty()) { ModifierKeyCode keyCode = ConfigObject.getInstance().getFavoriteKeyCode(); EntryStack entry = getCurrentEntry().copy(); diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java index 3723628ec..f4792168c 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java @@ -448,7 +448,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } public static class Search { - @Comment("Declares whether favorites will be searched.") private boolean searchFavorites = true; + @Comment("Declares whether favorites will be searched.") private boolean searchFavorites = false; @Comment("Declares whether search time should be debugged.") private boolean debugSearchTimeRequired = false; @Comment("Declares whether REI should search async.") private boolean asyncSearch = true; @Comment("Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400) diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java index 8a7c395dd..d75deeda5 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java @@ -65,6 +65,8 @@ public class FluidEntryStack extends AbstractEntryStack { private static final Fraction IGNORE_AMOUNT = Fraction.of(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)).simplify(); private Fluid fluid; private Fraction amount; + private int hashIgnoreAmount; + private int hash; public FluidEntryStack(Fluid fluid) { this(fluid, IGNORE_AMOUNT); @@ -73,6 +75,15 @@ public class FluidEntryStack extends AbstractEntryStack { public FluidEntryStack(Fluid fluid, Fraction amount) { this.fluid = fluid; this.amount = amount; + + rehash(); + } + + private void rehash() { + hashIgnoreAmount = 31 + getType().ordinal(); + hashIgnoreAmount = 31 * hashIgnoreAmount + fluid.hashCode(); + + hash = 31 * hashIgnoreAmount + amount.hashCode(); } @Override @@ -96,6 +107,8 @@ public class FluidEntryStack extends AbstractEntryStack { if (isEmpty()) { fluid = Fluids.EMPTY; } + + rehash(); } private <T extends Comparable<T>> T max(T o1, T o2) { @@ -157,27 +170,22 @@ public class FluidEntryStack extends AbstractEntryStack { @Override public int hashOfAll() { - int result = hashIgnoreAmountAndTags(); - result = 31 * result + amount.hashCode(); - return result; + return hash; } @Override public int hashIgnoreAmountAndTags() { - int result = 1; - result = 31 * result + getType().ordinal(); - result = 31 * result + fluid.hashCode(); - return result; + return hashIgnoreAmount; } @Override public int hashIgnoreTags() { - return hashOfAll(); + return hash; } @Override public int hashIgnoreAmount() { - return hashIgnoreAmountAndTags(); + return hashIgnoreAmount; } @Nullable diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java index 10234146c..553a42813 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java @@ -98,7 +98,7 @@ public class RecipeHelperImpl implements RecipeHelper { } } if (slotsCraftable == recipeDisplay.getRequiredEntries().size()) - craftables.addAll(recipeDisplay.getOutputEntries()); + recipeDisplay.getResultingEntries().stream().flatMap(Collection::stream).collect(Collectors.toCollection(() -> craftables)); } return craftables.stream().distinct().collect(Collectors.toList()); } @@ -175,12 +175,14 @@ public class RecipeHelperImpl implements RecipeHelper { for (RecipeDisplay display : allRecipesFromCategory) { if (!isDisplayVisible(display)) continue; if (!recipesFor.isEmpty()) { - label: - for (EntryStack outputStack : display.getOutputEntries()) { - for (EntryStack stack : recipesFor) { - if (stack.equals(outputStack)) { - set.add(display); - break label; + back: + for (List<EntryStack> results : display.getResultingEntries()) { + for (EntryStack otherEntry : results) { + for (EntryStack stack : recipesFor) { + if (otherEntry.equals(stack)) { + set.add(display); + break back; + } } } } diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java index cf09ab318..f6ceaa584 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java @@ -33,6 +33,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,7 +45,7 @@ import net.minecraft.client.resource.language.I18n; 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; @@ -66,7 +67,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 (!ClientHelper.getInstance().canUseMovePackets()) @@ -100,11 +101,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++) { @@ -112,19 +114,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; } } } |
