Jump to content

Recommended Posts

Posted

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.

Posted

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/

Posted

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.

 

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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