Jump to content

Bugzoo

Members
  • Posts

    268
  • Joined

  • Last visited

Posts posted by Bugzoo

  1.   On 12/5/2014 at 2:50 PM, Draco18s said:

    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?

  2. 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

     

     

  3.   On 12/3/2014 at 5:37 PM, FLUFFY2 said:

    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.

  4.   On 12/3/2014 at 5:25 PM, Draco18s said:

    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

     

     

  5.   On 12/3/2014 at 5:08 PM, Draco18s said:

      Quote

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

     

    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.

  6.   On 12/1/2014 at 7:10 PM, larsgerrits said:

    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?

  7.   On 12/1/2014 at 6:57 PM, larsgerrits said:

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

     

     

  8.   On 12/1/2014 at 6:40 PM, larsgerrits said:

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

  9.   On 11/30/2014 at 4:34 PM, larsgerrits said:

    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?

  10.   On 11/30/2014 at 3:36 PM, Draco18s said:

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

     

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

     

      Quote

    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

  11.   On 11/30/2014 at 1:15 PM, larsgerrits said:

    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?

×
×
  • Create New...

Important Information

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