Jump to content

[SOLVED] How do I make one block turn into another on a right click with a item?


Nieue

Recommended Posts

Hello, as you can see in the title I want to know how to change one block turn into another block by right clicking it with an item.

Also, it would be changing one custom furnace into another, maybe this changes how it works maybe not, but that's what I want to know.

Link to comment
Share on other sites

if you want to do this with the item you can do

@Override
public boolean onItemUse(ItemStack par1ItemStack,
	EntityPlayer par2EntityPlayer, World par3World, int par4, int par5,
	int par6, int par7, float par8, float par9, float par10)
{
	if(!par3World.isRemote && par1World.getBlockID(par4, par5, par6) == myBlock.blockID)
	{
		par3World.setBlock(par4, par5, par6, myOtherBlock.blockID);
	}

	return super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5,
		par6, par7, par8, par9, par10);
}

 

if you want this in the block, similarly you can do:

@Override
public boolean onBlockActivated(World par1World, int par2, int par3,
	int par4, EntityPlayer par5EntityPlayer, int par6, float par7,
	float par8, float par9)
{

	if(par5EntityPlayer.getHeldItem().itemID == myItem.itemID)
	{
		par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.
		if(par1World.isRemote)
		{
			par1World.setBlock(par2, par3, par4, myBlock.blockID);
		}
	}
	return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer,
		par6, par7, par8, par9);
}

 

 

EDIT:

This could cause some funky stuff with containers so make sure you think of a way to handle the inventory when you do this, Not going to do that for you, as it would take me too long and I've got stuff to do for my mod.

Link to comment
Share on other sites

if you want to do this with the item you can do

@Override
public boolean onItemUse(ItemStack par1ItemStack,
	EntityPlayer par2EntityPlayer, World par3World, int par4, int par5,
	int par6, int par7, float par8, float par9, float par10)
{
	if(!par3World.isRemote && par1World.getBlockID(par4, par5, par6) == myBlock.blockID)
	{
		par3World.setBlock(par4, par5, par6, myOtherBlock.blockID);
	}

	return super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5,
		par6, par7, par8, par9, par10);
}

 

if you want this in the block, similarly you can do:

@Override
public boolean onBlockActivated(World par1World, int par2, int par3,
	int par4, EntityPlayer par5EntityPlayer, int par6, float par7,
	float par8, float par9)
{

	if(par5EntityPlayer.getHeldItem().itemID == myItem.itemID)
	{
		par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.
		if(par1World.isRemote)
		{
			par1World.setBlock(par2, par3, par4, myBlock.blockID);
		}
	}
	return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer,
		par6, par7, par8, par9);
}

 

 

EDIT:

This could cause some funky stuff with containers so make sure you think of a way to handle the inventory when you do this, Not going to do that for you, as it would take me too long and I've got stuff to do for my mod.

Okay, so I add this to my item class that I want to drop?

Link to comment
Share on other sites

not both, just one or the other

Okay, that worked :D But, the item I right click doesn't go away when I right click it. I do want it to do that, how?

If you put the code in the block, use the line Yagoki put in there:

par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.

If you put it in the item, you should be able to use the same code.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

not both, just one or the other

Okay, that worked :D But, the item I right click doesn't go away when I right click it. I do want it to do that, how?

If you put the code in the block, use the line Yagoki put in there:

par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.

If you put it in the item, you should be able to use the same code.

So where should I put this in the code? (I'm using it on an item)

Link to comment
Share on other sites

not both, just one or the other

Okay, that worked :D But, the item I right click doesn't go away when I right click it. I do want it to do that, how?

If you put the code in the block, use the line Yagoki put in there:

par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.

If you put it in the item, you should be able to use the same code.

So where should I put this in the code? (I'm using it on an item)

Right after World.setBlock

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

not both, just one or the other

Okay, that worked :D But, the item I right click doesn't go away when I right click it. I do want it to do that, how?

If you put the code in the block, use the line Yagoki put in there:

par5EntityPlayer.getHeldItem().stackSize -= 1; //only if you want to use the item when you do this.

If you put it in the item, you should be able to use the same code.

So where should I put this in the code? (I'm using it on an item)

Right after World.setBlock

Thanks! It worked :D

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.