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.

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

Featured Replies

Posted

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.

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.

  • Author

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?

  • Author

Oops, I was thinking this was posted in another topic :P

 

So, I add these files to both the block I want to change + the item I want to use to change to block?

  • Author

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?

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.

  • Author

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)

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.

  • Author

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

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.