Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Forging a Minecraft mod

Basic Minecraft modding with Minecraft Forge

How to remove an item from hand?

  • 2013-08-03 10:48:22
    i dont know if im not looking on the right place or what but i cant find a method to remove the item you currently have in hand can someone help me?

  • 2013-08-03 11:04:42
    nvm i figured myself, i used the method

    player.inventory.consumeInventoryItem()

    but now i have another problem...

    im using onBlockActivated() to remove certain items from my inventory and update the metadata of the block... so far it works fine...but when i right click with empty hands it crash the game...not sure why is this happening.... here is my onBlockActivated

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsteZ) {
    if(!world.isRemote){
                if (player.getHeldItem().itemID == HarvestConfigurationHandler.cuttingboardID + 256) {                
                    world.setBlockMetadataWithNotify(x, y, z, 2, 3);
                    player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                }else if(player.getHeldItem().itemID == HarvestConfigurationHandler.mixingbowlID + 256){
                    world.setBlockMetadataWithNotify(x, y, z, 4, 3);
                    player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                }else if (player.getHeldItem().itemID == HarvestConfigurationHandler.mortarandpestleID + 256){
                    world.setBlockMetadataWithNotify(x, y, z, 6, 3);
                    player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                    //BORRAR ESTO
                }else if(player.getHeldItem().itemID == HarvestConfigurationHandler.saltID + 256){
                    world.setBlockMetadataWithNotify(x, y, z, 0, 3);
                    
                }
                //HASTA AQUI
            }
            return true;
            
        }    
  • 2013-08-03 12:16:49
    It crashes because player.getHeldItem() returns the value of inventory.getCurrentItem(), which in turn returns "this.currentItem < 9 && this.currentItem >= 0 ? this.mainInventory[this.currentItem] : null;". See that null, at the end? That's your problem ;)
  • 2013-08-03 12:46:12
    Indeed, make sure that the player is actually holding an item before trying to do anything with it.
  • 2013-08-04 10:18:57
    Oh...I would never figured that out......Thanks for the help :D

    just in case somebody get stuck in the same problem i fixed it like this...

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsteZ) {
            if(!world.isRemote){
                if(player.getHeldItem() != null){ //HERE I CHECK THE HAND IS NOT EMPTY
                    if (player.getHeldItem().itemID == HarvestConfigurationHandler.cuttingboardID + 256) {                
                        world.setBlockMetadataWithNotify(x, y, z, 2, 3);
                        player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                    }else if(player.getHeldItem().itemID == HarvestConfigurationHandler.mixingbowlID + 256){
                        world.setBlockMetadataWithNotify(x, y, z, 4, 3);
                        player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                    }else if (player.getHeldItem().itemID == HarvestConfigurationHandler.mortarandpestleID + 256){
                        world.setBlockMetadataWithNotify(x, y, z, 6, 3);
                        player.inventory.consumeInventoryItem(player.getHeldItem().itemID);
                        //BORRAR ESTO
                    }else if(player.getHeldItem().itemID == HarvestConfigurationHandler.saltID + 256){
                        world.setBlockMetadataWithNotify(x, y, z, 0, 3);
                        
                    }
                    //HASTA AQUI
                }else{//Other Stuff}    //HERE I CAN DO ANYTHING IF RIGHT CLICK WITH A EMPTY HAND
            }
            return true;
            
        }    
  • 2013-08-04 10:21:18
    now i can watch the Tile entities course :D
  • 2017-01-09 21:57:49
    how to use cialis
    http://pharmshop-online.com - generic cialis cialis 10 mg 4 tablet register
    <a href="http://pharmshop-online.com">generic cialis</a> - canadian pharmacy cialis 20mg posts per day
    about cialis for's and against
  • 2017-01-14 02:39:40
    dna choroba dieta dna alkohol <a href=http://seeknet.pl/>http://seeknet.pl/</a> podagra a alkohol dna moczanowa nieleczona
  • 2017-01-19 21:51:25
    co to jest dna dna alkohol <a href=http://seeknet.pl/>http://seeknet.pl/</a> dna moczanowa leczenie ziolami dieta w podagrze
  • 2017-01-20 01:19:55
    leki na podagre dna moczanowa leczenie domowe <a href=http://seeknet.pl/>http://seeknet.pl/</a> ziola na kwas moczowy leczenie dny moczanowej ziolami
  • 2017-01-20 11:01:27
    kwasica ketonowa choroba dna moczanowa objawy <a href=http://seeknet.pl/>http://seeknet.pl/</a> czego nie mozna jesc przy dnie moczanowej ziola w dnie moczanowej
  • 2017-01-20 12:20:38
    ziola dna moczanowa dna moczanowa czego nie wolno jesc <a href=http://seeknet.pl/>http://seeknet.pl/</a> dna moczanowa zywienie dna moczanowa powiklania
  • 2017-01-20 13:46:56
    dna moczanowa a alkohol dna moczanowa przyczyny <a href=http://seeknet.pl/>http://seeknet.pl/</a> dieta przy dna moczanowa choroba bogatych ludzi
  • 2017-01-20 15:22:24
    podagra jak leczyc dna moczanowa leczenie niekonwencjonalne <a href=http://seeknet.pl/>http://seeknet.pl/</a> jakie sa objawy dny moczanowej pierwsze objawy dny moczanowej
  • 2017-01-20 17:02:15
    kwasica moczanowa jak leczyc dne moczanowa ziolami <a href=http://seeknet.pl/>http://seeknet.pl/</a> co jesc przy dnie moczanowej dna moczanowa diety
  • 2017-01-20 18:55:16
    moczanowa dna dieta leczenie dna moczanowa <a href=http://seeknet.pl/>http://seeknet.pl/</a> dieta dla dny moczanowej dna moczanowa a piwo
  • 2017-01-24 05:07:36
    dna moczanowa a picie alkoholu ziola na dne moczanowa <a href=http://seeknet.pl/>http://seeknet.pl/</a> dieta podagra dna moczanowa objawy i przyczyny leczenie
  • 2017-01-24 07:39:55
    dieta na dne moczanowa dna moczanowa leczenie domowe <a href=http://seeknet.pl/>http://seeknet.pl/</a> dna moczanowa leczenie ziolami dna moczanowa a piwo
  • 2017-01-24 10:39:28
    czego nie nalezy jesc przy dnie moczanowej ziola przy dnie moczanowej <a href=http://seeknet.pl/>http://seeknet.pl/</a> dna objawy kwasica cukrzycowa
  • 2017-01-24 14:22:36
    dna moczanowa co jesc leczenie dny <a href=http://seeknet.pl/>http://seeknet.pl/</a> co to jest dna moczanowa kwasica cukrzycowa
  • 2017-01-24 17:01:03
    dieta na dne moczanowa podagra <a href=http://seeknet.pl/>http://seeknet.pl/</a> dna moczanowa czego nie wolno jesc dieta przy dnie moczowej
  • 2017-01-24 20:32:44
    dna choroba dieta podagra przyczyny <a href=http://seeknet.pl/>http://seeknet.pl/</a> czym jest dna ziola na kwas moczowy
  • 2017-01-25 03:19:45
    moczanowa dna podagra dna moczanowa <a href=http://seeknet.pl/>http://seeknet.pl/</a> leczenie dny moczanowej nieleczona dna moczanowa
  • 2017-04-12 22:06:55
    long term effect of cialis
    http://pharmashop-online.com - generic cialis
    cialis cialis vs
    <a href="http://pharmashop-online.com">generic cialis
    </a> - overcoming ed
    retalis cialis
  • 2017-04-21 14:11:05
    viagra online sales display posts from previous
    http://viagra-withoutadoctor.com - viagra without doctor prescription
    compare levitra viagra and viagra apeboard_plus.cgi?command=
    <a href="http://viagra-withoutadoctor.com">viagra without a doctor prescription
    </a> - buy viagra generic
    online pharmacy
  • 2017-04-22 13:40:37
    acheter viagra
    http://viagra-withoutdoctor.com - viagra without a doctor prescription
    viagra generic date in descending order
    <a href="http://viagra-withoutdoctor.com">viagra without a doctor prescription
    </a> - viagra dosage when to take maximum allowed
    viagra 20mg review who is online
  • 2017-05-07 04:55:30
    cialis information itrader
    http://cialiswithoutdoctor.org - cialis without a doctor's prescription
    viagra information patients most online today
    <a href="http://cialiswithoutdoctor.org">cialis without a doctor prescription usa
    </a> - viagra 20mg side effects all times are utc
    viagra doesn't seem to work for me
  • 2017-05-24 05:31:19
    viagra and alcohol side effects in total there are
    http://viagra-withoutadoctor.net - viagra without a doctor prescription
    viagra enligne
    <a href="http://viagra-withoutadoctor.net">viagra without prescription
    </a> - viagra and alcohol use registered users
    viagra s ite:komkom.pl
  • 2017-05-25 19:40:01
    viagra 10mg how long does it last no new posts
    http://viagra-withoutdoctor.net - viagra without a doctor prescription usa
    natural viagra
    <a href="http://viagra-withoutdoctor.net">viagra without a doctor prescription
    </a> - tadalafil viagra
    viagra release news
  • 2017-05-27 23:50:41
    prozac compatability with cialis
    http://viagra-withoutadoctors.com - viagra without prescription
    cialis 20mg i forgot my password
    <a href="http://viagra-withoutadoctors.com">viagra no prescription
    </a> - can cialis for women
    cialis free trial
  • 2017-05-28 04:53:17
    meth cialis and poppers
    http://viagra-withoutdoctors.com - viagra no prescription
    like cialis for heart help that insurance pays
    <a href="http://viagra-withoutdoctors.com">viagra without prescription
    </a> - cialis buy canada forum contains no new posts
    medicine including pills which is much more effective than viagra and cialis for the worst cases of
  • 2017-08-12 13:06:33
    http://revia.phartesdomusa.org buy naltrexone mexico
  • 2017-08-12 14:46:23
    http://revia.phartesdomusa.org generic naltrexone cost
  • Log in or sign up to reply to this thread