diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index 1d597b056..ef47b87d9 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -7,12 +7,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.minecraft.client.gui.screen.ingame.AnvilScreen; -import net.minecraft.client.gui.screen.ingame.CraftingScreen; -import net.minecraft.client.gui.screen.ingame.GrindstoneScreen; -import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.gui.screen.ingame.*; import net.minecraft.screen.ForgingScreenHandler; import net.minecraft.screen.GrindstoneScreenHandler; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.CraftingResultSlot; import fi.dy.masa.itemscroller.Reference; import fi.dy.masa.itemscroller.recipes.CraftingHandler; @@ -127,8 +125,10 @@ public static void loadFromFile() CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4)); // vanilla anvil CraftingHandler.addCraftingGridDefinition(AnvilScreen.class.getName(), ForgingScreenHandler.class.getName()+"$2", 2, new SlotRange(0, 2)); - // vanill grindstone + // vanilla grindstone CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), GrindstoneScreenHandler.class.getName()+"$4", 2, new SlotRange(0, 2)); + // vanilla stonecutter + CraftingHandler.addCraftingGridDefinition(StonecutterScreen.class.getName(), StonecutterScreenHandler.class.getName()+"$2", 1, new SlotRange(0, 1)); } public static void saveToFile() diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 39390fc05..85d5c218b 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -4,7 +4,10 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.gui.screen.ingame.StonecutterScreen; import net.minecraft.recipe.CraftingRecipe; +import net.minecraft.recipe.StonecuttingRecipe; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.Slot; import fi.dy.masa.itemscroller.ItemScroller; import fi.dy.masa.itemscroller.config.Configs; @@ -187,21 +190,29 @@ public void onClientTick(MinecraftClient mc) RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); - if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible + int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); + if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); int option = InventoryUtils.checkRecipeEnough(recipe, gui); if(option > 0) { mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); } - } else { - // System.out.println("move"); + } + else { InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); + if(stonecuttingRecipeIndex != -1 && gui instanceof StonecutterScreen) { + mc.interactionManager.clickButton((gui.getScreenHandler()).syncId, stonecuttingRecipeIndex); + } } -// for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { -// InventoryUtils.dropStack(gui, outputSlot.id); -// } - InventoryUtils.dropItem(gui, outputSlot.id); + if(recipe.getResult().isStackable()) { + for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { + InventoryUtils.dropStack(gui, outputSlot.id); + } + } + else { + InventoryUtils.dropItem(gui, outputSlot.id); + } InventoryUtils.tryClearCursor(gui); InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); diff --git a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java index 4a155c93a..b6a84abbc 100644 --- a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java +++ b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; import net.minecraft.recipe.CraftingRecipe; +import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange; @@ -20,6 +21,8 @@ public class RecipePattern private ItemStack result = InventoryUtils.EMPTY_STACK; private ItemStack[] recipe = new ItemStack[9]; public CraftingRecipe cachedRecipeFromBook = null; + + public int cachedRecipeFromStonecutting = -1; private int maxCraftAmount = 64; private HashSet recipeRemainders = new HashSet(); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 36331fcd2..508d37762 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -27,19 +27,19 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.recipe.RecipeType; -import net.minecraft.screen.AnvilScreenHandler; +import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.screen.Generic3x3ContainerScreenHandler; import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.CraftingResultSlot; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.screen.slot.TradeOutputSlot; @@ -47,9 +47,6 @@ import net.minecraft.util.registry.Registry; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOfferList; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import fi.dy.masa.itemscroller.mixin.IMixinCraftingResultSlot; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparator; import org.apache.commons.lang3.StringUtils; @@ -1342,6 +1339,32 @@ public static CraftingRecipe getBookRecipeFromPattern(RecipePattern recipe) { return null; } + public static int getStonecuttingRecipeFromPattern(RecipePattern recipe) { + if(recipe.cachedRecipeFromStonecutting != -1) { + return recipe.cachedRecipeFromStonecutting; + } + else { + MinecraftClient mc = MinecraftClient.getInstance(); + RecipeManager recipeManager = mc.world.getRecipeManager(); + + ItemStack[] items = recipe.getRecipeItems(); + SimpleInventory search = new SimpleInventory(items.length); + // Set dummy slots with recipe pattern + for (int i = 0; i < items.length; i++) { + search.setStack(i, items[i]); + } + List inputRecipes = recipeManager.getAllMatches(RecipeType.STONECUTTING, search, mc.world); + for(int i=0; i gui) { Slot slot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui);