Jump to content

[1.12.2] Spawn Baby Animals from Item Right Click


minecraftisscience

Recommended Posts

Hey there,

 

i am programming a villager mod for Minecraft 1.12.2 and i want my villagers to trade special Items.

Now I'm struggling with the code of one of these items.

 

I want an Item, that can spawn only baby vanilla animals, like baby pigs, baby cows and so on.

But i don't really know, how to spawn baby animals.

At the moment, the following code in the items 'onItemRightClick' function spawns only adult vanilla pigs.

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
        ItemStack itemstack = playerIn.getHeldItem(hand);
        
        if(!worldIn.isRemote){
            EntityPig pig = new EntityPig(worldIn);
            EntityAgeable child = new EntityPig(worldIn).createChild(pig);
            child.setPosition(playerIn.posX + 0.5D , playerIn.posY, playerIn.posZ + 0.5D);
            worldIn.spawnEntity(child);
            itemstack.shrink(1);
            return new ActionResult(EnumActionResult.SUCCESS,itemstack);
            
        }
        return super.onItemRightClick(worldIn, playerIn, hand);
    }

 

What can i do, to get only baby pigs?

And is this even possible?

 

Thank you very mutch

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.

Announcements



×
×
  • Create New...

Important Information

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