Posted June 4, 201312 yr 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.
June 4, 201312 yr 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. github
June 4, 201312 yr 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?
June 4, 201312 yr Author Oops, I was thinking this was posted in another topic So, I add these files to both the block I want to change + the item I want to use to change to block?
June 5, 201312 yr Author not both, just one or the other Okay, that worked But, the item I right click doesn't go away when I right click it. I do want it to do that, how?
June 5, 201312 yr not both, just one or the other Okay, that worked 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.
June 5, 201312 yr Author not both, just one or the other Okay, that worked 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)
June 5, 201312 yr not both, just one or the other Okay, that worked 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.
June 5, 201312 yr Author not both, just one or the other Okay, that worked 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
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.