From b33a6be9cba586d40cc4ccb0a08b249c8c3dadf2 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 19 Sep 2016 01:58:41 -0400 Subject: [PATCH] Use recipe handler for templates to prevent sealed drawers from being used. --- build.gradle | 2 +- .../storagedrawers/core/ModRecipes.java | 10 ++- .../core/recipe/TemplateRecipe.java | 62 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/core/recipe/TemplateRecipe.java diff --git a/build.gradle b/build.gradle index 350b5f1..819a942 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.10.2" +version = "1.7.10-1.10.3" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java b/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java index 1d6ec16..3f2e0a1 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java @@ -4,12 +4,14 @@ import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers; import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; import com.jaquadro.minecraft.storagedrawers.core.recipe.FallbackShapedOreRecipe; +import com.jaquadro.minecraft.storagedrawers.core.recipe.TemplateRecipe; import cpw.mods.fml.common.registry.GameRegistry; import minetweaker.mc1710.recipes.ShapedRecipeOre; import net.minecraft.block.BlockWood; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.ShapedOreRecipe; @@ -79,8 +81,8 @@ public class ModRecipes GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.controllerSlave), "xxx", "yzy", "xwx", 'x', new ItemStack(Blocks.stone), 'y', Items.comparator, 'z', "drawerBasic", 'w', "ingotGold")); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgradeTemplate, 2), "xxx", "xyx", "xxx", - 'x', "stickWood", 'y', "drawerBasic")); + //GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgradeTemplate, 2), "xxx", "xyx", "xxx", + // 'x', "stickWood", 'y', "drawerBasic")); if (config.cache.enableStorageUpgrades) { GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgrade, 1, 2), "xyx", "yzy", "xyx", @@ -157,5 +159,9 @@ public class ModRecipes GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.trimCustom, config.getBlockRecipeOutput("trim"), 0), "yxy", "xyx", "yxy", 'x', "stickWood", 'y', "plankWood")); } + + RecipeSorter.register("StorageDrawers:UpgradeTemplate", TemplateRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped"); + + CraftingManager.getInstance().getRecipeList().add(new TemplateRecipe()); } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/recipe/TemplateRecipe.java b/src/com/jaquadro/minecraft/storagedrawers/core/recipe/TemplateRecipe.java new file mode 100644 index 0000000..1c284b9 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/core/recipe/TemplateRecipe.java @@ -0,0 +1,62 @@ +package com.jaquadro.minecraft.storagedrawers.core.recipe; + +import com.jaquadro.minecraft.storagedrawers.core.ModItems; +import com.jaquadro.minecraft.storagedrawers.item.ItemDrawers; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.List; + +public class TemplateRecipe implements IRecipe +{ + @Override + public boolean matches (InventoryCrafting inventory, World world) { + return getCraftingResult(inventory) != null; + } + + @Override + public ItemStack getCraftingResult (InventoryCrafting inventory) { + List sticks = OreDictionary.getOres("stickWood"); + for (int row = 0; row < 3; row++) { + for (int col = 0; col < 3; col++) { + if (row == 1 && col == 1) + continue; + + ItemStack stack = inventory.getStackInRowAndColumn(col, row); + if (stack == null) + return null; + + boolean match = false; + for (ItemStack comp : sticks) { + if (comp != null && comp.isItemEqual(stack)) + match = true; + } + + if (!match) + return null; + } + } + + ItemStack center = inventory.getStackInRowAndColumn(1, 1); + if (center == null || !(center.getItem() instanceof ItemDrawers)) + return null; + + if (center.getTagCompound() != null && center.getTagCompound().hasKey("tile")) + return null; + + return getRecipeOutput(); + } + + @Override + public int getRecipeSize () { + return 9; + } + + @Override + public ItemStack getRecipeOutput () { + return new ItemStack(ModItems.upgradeTemplate, 2); + } +}