Jump to content

Changing a metadata block to another metadata block when right clicking.


Recommended Posts

Posted

Ok, so I have the code set up and I figured out one of the things which is how to make a block turn into a metadata block; But what I need is to make a metadata block turn into another metadata block

 

public boolean onItemUse( ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
    {
            if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6))
            {
                    return false;
            }

            int i = par3World.getBlockId(par4, par5, par6);

            if (par5 != 0 && i == BlockThatGetsChangedIntoTheBlockBelowAndThatNeedsToHaveADamageValue.blockID)
            {
                    Block block = BlockThatGetsPutInWorldWhenYouRightClickBlockAboveThisOneAlreadyHasMetadata;

                    par3World.playSoundEffect((float)par4 + 0.5F, (float)par5 + 0.5F, (float)par6 + 0.5F, block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);

                    if (par3World.isRemote)
                    {
                            return true;
                    }
                    else
                    {
                            par3World.setBlockAndMetadataWithNotify(par4, par5, par6, block.blockID, 5); <The int at the end of this is the damage value
                            par1ItemStack.damageItem(1, par2EntityPlayer);
                            return true;
                    }

 

So basically I need the block: BlockThatGetsChangedIntoTheBlockBelowAndThatNeedsToBeAMetadataBlock.blockID to be able to have a damage value!

 

Thanks for reading, please help! :D

Posted
  On 7/19/2012 at 6:03 PM, DarkGuardsman said:

just get the blocks location and use code too place a new block with a different value in that spot.

par3World.setBlockWithNotify(x, y, z, BlockID)

there is a meta data version of the above but i don't have time to find it sorry.

 

I have already tried setBlockAndMetadataWithNotify it doesnt work, and I cant put it a damage value... :|

Posted

ItemStack item = par5EntityPlayer.getCurrentEquippedItem();
    	int a = world.getBlockMetadata(x, y, z);
    	
    	if(item!=null){
    		int itemID = item.itemID;
    			if(itemID == Item.bucketWater.shiftedIndex){
        	
    				if(a < 4){
    					
    					world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a+1);
    					par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
    					return true;
    					
    				}
        	
    			}else if(itemID == Item.bucketEmpty.shiftedIndex){
    	        	
    	    		if(a > 0){
    	    					
    	    			world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a-1);
    	    			par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketWater));
    	    			return true;
    	    					
    	    		}
    	        	
    	    	}
    			
    	}
        return false;

 

works for me. i have been messing around with the code for the past few days, trying to recreate a storage tank similar to buildcrafts without looking at their code. having problems with filling it with actual water though (about to post a thread for help)

Posted
  On 7/19/2012 at 8:55 PM, Cutter said:

ItemStack item = par5EntityPlayer.getCurrentEquippedItem();
    	int a = world.getBlockMetadata(x, y, z);
    	
    	if(item!=null){
    		int itemID = item.itemID;
    			if(itemID == Item.bucketWater.shiftedIndex){
        	
    				if(a < 4){
    					
    					world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a+1);
    					par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
    					return true;
    					
    				}
        	
    			}else if(itemID == Item.bucketEmpty.shiftedIndex){
    	        	
    	    		if(a > 0){
    	    					
    	    			world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a-1);
    	    			par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketWater));
    	    			return true;
    	    					
    	    		}
    	        	
    	    	}
    			
    	}
        return false;

 

works for me. i have been messing around with the code for the past few days, trying to recreate a storage tank similar to buildcrafts without looking at their code. having problems with filling it with actual water though (about to post a thread for help)

 

Im trying to make a metadata block into another metadata block by right clicking said block with an item.

I already got the block that it turns into working with metadata but not the one you click. I dont know how to add in a damage value to the block that you right click to make into the second block. SetBlockMetadataWithNotify only works on the block that it turns into not the actual block you click. Thank you!

Posted
  On 7/19/2012 at 10:10 PM, Thor597 said:

  Quote

ItemStack item = par5EntityPlayer.getCurrentEquippedItem();
    	int a = world.getBlockMetadata(x, y, z);
    	
    	if(item!=null){
    		int itemID = item.itemID;
    			if(itemID == Item.bucketWater.shiftedIndex){
        	
    				if(a < 4){
    					
    					world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a+1);
    					par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
    					return true;
    					
    				}
        	
    			}else if(itemID == Item.bucketEmpty.shiftedIndex){
    	        	
    	    		if(a > 0){
    	    					
    	    			world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a-1);
    	    			par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketWater));
    	    			return true;
    	    					
    	    		}
    	        	
    	    	}
    			
    	}
        return false;

 

works for me. i have been messing around with the code for the past few days, trying to recreate a storage tank similar to buildcrafts without looking at their code. having problems with filling it with actual water though (about to post a thread for help)

 

Im trying to make a metadata block into another metadata block by right clicking said block with an item.

I already got the block that it turns into working with metadata but not the one you click. I dont know how to add in a damage value to the block that you right click to make into the second block. SetBlockMetadataWithNotify only works on the block that it turns into not the actual block you click. Thank you! BTW there should've been a getBlockIdAndMetadata...

Posted
  On 7/19/2012 at 10:11 PM, Thor597 said:

  Quote

  Quote

ItemStack item = par5EntityPlayer.getCurrentEquippedItem();
    	[b]int a = world.getBlockMetadata(x, y, z);[/b]
    	
    	if(item!=null){
    		int itemID = item.itemID;
    			if(itemID == Item.bucketWater.shiftedIndex){
        	
    				if(a < 4){
    					
    					[b]world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a+1);[/b]
    					par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
    					return true;
    					
    				}
        	
    			}else if(itemID == Item.bucketEmpty.shiftedIndex){
    	        	
    	    		if(a > 0){
    	    					
    	    			world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a-1);
    	    			par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketWater));
    	    			return true;
    	    					
    	    		}
    	        	
    	    	}
    			
    	}
        return false;

 

works for me. i have been messing around with the code for the past few days, trying to recreate a storage tank similar to buildcrafts without looking at their code. having problems with filling it with actual water though (about to post a thread for help)

 

Im trying to make a metadata block into another metadata block by right clicking said block with an item.

I already got the block that it turns into working with metadata but not the one you click. I dont know how to add in a damage value to the block that you right click to make into the second block. SetBlockMetadataWithNotify only works on the block that it turns into not the actual block you click. Thank you! BTW there should've been a getBlockIdAndMetadata...

"BTW there should've been a getBlockIdAndMetadata..." = int a = world.getBlockMetadata(x, y, z);

 

"Im trying to make a metadata block into another metadata block by right clicking said block with an item." = world.setBlockAndMetadataWithNotify(x, y, z, mod_cutter.storageTank.blockID, a+1);

 

the "a+1" part changes the current blocks metadata to 1 higher, which is exactly what your looking for. unless the problem is different to what you described.

Posted
  On 7/20/2012 at 12:17 AM, Thor597 said:

No, my problem wasnt changing 1 damage value up, it was to change 1 metadata block into one completely other one, EG from birch wood planks to magenta wool.

just use world.setBlock(x,y,z,blockID); then.

Posted
  On 7/20/2012 at 12:27 AM, Thor597 said:

Taking my previous example, how would i then specify that the planks im right clicking are birch planks and not any of the other planks?

world.setBlockAndMetadata(x, y, z,blockID, metaData);

 

say planks blockID is 50, and the metaData for the birch is 3 and you want to change the block at (0,0,0)

world.setBlockAndMetadata(0, 0, 0, 50, 3)

 

if you dont understand that method, then i think you should go back over metadata and relearn it.

Posted
  On 7/20/2012 at 12:31 AM, Cutter said:

  Quote

Taking my previous example, how would i then specify that the planks im right clicking are birch planks and not any of the other planks?

world.setBlockAndMetadata(x, y, z,blockID, metaData);

 

say planks blockID is 50, and the metaData for the birch is 3 and you want to change the block at (0,0,0)

world.setBlockAndMetadata(0, 0, 0, 50, 3)

 

if you dont understand that method, then i think you should go back over metadata and relearn it.

 

Read the first post and my first code.

 

I cant 'set' it because its not the block that it sets its the block that is already there; thats why I have GETBlockId there at the first block however on the second one(the one that i set when right clicked) logically enough has SET because it sets the block there. The birch planks, taking my example are not the block that gets set when the first one gets clicked but its actually the block getting clicked. What I have problems with is to make it so that birch planks in this case and not any of the other planks gets turned into magenta wool;and as said before, I already have the damage value for the block It TURNS INTO. So before you start being a dick, get your facts straight.

 

 

EDIT: If i am just misunderstanding what you've said, I deeply apologize and I can only ask of you to maybe tell me where to put the setBlockAndMetadata method and in what context, also; can you then make your code example like how we discussed it, with the birch plank/magenta wool thing? Its easier to understand that way.  Thanks!

Posted
  On 7/20/2012 at 12:45 AM, Thor597 said:

  Quote

  Quote

Taking my previous example, how would i then specify that the planks im right clicking are birch planks and not any of the other planks?

world.setBlockAndMetadata(x, y, z,blockID, metaData);

 

say planks blockID is 50, and the metaData for the birch is 3 and you want to change the block at (0,0,0)

world.setBlockAndMetadata(0, 0, 0, 50, 3)

 

if you dont understand that method, then i think you should go back over metadata and relearn it.

 

Read the first post and my first code.

 

I cant 'set' it because its not the block that it sets its the block that is already there; thats why I have GETBlockId there at the first block however on the second one(the one that i set when right clicked) logically enough has SET because it sets the block there. The birch planks, taking my example are not the block that gets set when the first one gets clicked but its actually the block getting clicked. What I have problems with is to make it so that birch planks in this case and not any of the other planks gets turned into magenta wool;and as said before, I already have the damage value for the block It TURNS INTO. So before you start being a dick, get your facts straight.

 

 

EDIT: If i am just misunderstanding what you've said, I deeply apologize and I can only ask of you to maybe tell me where to put the setBlockMetadata method and in what context, also; can you then make your code example like how we discussed it, with the birch plank/magenta wool thing? Thanks!

 

no, i was being an idiot. but from the sounds of it, all your looking for is an if condition checking to make sure that the metadata is of a certain value, yes?

 

in which case int birchPlankMetaData = world.getBlockMetadata(x, y, z); will get the metadata of the block being clicked on because you get the location of the block from the parameters of blockActivated.

 

then use a simple if statement to check whether birchPlankMetaData is equal to the metadata value you need.

 

public boolean blockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer){

    	int birchPlankMetaData = world.getBlockMetadata(x, y, z);
    	
    	if(birchPlankMetaData==0){
    		
    		world.setBlockAndMetadata(x, y, z, Block.cloth.blockID, 3);
    		return true;
    		
    	}
    	return false;
    }

as simple as that i think. worked for changing a meta data item i had into lightblue wool.

Posted

Yes, this seems nice for that purpose, but -not to be ungrateful or anything- you see, the reason I was using an onItemUse method is because of these reasons:

 

1: If i were to use an onBlockActivated method I would have to edit base code which you know, no one would like to do

 

2: I want the tool im using onItemUse in to be the only tool able to do this.

 

3: I want to make the tool take damage when doing it

 

I think maybe 2 and 3 could be solved in a way with onBlockActivated, but I really really do not want to edit base code. Thanks anyway!

Posted
  On 7/20/2012 at 1:35 AM, Thor597 said:

Yes, this seems nice for that purpose, but -not to be ungrateful or anything- you see, the reason I was using an onItemUse method is because of these reasons:

 

1: If i were to use an onBlockActivated method I would have to edit base code which you know, no one would like to do

 

2: I want the tool im using onItemUse in to be the only tool able to do this.

 

3: I want to make the tool take damage when doing it

 

I think maybe 2 and 3 could be solved in a way with onBlockActivated, but I really really do not want to edit base code. Thanks anyway!

 

oh i didnt realise =.= its really late for me now so im going to bed, but if you dont find a fix for it in the next 12 hours or so, then i will look and post one with the 'onItemUse' method.

Posted

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7)
    {
    	int metaDataOfTargetBlock = world.getBlockMetadata(x, y, z);
    	
    	if(metaDataOfTargetBlock==1){
    		
    		world.setBlockAndMetadata(x, y, z, Block.cloth.blockID, 3);
    		return true;
    		
    	}
    	return false;
    }

 

this code works if you just add it to an item as an overide. BECAREFUL though, if you set the metaDataOfTargetBlock == 0, all blocks in the world will be changed as most have a metadata of 0. although, im pretty sure if you just add in the target blocks blockID into the if statement aswell, you can prevent that. i think par7 is metaData being provided from the tool itself, but i dont know.

Posted
  On 7/20/2012 at 10:19 PM, Cutter said:

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7)
    {
    	int metaDataOfTargetBlock = world.getBlockMetadata(x, y, z);
    	
    	if(metaDataOfTargetBlock==1){
    		
    		world.setBlockAndMetadata(x, y, z, Block.cloth.blockID, 3);
    		return true;
    		
    	}
    	return false;
    }

 

this code works if you just add it to an item as an overide. BECAREFUL though, if you set the metaDataOfTargetBlock == 0, all blocks in the world will be changed as most have a metadata of 0. although, im pretty sure if you just add in the target blocks blockID into the if statement aswell, you can prevent that. i think par7 is metaData being provided from the tool itself, but i dont know.

 

Thank you SOOOOO much! This is my finished code that works:

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7)
    {
    	
        int i = world.getBlockId(x, y, z);

        if (y != 0 && i == Block.planks.blockID)
        {   	
    	int metaDataOfTargetBlock = world.getBlockMetadata(x, y, z);
    	
    	if(metaDataOfTargetBlock == 1){
    		
    		Block block = Block.cloth;	   		
    		world.playSoundEffect((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F, block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);	    		
    		world.setBlockAndMetadataWithNotify(x, y, z, Block.cloth.blockID, 3);
    		return true;
    	}
    		
    }
    	return false;
    }	

 

 

The only wrong thing in your code there was the world.setBlockAndMetadata, it shouldve been world.setBlockAndMetadataWithNotify but i've fixed that up now!

Posted
  On 7/20/2012 at 11:00 PM, Thor597 said:

  Quote

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7)
    {
    	int metaDataOfTargetBlock = world.getBlockMetadata(x, y, z);
    	
    	if(metaDataOfTargetBlock==1){
    		
    		world.setBlockAndMetadata(x, y, z, Block.cloth.blockID, 3);
    		return true;
    		
    	}
    	return false;
    }

 

this code works if you just add it to an item as an overide. BECAREFUL though, if you set the metaDataOfTargetBlock == 0, all blocks in the world will be changed as most have a metadata of 0. although, im pretty sure if you just add in the target blocks blockID into the if statement aswell, you can prevent that. i think par7 is metaData being provided from the tool itself, but i dont know.

 

Thank you SOOOOO much! This is my finished code that works:

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7)
    {
    	
        int i = world.getBlockId(x, y, z);

        if (y != 0 && i == Block.planks.blockID)
        {   	
    	int metaDataOfTargetBlock = world.getBlockMetadata(x, y, z);
    	
    	if(metaDataOfTargetBlock == 1){
    		
    		Block block = Block.cloth;	   		
    		world.playSoundEffect((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F, block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);	    		
    		world.setBlockAndMetadataWithNotify(x, y, z, Block.cloth.blockID, 3);
    		return true;
    	}
    		
    }
    	return false;
    }	

 

 

The only wrong thing in your code there was the world.setBlockAndMetadata, it shouldve been world.setBlockAndMetadataWithNotify but i've fixed that up now!

 

ah, in my original code im using world.setBlockAndMetadataWithNotify, not sure how it changed. anyways, np, glad i could help ^_^

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I never imagined I would be writing this kind of testimony, but I feel it’s important to share my experience with Malice Cyber Recovery and how they helped me recover $230,000 I lost to crypto scammers. A few months ago, I got involved in a crypto investment opportunity that seemed legitimate at first. The scammers were incredibly convincing. They showed me impressive returns, sent regular updates, and even gave me access to what looked like a real trading platform. I was initially cautious, but after seeing the returns, I began to invest more, ultimately transferring over $230,000. Unfortunately, after a few weeks, when I tried to withdraw my funds, I found that the platform had disappeared, and I could no longer contact anyone involved. It was clear I had been scammed, and I felt completely helpless. For weeks, I tried everything to get my money back—contacting the authorities, reaching out to the platform’s so-called support team (who of course were unreachable), and trying to trace the transactions myself. But everything led to dead ends. The more I researched, the more I realized just how hard it was to recover stolen crypto. I began to lose hope. That’s when I came across Malice Cyber Recovery. At first, I was skeptical. Could they really help me recover my funds after everything I had been through? I decided to reach out anyway, just to see if they could offer any guidance. From the very first conversation, their team was not only professional but also deeply empathetic. They understood exactly how I was feeling and immediately made it clear that they were dedicated to helping me recover my lost funds. Malice Cyber Recovery’s team got to work quickly. They walked me through every step of the process, explaining the methods they would use to track down my stolen crypto. Their knowledge of blockchain technology and how to trace crypto transactions was incredibly impressive. They didn’t just give me vague promises they showed me the action they were taking and the progress they were making, which gave me hope that my money wasn’t gone forever. One of the most reassuring aspects of working with Malice Cyber Recovery was their transparency. They kept me updated regularly, letting me know what they were doing, what obstacles they encountered, and how they were overcoming them. It wasn’t an easy process; tracing funds through blockchain and dealing with scammers who hide behind fake identities and complex networks is incredibly difficult. But Malice Cyber Recovery’s team was relentless. They used advanced tools and techniques to trace the flow of my funds, and within just a few weeks, they managed to locate a significant portion of my lost funds. I couldn’t believe it when they informed me that they had successfully recovered a large chunk of my money. I never thought I’d see that $230,000 again. The recovery process wasn’t instantaneous it  took time, patience, and persistence but Malice Cyber Recovery delivered on their promise.  
    • Almost, just the java -server -Xmx4G -Xms4G -Dlog4j.configurationFile=log4jformattingfix.xml -jar forge-1.12.2-14.23.5.2860.jar nogui and if that doesn't work, try java --version
    • What so just copy and paste " java -server -Xmx4G -Xms4G -Dlog4j.configurationFile=log4jformattingfix.xml -jar forge-1.12.2-14.23.5.2860.jar nogui Pause >nul " into a cmd terminal? If that's what you mean, nothing happens
    • The networking has been far simplified in 1.20.5+ The docs could be old, as Ash has said feel free to submit a PR updating the community docs. However the only real up-to-date reference would be the code itself. So your best bet is to just read the code and give it want it wants.
    • No matter how many mods I disable it keeps giving the same error. https://paste.ee/p/1fBHCe9O
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.