From b866becfb620c02a74fb990915001e154b5d2b0b Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 2 Aug 2021 19:54:29 +0800 Subject: Welcome, Forge 1.17 --- .../autocrafting/DefaultRecipeBookHandler.java | 99 ---------------------- .../recipebook/DefaultRecipeBookHandler.java | 99 ++++++++++++++++++++++ .../rei/plugin/client/DefaultClientPlugin.java | 2 +- 3 files changed, 100 insertions(+), 100 deletions(-) delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java (limited to 'default-plugin/src') diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java deleted file mode 100644 index 6406429d1..000000000 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021 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.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.plugin.common.displays.cooking.DefaultCookingDisplay; -import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.world.inventory.CraftingMenu; -import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.inventory.RecipeBookMenu; -import net.minecraft.world.item.crafting.Recipe; - -@Environment(EnvType.CLIENT) -public class DefaultRecipeBookHandler implements TransferHandler { - @Override - public Result handle(Context context) { - if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets()) - return Result.createNotApplicable(); - Display display = context.getDisplay(); - if (!(context.getMenu() instanceof RecipeBookMenu container)) - return Result.createNotApplicable(); - if (container == null) - return Result.createNotApplicable(); - if (display instanceof DefaultCraftingDisplay craftingDisplay) { - if (craftingDisplay.getOptionalRecipe().isPresent()) { - int h = -1, w = -1; - if (container instanceof CraftingMenu) { - h = 3; - w = 3; - } else if (container instanceof InventoryMenu) { - h = 2; - w = 2; - } - if (h == -1 || w == -1) - return Result.createNotApplicable(); - Recipe recipe = craftingDisplay.getOptionalRecipe().get(); - if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w) - return Result.createFailed(new TranslatableComponent("error.rei.transfer.too_small", h, w)); - if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) - return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); - if (!context.isActuallyCrafting()) - return Result.createSuccessful(); - context.getMinecraft().setScreen(context.getContainerScreen()); - if (context.getContainerScreen() instanceof RecipeUpdateListener) - ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); - context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); - return Result.createSuccessful(); - } - } else if (display instanceof DefaultCookingDisplay defaultDisplay) { - if (defaultDisplay.getOptionalRecipe().isPresent()) { - Recipe recipe = (defaultDisplay).getOptionalRecipe().get(); - if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) - return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); - if (!context.isActuallyCrafting()) - return Result.createSuccessful(); - context.getMinecraft().setScreen(context.getContainerScreen()); - if (context.getContainerScreen() instanceof RecipeUpdateListener) - ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); - context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); - return Result.createSuccessful(); - } - } - return Result.createNotApplicable(); - } - - @Override - public double getPriority() { - return -20; - } -} 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 new file mode 100644 index 000000000..9de8162ae --- /dev/null +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java @@ -0,0 +1,99 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.recipebook; + +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.plugin.common.displays.cooking.DefaultCookingDisplay; +import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.inventory.CraftingMenu; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.RecipeBookMenu; +import net.minecraft.world.item.crafting.Recipe; + +@Environment(EnvType.CLIENT) +public class DefaultRecipeBookHandler implements TransferHandler { + @Override + public Result handle(Context context) { + if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets()) + return Result.createNotApplicable(); + Display display = context.getDisplay(); + if (!(context.getMenu() instanceof RecipeBookMenu container)) + return Result.createNotApplicable(); + if (container == null) + return Result.createNotApplicable(); + if (display instanceof DefaultCraftingDisplay craftingDisplay) { + if (craftingDisplay.getOptionalRecipe().isPresent()) { + int h = -1, w = -1; + if (container instanceof CraftingMenu) { + h = 3; + w = 3; + } else if (container instanceof InventoryMenu) { + h = 2; + w = 2; + } + if (h == -1 || w == -1) + return Result.createNotApplicable(); + Recipe recipe = craftingDisplay.getOptionalRecipe().get(); + if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w) + return Result.createFailed(new TranslatableComponent("error.rei.transfer.too_small", h, w)); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().setScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeUpdateListener) + ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); + context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } else if (display instanceof DefaultCookingDisplay defaultDisplay) { + if (defaultDisplay.getOptionalRecipe().isPresent()) { + Recipe recipe = (defaultDisplay).getOptionalRecipe().get(); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().setScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeUpdateListener) + ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); + context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } + return Result.createNotApplicable(); + } + + @Override + public double getPriority() { + return -20; + } +} 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 ae38726c3..2bb9c0925 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 @@ -48,7 +48,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; 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.DefaultRecipeBookHandler; +import me.shedaniel.rei.plugin.autocrafting.recipebook.DefaultRecipeBookHandler; import me.shedaniel.rei.plugin.client.categories.*; import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconBaseCategory; import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconPaymentCategory; -- cgit