Jump to content

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


Recommended Posts

Posted

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.

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

Posted

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

Posted

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

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

Announcements



×
×
  • Create New...

Important Information

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