Jump to content

Recommended Posts

Posted

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/

Posted

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?

Posted

hand.getItemDamage() == birch damage

Hard???

 

I've got that, but now I need to consume the birch wood

 player.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.log));

Posted

Just set the current item slot (player.inventory.currentItem) to null.

 

Tried this and it crashed my game

player.inventory.currentItem = (Integer) null;

Posted

*facedesk*

 

Of course that will throw an exception. Learn about autoboxing.

You need to set the Slot to null, not the currentItem field.

 

Lol, well how do I get the slot?

Posted

InventoryPlayer implements IInventory so it has setInventorySlotContents.

 

I've got this code

player.inventory.setInventorySlotContents(int, itemstack);

So what arguments do I have to put in?

Posted

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.

Posted

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

Posted

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.

Posted

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/

Posted

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?

Posted

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/

Posted

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);
	}
}
}

Posted

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);
	}
}
}

 

 

Posted

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/

Posted

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?

Posted

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/

Posted

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.

 

Yea, thats what i'm trying to do, but that code doesn't work. It runs the method no-matter what log it is

Posted

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

 

Yea, so this if statement

 

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

 

Runs the code no-matter what log it is. I only want it to run if it is birch

Posted

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.

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.