Jump to content
Search In
  • More options...
Find results that contain...
Find results in...



Recommended Posts

this is my code

    public void checkItem(BlockEvent.EntityPlaceEvent event) {
        if (!event.getWorld().isRemote()) {
            if (event.getEntity() instanceof PlayerEntity) {
                PlayerEntity player = (PlayerEntity) event.getEntity();
                Hand hand = player.getActiveHand();
                ItemStack stack = player.getHeldItem(hand);
                if (stack.getCount() == 1) {
                    int i = this.findItem(player, stack.getItem().getItem());
                    if (i != -1) {
                        ItemStack item = player.inventory.mainInventory.get(i);
                        player.inventory.mainInventory.set(i, ItemStack.EMPTY);
                        player.setHeldItem(hand, item);
                        System.out.println(stack + " 1");
public int findItem(PlayerEntity player, Item item) {
        for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
            ItemStack stack = player.inventory.mainInventory.get(i);
            if (!stack.isEmpty() && stack.getItem().getItem() == item) {
                return i;
        return -1;


Edited by IamP
syntax highlighting
Link to comment
Share on other sites

  • IamP changed the title to .

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.

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.