Jump to content

[1.6.2] Need help with item doing damage to the player.


dncwalk99

Recommended Posts

I created an item with metadata for 2 states.  We'll call it "active" and "inactive".  The item is just an item, not a food, or a tool.  I need it so that when the item is used (read Left-Clicked) on a grass block, it changes from metadata 0 to 1, spawns lightning at the players position,kills the player, and shows a custom death message.

 

I've gotten the metadata to change by using this in the items class:

public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
{
	if(par1ItemStack.getItemDamage() == 0)
	{
		if(par2Block.blockID == 2)
		{
			this.setDamage(par1ItemStack, 1);

		}
		//ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode: Bingo!");
	}
 return 1.0F;
}

 

This does change the item from inactive to active when hitting a grass block.

 

That's is about all the success I've had with it.  I've gotten some of the other things to work, but none of them together.  I've even been trying things in my event handler.

 

Any help would be appreciated.

Link to comment
Share on other sites

At some point you're going to need this:

 

EntityLightningBolt entityLightningBolt = new EntityLightningBolt(world, ix, iy, iz);
world.addWeatherEffect(entityLightningBolt);

 

ix, iy, and iz is the block you want the lightning to hit.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

@ForgeSubscribe
public void onPlayerLeftClick(PlayerInteractEvent event){
    if(event.action==Action.LEFT_CLICK_BLOCK &&  event.entityPlayer.getHeldItem()!=null && event.player.getHeldItem().itemID==your_Item_ID && event.entityplayer.worldObj.getBlockId(event.x,event.y,event.z)==Block.grass.blockID){
    //do things
    }
}

Link to comment
Share on other sites

Yep. Figured it out late last night after asking for an example.  Here it is in case it helps anyone. You'll want to put this in your EventHandler class.

 

@ForgeSubscribe
public void onPlayerInteractEvent(PlayerInteractEvent event)
{
	ItemStack inHand = event.entityPlayer.getHeldItem();
	World world = MinecraftServer.getServer().worldServerForDimension(event.entityPlayer.dimension);

	if (inHand != null && inHand.getItem().itemID == GaiaMod.heartStoneItem.itemID)
	{
		if (inHand.getItemDamage() == 0)
		{
			if (event.action.LEFT_CLICK_BLOCK != null)
			{
				if (event.entityPlayer.worldObj.getBlockId(event.x, event.y, event.z) == Block.grass.blockID)
				{
					inHand.setItemDamage(1);

					EntityLightningBolt entityLightningBolt = new EntityLightningBolt(world, event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ);
					world.addWeatherEffect(entityLightningBolt);

					event.entityPlayer.setHealth(0);
					//event.entityPlayer.addChatMessage(par1Str);

					//ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode: Bingo!");
				}
			}
		}
	}

}

 

Thanks GotoLink.

Link to comment
Share on other sites

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.