Posted March 13, 201411 yr Sorry, me again, is there any way of listening for right mouse button clicks on vanilla tools (specifically axes) that doesn't involve access modifiers or listening to every single right click then checking the tool in hand? I suppose, what I'm asking really, is this: Is there any way to have a function that only listens for rightclicks when a specific tool type is in hand at that moment? (background fluff: I'm hoping to make it possible to right click oak logs with any axe to strip the bark (cork) off. I don't want to add in another type of axe just for stripping bark) Cheers in advance. -Nick B (Minothor) https://lh6.googleusercontent.com/-z5frUimWWu0/U4Wuz9xle4I/AAAAAAAABsE/q3eMXJIDXIM/s800/EmeraldCasinoSig.png[/img]
March 13, 201411 yr Not really, but there is the PlayerInteractEvent which fires for LEFT_CLICK_BLOCK, RIGHT_CLICK_BLOCK, and RIGHT_CLICK_AIR. Use that to check (on right click block) if the held item is an axe and do your thing from there. http://i.imgur.com/NdrFdld.png[/img]
March 24, 201411 yr Author Ok, I've decided that the easiest way to support all axes and those from other mods would probably be to register them with the oreDict under "toolAxe". That said, I'm really struggling with the event handling, I've look up what documentation I can from the Wiki's reference, searching the forums and AtomicStryker's post here: http://www.minecraftforum.net/topic/1419836- ) Currently the only thing that Eclipse is being a bit iffy about is the @ForgeSubscribe annotation before the function. Can anyone shed any light on how and where I'm mucking up here please? Thanks in Advance, -Mino Event Handling class: package minothor.bab.events.EventHandlers; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.*; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.oredict.OreDictionary; public class CentEventHandler { public CentEventHandler(){ MinecraftForge.EVENT_BUS.register(this); } @ForgeSubscribe public void playerInteract(PlayerInteractEvent event) { Action eventAction = event.action; World currentWorld = event.entityPlayer.worldObj; Block blockAffected = currentWorld.getBlock(event.x, event.y, event.z); ItemStack currentTool = event.entityPlayer.getCurrentEquippedItem(); if(eventAction.RIGHT_CLICK_BLOCK != null){ System.out.println("Yes, You're Richtclicking"); if(currentWorld.getBlock(event.x, event.y, event.z) == Blocks.log){ System.out.println("a Log"); } if (OreDictionary.getOreName(OreDictionary.getOreID(currentTool)).equals("toolAxe")){ System.out.println("with an Axe!"); } } } } Main Class: package minothor.bab; import java.util.logging.Logger; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.event.ForgeEventFactory; import minothor.bab.proxy.*; import minothor.bab.items.*; import minothor.bab.blocks.*; import minothor.bab.events.EventHandlers.*; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid="BigAssBarrels", name="Big Ass Barrels", version="1.7.2 - Alpha 0.0.1") public class bab { public static final String modid = "BigAssBarrels"; public static final String name = "Bigass Barrels"; public static final String version = "1.7.2 - Alpha 0.0.1"; @Instance(value = "BigAssBarrels") public static bab instance; @SidedProxy(clientSide="minothor.bab.proxy.clientProxy", serverSide="minothor.bab.proxy.commonProxy") public static commonProxy proxy; //Declare Tab //Set Creative Tab Icon public static CreativeTabs tabBAB; //public static CreativeTabs tabBAB; //Declare Items public static Item itemBark; public static Item itemCork; //Declare Blocks public static Block blockCork; public static Block blockStrippedOak; //Declare Tools public static Item itemMallet; //Declare Event Handler used public static CentEventHandler CentralHandler; //public static logger; @EventHandler public void preInit(FMLPreInitializationEvent event) { Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); //config stuff here config.save(); tabBAB = new CreativeTabs("tabBAB"){ public Item getTabIconItem() { return itemCork; } }; itemBark = new Item().setUnlocalizedName("StrippedBark").setCreativeTab(tabBAB).setTextureName(modid + ":" + "StrippedBark"); GameRegistry.registerItem(itemBark, "StrippedBark"); itemCork= new Item().setUnlocalizedName("BottleCork").setCreativeTab(tabBAB).setTextureName(modid + ":" + "BottleCork"); GameRegistry.registerItem(itemCork, "BottleCork"); itemMallet = new itemMallet().setCreativeTab(tabBAB).setTextureName(modid + ":" + "WoodenMallet"); GameRegistry.registerItem(itemMallet, "WoodenMallet"); blockCork = new blockCork().setCreativeTab(tabBAB).setBlockTextureName(modid + ":" + "BlockCork"); GameRegistry.registerBlock(blockCork, "BlockCork"); blockStrippedOak = new blockStrippedOak().setCreativeTab(tabBAB); GameRegistry.registerBlock(blockStrippedOak, "BlockStrippedOak"); GameRegistry.addRecipe(new ItemStack(Item.getItemFromBlock(blockCork)), "XXX", "XYX", "XXX", 'X', new ItemStack(itemBark), 'Y', new ItemStack(itemCork)); GameRegistry.addRecipe(new ShapedOreRecipe( new ItemStack(itemMallet), "-X", "Y-", 'X', "logWood", 'Y', new ItemStack(Items.stick))); OreDictionary.registerOre("logWood", blockStrippedOak); GameRegistry.addRecipe(new ItemStack(Blocks.planks,4), "X", 'X', new ItemStack(Item.getItemFromBlock(blockStrippedOak))); GameRegistry.addRecipe(new ItemStack(itemCork), "X", "X", 'X', new ItemStack(itemBark)); //Creating toolAxe Oredictionary Section OreDictionary.registerOre("toolAxe", Items.wooden_axe); OreDictionary.registerOre("toolAxe", Items.stone_axe); OreDictionary.registerOre("toolAxe", Items.iron_axe); OreDictionary.registerOre("toolAxe", Items.golden_axe); OreDictionary.registerOre("toolAxe", Items.diamond_axe); //System.out.println(OreDictionary.getOres("toolAxe")); //Registering Events Handlers CentralHandler = new CentEventHandler(); } @EventHandler public void load(FMLInitializationEvent event) { proxy.registerRenderers(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { // Stub Method } } https://lh6.googleusercontent.com/-z5frUimWWu0/U4Wuz9xle4I/AAAAAAAABsE/q3eMXJIDXIM/s800/EmeraldCasinoSig.png[/img]
March 24, 201411 yr @ForgeSubscribe is for 1.6. @SubscribeEvent for 1.7. On 1.7, there are PlayerUseItemEvent events, and Item#getToolClasses(ItemStack).
March 25, 201411 yr Ok, I've decided that the easiest way to support all axes and those from other mods would probably be to register them with the oreDict under "toolAxe". Not at all. Why would any other mod register one of their axes in an "ore" dictionary? Answer: they won't. Use the instanceof ItemAxe or at least instanceof ItemTool (Here you would check the name for having 'axe' or 'hatchet' in it but not pickaxe) Any coder with any brains is likely not going to make an axe in some other class. The OreDictionary should be reserved for crafting. You should register crafting recipes in Init eventhandler not preinit. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.