Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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)

  • 2 weeks later...
  • 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
}


}

@ForgeSubscribe is for 1.6.

@SubscribeEvent for 1.7.

 

On 1.7, there are PlayerUseItemEvent events, and Item#getToolClasses(ItemStack).

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.

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.