Jump to content

[1.7.2] Block drops item on right click - timed drop question


Thornack

Recommended Posts

I have made a block that upon right click drops an item. I wish to implement functionality so that the block can only drop the item once per

day.

 

in my block class that extends my custom block class which then extends Minecraft's Block class I wrote the code below to implement the item dropping when the block is right clicked.

 

It works as intended however I am now wishing to add a timed item drop aspect. I was thinking of somehow getting the world time at the time of the right click and equating it to a variable maybe called timeOfBlockClicked and having while or if statements that would forbid the item to drop if the block is right clicked until the World time was again greater than or equal to the timeOfBlockClicked at which point the timeOfBlockClicked variable would be reset to 0 and a new timeOfBlockClicked would be set again and a new item could drop. I am unsure how to get the world time though and how to save the time.

 

@Override
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
{
if(world.isRemote == false)//world.isRemote == false - has to be false otherwise you do it twice once for server and once for client
{
ItemStack myItemStack = new ItemStack(MyMod.customItem, 1);
EntityItem entityitem = new EntityItem(world, x, y, z, myItemStack);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
}
return false;
}
}

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.