Posted August 19, 201510 yr So, I'm trying to make a debug item that tells you information about the block you right click with it. I check if the player right clicks a block, then I check if the player is holding the debug item. It is supposed to say the unlocalized name of the item that I right click with the item in chat but it doesn't. My event handler: package com.miner.core; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; public class MinerEventHandler { @SubscribeEvent public void interactEvent(PlayerInteractEvent event) { if(event.action != null && event.action == Action.RIGHT_CLICK_BLOCK){ int x = event.x; int y = event.y; int z = event.z; if(event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem() == new ItemStack(MinerCore.debugItem)) { ChatHandler.sendChat(event.world.getBlock(x, y, z).getUnlocalizedName()); } } } } ChatHandler is a class I made just to make adding chat easier. The event handler is registered too.
August 19, 201510 yr Are you sure you registered it on the right bus? Can you post your registration code? Also, to eliminate the possibility that it is an issue with your chat handler, can you put in a console statement (with System.out.println) in the beginning of the event handling method to confirm that the event is firing? Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 19, 201510 yr Author FMLCommonHandler.instance().bus().register(eventHandler); MinecraftForge.EVENT_BUS.register(eventHandler); That is in pre init. Also, I just did the println test and the event fires but it only works under if(event.action != null && event.action == Action.RIGHT_CLICK_BLOCK) if(event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem() == new ItemStack(MinerCore.debugItem)) doesn't work though.
August 19, 201510 yr you are comparing itemstacks. don't do that. compare items. Long time Bukkit & Forge Programmer Happy to try and help
August 19, 201510 yr How do I do that? event.entityPlayer.getHeldItem() returns an itemstack. Right. And item stacks have methods, including one called getItem(). Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.