Jump to content

Placing a block, clearing inventory.

Code Wrecker

Recommended Posts

I'm creating an item that places blocks from your inventory.


The idea of the item is, if you click side 0, it places on side 1 of the furthest solid block in that direction. If you click side 2, it places on the furthest block on side 3. etc etc.


(So you can stand in one place, and build a line of blocks away from you, above you, or below you, by simply clicking a 'source' block, and it will use your inventory and build out.)


I've built things that place blocks before, no big deal. I was trying to streamline it, put in more checks for world protection, valid placement, and things like that. So I was reusing a bunch of code from ItemBlock.class. Why reinvent the wheel? Use the default minecraft checks to do the heavy lifting.


At the end of the day, my OnUse grabs an ItemStack from inventory, not an ItemBlock. I'm just trying to find the 'hook' that clears the inventory of an item when the itemstack/itemblock stack count ==0;


Sure I could remember what inventory slot I grabbed, and then go back into the player inventory and null that. I'm just looking for a more elegant way of dealing with it, since I don't see any of the default minecraft code using the brute force player.inventory.maineinventory[x] = null;



Is there some method I should call?


Here is what I'm currently doing to place the block, and I'm not sure I like it.


iStack.tryPlaceItemIntoWorld(player, world, myPosX, myPosY, myPosZ, mySide, f1, f2, f3))



It decrements the stack to 0, and all that, it just doesn't destroy the stack from the inventory if I hit 0.



Link to comment
Share on other sites

This does not set the inventory stack to null, it sets your local variable to null.


ItemStack myStack = inventory.getStackInSlot(i);


myStack = 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.

Link to comment
Share on other sites

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.

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.


  • Create New...

Important Information

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