Hey guys,
I am trying to make an event as a test to see if I am properly firing events. I am new to forge so it is throwing me off a little.
I am not sure if I am just using the wrong event (playerinteractevent) and I should use a different one, or I just didn't do something in initializing my event or whatever it would be. If someone could help, that'd be great.
CommonProxy class(I link it with my main, so the info is in proxies but is called by the main):
package me.redstery11.dm.proxy;
import me.redstery11.dm.Events;
import me.redstery11.dm.Recipies;
import me.redstery11.dm._Items;
import me.redstery11.dm.theItems.Phone;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
public class CommonProxy {
Events handler = new Events();
@EventHandler
public void preInit(FMLPreInitializationEvent e)
{
MinecraftForge.EVENT_BUS.register(handler);
_Items.preinit();
}
@EventHandler
public void Init(FMLInitializationEvent e)
{
Recipies.init();
MinecraftForge.EVENT_BUS.register(new Phone());
}
@EventHandler
public void postInit(FMLPostInitializationEvent e){
}
}
The events class:
The first problem I came up with was that an Itemstack cannot be compared to an item, so I went around it, but I am not sure if that worked.
package me.redstery11.dm;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class Events {
@SubscribeEvent
public void onRightClick(PlayerInteractEvent e)
{
EntityPlayer p = e.getEntityPlayer();
if(p.inventory.getCurrentItem() != null)
{
if(p.inventory.getCurrentItem() == new ItemStack(_Items.cell_phone))
{
p.setFire(5);
}
}
}
}