Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

@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
    }
}

  • Author

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.