diff --git a/src/main/java/com/cricketcraft/chisel/api/IChiselItem.java b/src/main/java/com/cricketcraft/chisel/api/IChiselItem.java index f198aeee..93b8725e 100644 --- a/src/main/java/com/cricketcraft/chisel/api/IChiselItem.java +++ b/src/main/java/com/cricketcraft/chisel/api/IChiselItem.java @@ -1,5 +1,6 @@ package com.cricketcraft.chisel.api; +import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -18,4 +19,22 @@ public interface IChiselItem extends IChiselMode { */ void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target); + /** + * Allows you to control if your item can chisel this block in the world. + * + * @param world + * World object + * @param x + * X coord of the block being chiseled + * @param y + * Y coord of the block being chiseled + * @param z + * Z coord of the block being chiseled + * @param block + * The {@link Block} being chiseled + * @param metadata + * The blocks' metadata + * @return True if the chiseling should take place. False otherwise. + */ + boolean canChiselBlock(World world, int x, int y, int z, Block block, int metadata); } diff --git a/src/main/java/com/cricketcraft/chisel/config/Configurations.java b/src/main/java/com/cricketcraft/chisel/config/Configurations.java index 25e3ecae..e132cbd1 100644 --- a/src/main/java/com/cricketcraft/chisel/config/Configurations.java +++ b/src/main/java/com/cricketcraft/chisel/config/Configurations.java @@ -37,7 +37,8 @@ public class Configurations { public static boolean allowChiselDamage; public static int ironChiselMaxDamage; public static int diamondChiselMaxDamage; - + public static boolean ironChiselCanLeftClick; + public static boolean refreshConfig() { String category; @@ -76,7 +77,8 @@ public class Configurations { allowChiselDamage = config.get(category, "allowChiselDamage", true, "Should the chisel be damageable and take damage when it chisels something.").getBoolean(); ironChiselMaxDamage = config.get(category, "ironChiselMaxDamage", 500, "The max damage of the standard iron chisel. Default: 500.").getInt(); diamondChiselMaxDamage = config.get(category, "diamondChiselMaxDamage", 5000, "The max damage of the diamond chisel. Default: 5000").getInt(); - + ironChiselCanLeftClick = config.get(category, "ironChiselCanLeftClick", false, "If this is true, the iron chisel can left click chisel blocks. If false, it cannot.").getBoolean(); + if (config.hasChanged()) { config.save(); } diff --git a/src/main/java/com/cricketcraft/chisel/init/Features.java b/src/main/java/com/cricketcraft/chisel/init/Features.java index 9bffdd18..36dc48ac 100644 --- a/src/main/java/com/cricketcraft/chisel/init/Features.java +++ b/src/main/java/com/cricketcraft/chisel/init/Features.java @@ -325,11 +325,11 @@ public enum Features { @Override void addRecipes() { if (Configurations.chiselRecipe) { - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel, 1), " YY", " YY", "X ", 'X', Items.stick, 'Y', Items.iron_ingot)); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel, 1, 1), " YY", " YY", "x ", 'x', "stickWood", 'Y', "ingotIron")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel), " YY", " YY", "X ", 'X', "stickWood", 'Y', "ingotIron")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.diamondChisel), " YY", " YY", "x ", 'x', "stickWood", 'Y', "gemDiamond")); } else { - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel, 1), " Y", "X ", 'X', Items.stick, 'Y', Items.iron_ingot)); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel, 1, 1), " y", "x ", 'x', "stickWood", 'y', "ingotIron")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.chisel), " Y", "X ", 'X', "stickWood", 'Y', "ingotIron")); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ChiselItems.diamondChisel), " Y", "X ", 'X', "stickWood", 'Y', "gemDiamond")); } } }, diff --git a/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java b/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java index 11e1ecb4..a96fa1f1 100644 --- a/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java +++ b/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java @@ -8,7 +8,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import org.apache.commons.lang3.ArrayUtils; @@ -41,10 +40,11 @@ public final class ChiselController { ItemStack held = event.entityPlayer.getCurrentEquippedItem(); int slot = event.entityPlayer.inventory.currentItem; - // TODO config for diamond only if (held == null || !(held.getItem() instanceof IChiselItem)) { return; } + + IChiselItem chisel = (IChiselItem) held.getItem(); switch (event.action) { case LEFT_CLICK_BLOCK: @@ -55,7 +55,7 @@ public final class ChiselController { int metadata = event.world.getBlockMetadata(x, y, z); CarvingVariation[] variations = Carving.chisel.getVariations(block, metadata); - if (variations != null) { + if (variations != null && chisel.canChiselBlock(event.world, x, y, z, block, metadata)) { ItemStack target = General.getChiselTarget(held); if (target != null) { @@ -84,9 +84,6 @@ public final class ChiselController { event.entityPlayer.openGui(Chisel.instance, 0, event.world, 0, 0, 0); break; } - if (event.action == Action.LEFT_CLICK_BLOCK) { - - } } /** diff --git a/src/main/java/com/cricketcraft/chisel/item/chisel/ItemChisel.java b/src/main/java/com/cricketcraft/chisel/item/chisel/ItemChisel.java index 177cb10b..d621390e 100644 --- a/src/main/java/com/cricketcraft/chisel/item/chisel/ItemChisel.java +++ b/src/main/java/com/cricketcraft/chisel/item/chisel/ItemChisel.java @@ -2,6 +2,7 @@ package com.cricketcraft.chisel.item.chisel; import java.util.List; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; @@ -60,10 +61,12 @@ public class ItemChisel extends Item implements IChiselItem { @Override public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean held) { String unloc = "item.chisel.chisel.desc."; // TODO this is hacky - for (int i = 0; i < 3; i ++) { - list.add(StatCollector.translateToLocal(unloc + i)); + for (int i = 0; i < 3; i++) { + if (i == 0 || type == ChiselType.DIAMOND || Configurations.ironChiselCanLeftClick) { + list.add(StatCollector.translateToLocal(unloc + i)); + } } - + if (type == ChiselType.DIAMOND) { list.add(""); list.add(StatCollector.translateToLocal(getUnlocalizedName(stack) + ".desc")); @@ -96,4 +99,9 @@ public class ItemChisel extends Item implements IChiselItem { } } } + + @Override + public boolean canChiselBlock(World world, int x, int y, int z, Block block, int metadata) { + return type == ChiselType.DIAMOND || Configurations.ironChiselCanLeftClick; + } } \ No newline at end of file