Jump to content

[1.7.10] Check If Birch Is In Hand?


Bugzoo

Recommended Posts

1) hand can be null, so check if it's not before calling

hand.getItem()

2) you can't compare Items to Blocks. Use

hand.getItem() == Item.getItemFromBlock(Blocks.log)

.

3) if you can check if

hand.getItemDamage()

is the damage of birch wood.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

1) hand can be null, so check if it's not before calling

hand.getItem()

2) you can't compare Items to Blocks. Use

hand.getItem() == Item.getItemFromBlock(Blocks.log)

.

3) if you can check if

hand.getItemDamage()

is the damage of birch wood.

 

Ok, that works for oak wood, but how do I do it for birch using hand.getItemDamage?

Link to comment
Share on other sites

hand.getItemDamage() == birch damage

Hard???

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

The number of the slot you wish to change....and null.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The number of the slot you wish to change....and null.

 

Thanks, that works, but now going back in time to this.

 

hand.getItemDamage() == birch damage

Hard???

 

I've got this code

if(hand.getItem() == Item.getItemFromBlock(Blocks.log) && hand.getItemDamage() == 1)

 

But this doesn't work

Link to comment
Share on other sites

Describe how it doesn't work.  What seems to be the issue?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You mean, it goes inside the if statements, as it shouldn't. But the method you have that if statement in, of course it will run it for every type of wood because you haven't checked for birch specifically.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You mean, it goes inside the if statements, as it shouldn't. But the method you have that if statement in, of course it will run it for every type of wood because you haven't checked for birch specifically.

 

How do I check for birch specifically?

Link to comment
Share on other sites

Show the full method with that if-statement. The method is probably run for EVERYTHING, and if you check for birch wood, it should only go inside that if-statement if so.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Show the full method with that if-statement. The method is probably run for EVERYTHING, and if you check for birch wood, it should only go inside that if-statement if so.

 

if(player.getCurrentEquippedItem() != null)
      {
     ItemStack hand = player.getCurrentEquippedItem();
     
     if(hand.getItem() == Item.getItemFromBlock(Blocks.log) && hand.getItemDamage() == 1)
     {
    player.inventory.addItemStackToInventory(new ItemStack(Blocks.log, 1, 1));
    player.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.log));
	RenderGranter.isAnimated = true;
	RenderGranter.renderOak = true;
	System.out.println(hand.getItem().getMetadata(1));
	world.spawnEntityInWorld((new EntityLightningBolt(world, x, y+1, z)));
	world.createExplosion((Entity)player, (double)x, (double)y, (double)z, 2F, false);
	}
}
}

Link to comment
Share on other sites

Full method, so including the method name and its signatures.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Full method, so including the method name and its signatures.

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
  if(player.getCurrentEquippedItem() != null)
      {
     ItemStack hand = player.getCurrentEquippedItem();
     
     if(hand.getItem() == Item.getItemFromBlock(Blocks.log) && hand.getItemDamage() == 1)
     {
    player.inventory.addItemStackToInventory(new ItemStack(Blocks.log, 1, 1));
    player.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.log));
	RenderGranter.isAnimated = true;
	RenderGranter.renderOak = true;
	System.out.println(hand.getItem().getMetadata(1));
	world.spawnEntityInWorld((new EntityLightningBolt(world, x, y+1, z)));
	world.createExplosion((Entity)player, (double)x, (double)y, (double)z, 2F, false);
	}
}
}

 

 

Link to comment
Share on other sites

Ok, that method is called for EVERY time you right click on the block. But it shouldn't go inside the if-statement.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ok, that method is called for EVERY time you right click on the block. But it shouldn't go inside the if-statement.

 

Ok, the way my code works, is if you right click with a birch log it runs the code within the if statement, so why shouldn't it go in the if statement?

Link to comment
Share on other sites

Sorry for that, little unclear. I mean, only if you are holding birch wood, it would go into the if-statement, else it shouldn't.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Does it go INSIDE(!) the if-statement if holding, for example, oak log?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You need to add the metadata check, duh.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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