Jump to content

Recommended Posts

Posted

I am running Forge 1.5.1 and I would like that when you mine a certain ore and then you get the block in your inventory, you get damaged and if you keep it too long, you will die (just like hunger damage). Thanks!

Posted

You can't do it as a Block.  You'll need to have the ore block itself drop an Item version, which can damage the player.

 

The Item class has a function called...onUpdate that will let you do what you need to.

 

Here's an example:

 

public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
	double r = new Random().nextDouble();
	if(r < 0.005 * par1ItemStack.stackSize) {
		EntityPlayer p = (EntityPlayer)par3Entity;
		p.attackEntityFrom(DamageSource.generic, 1);
	}
}

 

I used a custom damage source ("cold") but I've replaced it above with Generic damage.  This code is great for stacking items, as the stack will only hurt you once.  What this does is increase the frequency that the player takes damage (rather than the amount) based on stack size.  Figure that that function is called 40 times a second when calculating how often you want the player to take damage (and there's a 1-2 second damage immunity effect after taking damage).  Which is why the random chance is so small (half a percent per item in the stack).

 

This code also means that roughly speaking, having 10 items in a stack is as bad for your health as 10 single items.

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.

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.