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

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

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

  • 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?

Use EntityInteractEvent.

It contains the player instance and the entity targetted.

Do a check for a cow entity, and the bucket stack in the player's hand.

Decrease the stack size, and give the player a filled bucket.

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.