
Bugzoo
-
Posts
268 -
Joined
-
Last visited
Posts posted by Bugzoo
-
-
-
Unfortunately that function doesn't deal with metadata. You're better of checking the player's hand for spruce (item == Blocks.log && itemDamage == 4 (I think spruce is 4)), and if so, decrementing the stack size.
Ok, I've now got this code
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
But that takes the whole stack away, how do I only take 1 away?
-
I want to consume one log (ex. spruce) everytime I right click on a block. Here is where I've got so far
player.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.log));
But that code consume only oak log, but I want it to consume spruce
-
And now you know why we use trace statements. They tell you what the program is doing as it does it, and lets you locate the problem area of code rather than BLINDLY GUESSING.
Yea, so sorry about so much fuss over me being blind
https://www.youtube.com/watch?v=YhSXAyybEIM
-
For the love of god, why not just simply use java correctly?
if(entityplayer.getCurrentEquippedItem() != null && (entityplayer.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(Blocks.log) && entityplayer.getCurrentEquippedItem().getItemDamage() == 2))
Bugzoo i see you are new to this so i just give you a simple advice. Use the vanilla src!
OMFG! I just realized I was running another if statement somewhere in the method which checked if the block was a log, and if it was it ran some code. That was the problem. But, on a sidenote, i'm not new to this. I have been programming in java for 4 years, programming minecraft mods for 2 years. Published 3 mods. So, i'm not really new to this.
-
Just above that if statement, put this:
System.out.println("Right clicked with: " + hand.getItem() + ":" + hand.getItemDamage()); System.out.println(hand.getItem() == Item.getItemFromBlock(Blocks.log)); System.out.println(hand.getItemDamage() == 0); System.out.println((hand.getItem() == Item.getItemFromBlock(Blocks.log) && hand.getItemDamage() == 0));
Then tell me what it prints out when you use various blocks.
When I right click with oak it prints this
[com.bugzoo.GranterMod.BlockGranter:onBlockActivated:50]: Right clicked with: net.minecraft.item.ItemMultiTexture@1c29de2:0 true true true
When I right click with any other type of log it prints out this
[com.bugzoo.GranterMod.BlockGranter:onBlockActivated:50]: Right clicked with: net.minecraft.item.ItemMultiTexture@1c29de2:3 true false false
-
I just noticed something. That line of code does work. So if I did
if(hand.getItemDamage() == 0)
The if statement would run, only if the block is Spruce or Dark Oak. Though if I do this
if(hand.getItem() == Item.getItemFromBlock(Blocks.log) && hand.getItemDamage() == 0)
It runs no-matter what log it is.
-
-
-
-
-
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?
-
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); } } }
-
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); } } }
-
-
-
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
-
-
-
-
-
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?
-
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
-
[1.7.10] Consume Logs
in Modder Support
Posted
I know how to get the held item. I just want to know how I can decrease 1 item from that stack