aboutsummaryrefslogtreecommitdiff
path: root/default-plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-09-01 19:49:53 +0800
committershedaniel <daniel@shedaniel.me>2023-09-01 19:49:53 +0800
commit8c03832d5ae716beba4047166505181cadd76e75 (patch)
tree372a573e629023a081b452a2404ee347a05efa08 /default-plugin
parente8cec3c8cf26ae9f5e200dd9f697887e40948303 (diff)
parent6a8bc6a8c34af1e3ff15fe8a802ef5ece3c417d2 (diff)
downloadRoughlyEnoughItems-8c03832d5ae716beba4047166505181cadd76e75.tar.gz
RoughlyEnoughItems-8c03832d5ae716beba4047166505181cadd76e75.tar.bz2
RoughlyEnoughItems-8c03832d5ae716beba4047166505181cadd76e75.zip
Merge remote-tracking branch 'shedaniel/9.x-1.19' into 11.x-1.19.4
# Conflicts: # api/src/main/java/me/shedaniel/rei/api/common/transfer/RecipeFinder.java # default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
Diffstat (limited to 'default-plugin')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/InventoryCraftingTransferHandler.java64
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java18
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java16
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java11
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java10
5 files changed, 103 insertions, 16 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/InventoryCraftingTransferHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/InventoryCraftingTransferHandler.java
new file mode 100644
index 000000000..d377c2add
--- /dev/null
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/InventoryCraftingTransferHandler.java
@@ -0,0 +1,64 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.plugin.autocrafting;
+
+import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
+import me.shedaniel.rei.api.client.registry.transfer.simple.SimpleTransferHandler;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.InputIngredient;
+import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
+import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay;
+import net.minecraft.network.chat.Component;
+
+import java.util.List;
+
+public class InventoryCraftingTransferHandler implements TransferHandler {
+ private final SimpleTransferHandler parent;
+
+ public InventoryCraftingTransferHandler(SimpleTransferHandler parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public ApplicabilityResult checkApplicable(Context context) {
+ ApplicabilityResult applicable = parent.checkApplicable(context);
+ if (!applicable.isApplicable()) return applicable;
+
+ DefaultCraftingDisplay<?> display = (DefaultCraftingDisplay<?>) context.getDisplay();
+ if (display != null && (display.getWidth() > 2 || display.getHeight() > 2)) {
+ return ApplicabilityResult.createApplicableWithError(Component.translatable("error.rei.transfer.too_small", 2, 2));
+ }
+
+ return applicable;
+ }
+
+ @Override
+ public Result handle(Context context) {
+ List<InputIngredient<EntryStack<?>>> inputs = ((DefaultCraftingDisplay<?>) context.getDisplay()).getInputIngredients(2, 2);
+ return parent.handleSimpleTransfer(context, parent.getMissingInputRenderer(),
+ CollectionUtils.map(inputs, entry -> InputIngredient.withType(entry, VanillaEntryTypes.ITEM)),
+ parent.getInputSlots(context), parent.getInventorySlots(context));
+ }
+}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
index d475a4b28..ff2b22547 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
@@ -27,6 +27,7 @@ import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay;
+import me.shedaniel.rei.api.common.transfer.info.MenuTransferException;
import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay;
import net.fabricmc.api.EnvType;
@@ -38,17 +39,26 @@ import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.RecipeBookMenu;
import net.minecraft.world.item.crafting.Recipe;
+import java.util.Optional;
+
@Environment(EnvType.CLIENT)
public class DefaultRecipeBookHandler implements TransferHandler {
@Override
- public Result handle(Context context) {
+ public ApplicabilityResult checkApplicable(Context context) {
if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets())
- return Result.createNotApplicable();
+ return ApplicabilityResult.createNotApplicable();
Display display = context.getDisplay();
if (!(context.getMenu() instanceof RecipeBookMenu<?> container))
- return Result.createNotApplicable();
+ return ApplicabilityResult.createNotApplicable();
if (container == null)
- return Result.createNotApplicable();
+ return ApplicabilityResult.createNotApplicable();
+ return ApplicabilityResult.createApplicable();
+ }
+
+ @Override
+ public Result handle(Context context) {
+ RecipeBookMenu<?> container = (RecipeBookMenu<?>) context.getMenu();
+ Display display = context.getDisplay();
if (display instanceof DefaultCraftingDisplay<?> craftingDisplay) {
if (craftingDisplay.getOptionalRecipe().isPresent()) {
int h = -1, w = -1;
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
index d1361c235..84be2cdb4 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
@@ -40,12 +40,14 @@ import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry;
+import me.shedaniel.rei.api.client.registry.transfer.simple.SimpleTransferHandler;
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.ClientInternals;
+import me.shedaniel.rei.plugin.autocrafting.InventoryCraftingTransferHandler;
import me.shedaniel.rei.plugin.autocrafting.recipebook.DefaultRecipeBookHandler;
import me.shedaniel.rei.plugin.client.categories.*;
import me.shedaniel.rei.plugin.client.categories.anvil.DefaultAnvilCategory;
@@ -59,6 +61,7 @@ import me.shedaniel.rei.plugin.client.exclusionzones.DefaultRecipeBookExclusionZ
import me.shedaniel.rei.plugin.client.favorites.GameModeFavoriteEntry;
import me.shedaniel.rei.plugin.client.favorites.TimeFavoriteEntry;
import me.shedaniel.rei.plugin.client.favorites.WeatherFavoriteEntry;
+import me.shedaniel.rei.plugin.common.BuiltinPlugin;
import me.shedaniel.rei.plugin.common.displays.*;
import me.shedaniel.rei.plugin.common.displays.anvil.AnvilRecipe;
import me.shedaniel.rei.plugin.common.displays.anvil.DefaultAnvilDisplay;
@@ -86,6 +89,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
+import net.minecraft.world.inventory.*;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
@@ -370,7 +374,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
protected void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) {
-
+
}
@Override
@@ -391,6 +395,16 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
@Override
public void registerTransferHandlers(TransferHandlerRegistry registry) {
+ registry.register(SimpleTransferHandler.create(CraftingMenu.class, BuiltinPlugin.CRAFTING,
+ new SimpleTransferHandler.IntRange(1, 10)));
+ registry.register(new InventoryCraftingTransferHandler(SimpleTransferHandler.create(InventoryMenu.class, BuiltinPlugin.CRAFTING,
+ new SimpleTransferHandler.IntRange(1, 5))));
+ registry.register(SimpleTransferHandler.create(FurnaceMenu.class, BuiltinPlugin.SMELTING,
+ new SimpleTransferHandler.IntRange(0, 1)));
+ registry.register(SimpleTransferHandler.create(SmokerMenu.class, BuiltinPlugin.SMOKING,
+ new SimpleTransferHandler.IntRange(0, 1)));
+ registry.register(SimpleTransferHandler.create(BlastFurnaceMenu.class, BuiltinPlugin.BLASTING,
+ new SimpleTransferHandler.IntRange(0, 1)));
registry.register(new DefaultRecipeBookHandler());
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
index c3465adff..e6a3e33ce 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
@@ -49,7 +49,7 @@ import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
-import net.minecraft.world.inventory.*;
+import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.*;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.ApiStatus;
@@ -124,15 +124,6 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin {
}
@Override
- public void registerMenuInfo(MenuInfoRegistry registry) {
- registry.register(BuiltinPlugin.CRAFTING, CraftingMenu.class, SimpleMenuInfoProvider.of(RecipeBookGridMenuInfo::new));
- registry.register(BuiltinPlugin.CRAFTING, InventoryMenu.class, SimpleMenuInfoProvider.of(RecipeBookGridMenuInfo::new));
- registry.register(BuiltinPlugin.SMELTING, FurnaceMenu.class, SimpleMenuInfoProvider.of(RecipeBookGridMenuInfo::new));
- registry.register(BuiltinPlugin.SMOKING, SmokerMenu.class, SimpleMenuInfoProvider.of(RecipeBookGridMenuInfo::new));
- registry.register(BuiltinPlugin.BLASTING, BlastFurnaceMenu.class, SimpleMenuInfoProvider.of(RecipeBookGridMenuInfo::new));
- }
-
- @Override
public double getPriority() {
return -100;
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
index 03243114a..a6bd71996 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
@@ -41,6 +41,7 @@ import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
@@ -191,6 +192,11 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD
return getInputIngredients(craftingWidth, craftingHeight);
}
+ @Override
+ public List<InputIngredient<EntryStack<?>>> getInputIngredients(@Nullable AbstractContainerMenu menu, @Nullable Player player) {
+ return getInputIngredients(3, 3);
+ }
+
public List<InputIngredient<EntryStack<?>>> getInputIngredients(int craftingWidth, int craftingHeight) {
int inputWidth = getInputWidth(craftingWidth, craftingHeight);
int inputHeight = getInputHeight(craftingWidth, craftingHeight);
@@ -204,7 +210,9 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD
continue;
}
int index = getSlotWithSize(inputWidth, i, craftingWidth);
- grid.put(new IntIntImmutablePair(i % inputWidth, i / inputWidth), InputIngredient.of(index, stacks));
+ int x = i % inputWidth;
+ int y = i / inputWidth;
+ grid.put(new IntIntImmutablePair(x, y), InputIngredient.of(index, 3 * y + x, stacks));
}
List<InputIngredient<EntryStack<?>>> list = new ArrayList<>(craftingWidth * craftingHeight);