Jump to content

[SOLVED] Trying to get a Item to right click/plant crops in a area.


shadoskill

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.

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

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