diff --git a/src/main/java/team/chisel/item/chisel/ChiselController.java b/src/main/java/team/chisel/item/chisel/ChiselController.java index f094f902..2486d006 100644 --- a/src/main/java/team/chisel/item/chisel/ChiselController.java +++ b/src/main/java/team/chisel/item/chisel/ChiselController.java @@ -30,7 +30,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; public final class ChiselController { - private static class GuiOpen implements Runnable { + protected static class GuiOpen implements Runnable { private EntityPlayer player; private ItemStack stack; @@ -54,8 +54,7 @@ public final class ChiselController { public static final ChiselController INSTANCE = new ChiselController(); - private long lastTickClick = 0; - private Queue openQueue = Queues.newArrayDeque(); + Queue openQueue = Queues.newArrayDeque(); private ChiselController() {} @@ -80,78 +79,65 @@ public final class ChiselController { IChiselItem chisel = (IChiselItem) held.getItem(); - switch (event.action) { - case LEFT_CLICK_BLOCK: - boolean shifting = event.entityPlayer.isSneaking(); - int x = event.x, y = event.y, z = event.z; - Block block = event.world.getBlock(x, y, z); - int metadata = event.world.getBlockMetadata(x, y, z); - ICarvingGroup group = Carving.chisel.getGroup(block, metadata); + if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) { + boolean shifting = event.entityPlayer.isSneaking(); + int x = event.x, y = event.y, z = event.z; + Block block = event.world.getBlock(x, y, z); + int metadata = event.world.getBlockMetadata(x, y, z); + ICarvingGroup group = Carving.chisel.getGroup(block, metadata); - if (group == null) { - return; - } + if (group == null) { + return; + } - TileEntity te = event.world.getTileEntity(x, y, z); - if (te != null) { - // Don't support chiseling tile entities - return; - } + TileEntity te = event.world.getTileEntity(x, y, z); + if (te != null) { + // Don't support chiseling tile entities + return; + } - List list = group.getVariations(); + List list = group.getVariations(); - main: for (ItemStack stack : OreDictionary.getOres(group.getOreName())) { - ICarvingVariation v = General.getVariation(stack); - for (ICarvingVariation check : list) { - if (check.getBlock() == v.getBlock() && check.getBlockMeta() == v.getBlockMeta()) { - continue main; - } - } - list.add(General.getVariation(stack)); - } - - ICarvingVariation[] variations = list.toArray(new ICarvingVariation[] {}); - - if (chisel.canChiselBlock(event.world, event.entityPlayer, x, y, z, block, metadata)) { - ItemStack target = General.getChiselTarget(held); - IChiselMode mode = General.getChiselMode(held); - ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face]; - - if (target != null) { - for (ICarvingVariation v : variations) { - if (v.getBlock() == Block.getBlockFromItem(target.getItem()) - && v.getBlockMeta() == target.getItemDamage()) { - mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, v); - } - } - } else { - int idx = 0; - for (int i = 0; i < variations.length; i++) { - ICarvingVariation v = variations[i]; - if (v.getBlock() == block && v.getBlockMeta() == metadata) { - idx = i + variations.length + (shifting ? -1 : 1); - idx %= variations.length; - } - } - - ICarvingVariation newVar = variations[idx]; - mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, newVar); - event.entityPlayer.inventory.currentItem = slot; + main: + for (ItemStack stack : OreDictionary.getOres(group.getOreName())) { + ICarvingVariation v = General.getVariation(stack); + for (ICarvingVariation check : list) { + if (check.getBlock() == v.getBlock() && check.getBlockMeta() == v.getBlockMeta()) { + continue main; } } - break; - case RIGHT_CLICK_AIR: - case RIGHT_CLICK_BLOCK: - // Make sure we have not responded this tick - if (event.world.getTotalWorldTime() == lastTickClick) { - break; + list.add(General.getVariation(stack)); + } + + ICarvingVariation[] variations = list.toArray(new ICarvingVariation[] {}); + + if (chisel.canChiselBlock(event.world, event.entityPlayer, x, y, z, block, metadata)) { + ItemStack target = General.getChiselTarget(held); + IChiselMode mode = General.getChiselMode(held); + ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face]; + + if (target != null) { + for (ICarvingVariation v : variations) { + if (v.getBlock() == Block.getBlockFromItem(target.getItem()) + && v.getBlockMeta() == target.getItemDamage()) { + mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, v); + } + } } else { - lastTickClick = event.world.getTotalWorldTime(); + int idx = 0; + for (int i = 0; i < variations.length; i++) { + ICarvingVariation v = variations[i]; + if (v.getBlock() == block && v.getBlockMeta() == metadata) { + idx = i + variations.length + (shifting ? -1 : 1); + idx %= variations.length; + } + } + + ICarvingVariation newVar = variations[idx]; + mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, newVar); + event.entityPlayer.inventory.currentItem = slot; } - if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held)) { - openQueue.add(new GuiOpen(event.entityPlayer, held)); - } - break; + } } } diff --git a/src/main/java/team/chisel/item/chisel/ItemChisel.java b/src/main/java/team/chisel/item/chisel/ItemChisel.java index 4beb7264..42c5063f 100644 --- a/src/main/java/team/chisel/item/chisel/ItemChisel.java +++ b/src/main/java/team/chisel/item/chisel/ItemChisel.java @@ -159,4 +159,12 @@ public class ItemChisel extends Item implements IChiselItem { || type == ChiselType.NETHERSTAR || Configurations.ironChiselHasModes; } + + @Override + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { + if (!world.isRemote && canOpenGui(world, player, itemStack)) { + ChiselController.INSTANCE.openQueue.add(new ChiselController.GuiOpen(player, itemStack)); + } + return itemStack; + } }