Posted November 30, 201410 yr I want to check if Birch wood is in the players hand if(hand.getItem() == Blocks.log) I have this code, but I get an error and thats oak and not birch
November 30, 201410 yr 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/
November 30, 201410 yr Author 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?
November 30, 201410 yr 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/
November 30, 201410 yr Author 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));
November 30, 201410 yr Author Just set the current item slot (player.inventory.currentItem) to null. Tried this and it crashed my game player.inventory.currentItem = (Integer) null;
November 30, 201410 yr Author *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?
November 30, 201410 yr Author 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?
November 30, 201410 yr 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.
November 30, 201410 yr Author 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
November 30, 201410 yr 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.
November 30, 201410 yr Author Describe how it doesn't work. What seems to be the issue? It runs the method if you right click with any type of wood
November 30, 201410 yr 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/
December 1, 201410 yr Author 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?
December 1, 201410 yr 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/
December 1, 201410 yr Author 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); } } }
December 1, 201410 yr 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/
December 1, 201410 yr Author 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); } } }
December 1, 201410 yr 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/
December 1, 201410 yr Author 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?
December 1, 201410 yr 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/
December 1, 201410 yr Author 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
December 2, 201410 yr 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/
December 2, 201410 yr Author 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
December 2, 201410 yr 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.