Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am trying to make a Item that can plant seeds next to it in the hot bar in a #x# area. The issue is I need to some how find out if the item is plantable if so plant it in a #x# area

  • Author

Sorry I worded that bad, I can't figure how when I right click with my item have it plant the seed that is next to it in the hot bar in a area around me. The area bit I can do, and I can get what Item is next to mine in the hot bar.

    
    @Override
    public boolean onItemUse(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
        if(side!=1 || world.getBlock(x, y, z) != Blocks.farmland)return false;
        if(world.isRemote)return true;
        int radius = 3;

        for(int x2 = -radius; x2<=radius; x2++)
        for(int z2 = -radius; z2<=radius; z2++)
           if(player.canPlayerEdit(x+x2, y, z+z2, side, is) && world.getBlock(x+x2, y+1, z+z2).getMaterial().isReplaceable() && world.getBlock(x+x2, y, z+z2) == Blocks.farmland)
               world.setBlock(x+x2, y+1, z+z2, Blocks.wheat, 0, 3);

        return true;
    }

       @Override
    public boolean onItemUse(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
        ItemStack next = player.inventory.currentItem+1 < player.inventory.getSizeInventory() ? player.inventory.getStackInSlot(player.inventory.currentItem+1) : null;

        if(side!=1 || !(next!=null && next.getItem() instanceof IPlantable))return false;
        int radius = 3;

        for(int x2 = -radius; x2<=radius; x2++)
        for(int z2 = -radius; z2<=radius; z2++){
              if(next.stackSize>0)next.getItem().onItemUse(next, player, world, x+x2, y, z+z2, side, hitX, hitY, hitZ);
              if(next.stackSize<=0)player.inventory.setInventorySlotContents(player.inventory.currentItem+1, null);
        }
        return true;
    }

I think it works.

  • Author

Ahh I see thanks!, didn't know you could use "getItem().onItemUse" like that with other items. That was what I was missing.

You have to be specific about "next to" when you talk about the hot bar, there is "to the left side" and "to the right side". Either check both sides or require a specific side for the seeds to be on.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.