MINERGUY67880 Posted August 19, 2015 Posted August 19, 2015 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: Reveal hidden contents 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. Quote
jabelar Posted August 19, 2015 Posted August 19, 2015 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? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
MINERGUY67880 Posted August 19, 2015 Author Posted August 19, 2015 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. Quote
delpi Posted August 19, 2015 Posted August 19, 2015 you are comparing itemstacks. don't do that. compare items. Quote Long time Bukkit & Forge Programmer Happy to try and help
MINERGUY67880 Posted August 19, 2015 Author Posted August 19, 2015 How do I do that? event.entityPlayer.getHeldItem() returns an itemstack. Quote
jabelar Posted August 19, 2015 Posted August 19, 2015 On 8/19/2015 at 5:35 AM, MINERGUY67880 said: How do I do that? event.entityPlayer.getHeldItem() returns an itemstack. Right. And item stacks have methods, including one called getItem(). Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
MINERGUY67880 Posted August 19, 2015 Author Posted August 19, 2015 Thank you so much! Im such an idiot Quote
Recommended Posts
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.