Jump to content

How can I milk cows with a custom bucket?


Netglex

Recommended Posts

I have the following problem: I programmed a custom bucket: the golden bucket (for example). Now, I want to milk a cow with it. I've already seen, that in ItemBucket.java, there is the important part:

else if (this.isFull == 0 && var12.entityHit instanceof EntityCow)

            {

            return new ItemStack(Item.bucketMilk);

            }

However, I recognized that in the file EntityCow.java, there is another important method:

public boolean interact(EntityPlayer par1EntityPlayer)

    {

        ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();

 

        if (var2 != null && var2.itemID == Item.bucketEmpty.itemID)

        {

            if (--var2.stackSize <= 0)

            {

                par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketMilk));

            }

            else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketMilk)))

            {

                par1EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketMilk.itemID, 1, 0));

            }

 

            return true;

        }

        else

        {

            return super.interact(par1EntityPlayer);

        }

    }

This is probably also responsable for the milking process. My question is now: How can I milk with a golden bucket without changing EntityCow.java and just changing my own mod files?

Link to comment
Share on other sites

  • 6 months later...

Don't use the buckets code for reference, it's overcomplicated. Instead, add the method itemInteractionForEntity() in your bucket class, and then do ItemStack.id = filledgoldenbucket.id+256

Sorry to bring back an old thread but this the only thread I could find on the issue and my reply is about this suggested method.

 

This suggestion would cause a stack of empty buckets to be filled with milk.  How do we allow only one bucket to be filled, since that method doesn't provide an EntityPlayer?

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.