Jump to content

Recommended Posts

Posted

At the moment, I'm learning to develop mods for Minecraft 1.4.7. However, as you can see in the title, I don't know how to programm a custom bucket. For example if I want to programm a gold bucket. Is there a special implentation available in Minecraft Forge? I heard of IBucketHandler, but it seems, that this doesn't exist anymore. Is there another way to programm it? Should I simply make the gold bucket a subclass of ItemBucket.java and change some values of its methods? If this is the right way, how should I do this exactly, because I already tried this, but it didn't work (maybe it's just a stupid mistake I haven't seen yet).

 

Thank you for helping!

Posted

You should certainly start by taking a look at ItemBucket and seeing how it does things. Whether you should subclass it or not depends on how much you want to customise it.

 

If all you want to do is make it look like it's made of gold, you probably don't need a subclass. Just make an instance of ItemBucket and use setTextureFile and setIconCoords to give it your own icon. You'll also want to set its name and install a language translation for that name so that it appears as "Gold Bucket" or whatever in tooltips.

 

You'll actually need to create two instances, one for a full bucket and one for an empty bucket, with different item IDs. Look at the two "new ItemBucket" calls in Item.java to see how you need to set them up.

Posted

Thank you really much for your help.

 

I had again a look on my subclass and I found the mistake. It was really tricky in a way... But afterwards it sounds really easily. My mistake was: You shouldn't forget this.isFull = par 2 in public TutorialItemBucket(int par1, int par2).

package tutorial;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.entity.passive.EntityCow;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBucket;

import net.minecraft.item.ItemStack;

import net.minecraft.util.EnumMovingObjectType;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.event.Event;

import net.minecraftforge.event.entity.player.FillBucketEvent;

 

public class TutorialItemBucket extends ItemBucket {

 

private int isFull;

 

public TutorialItemBucket(int par1, int par2) {

super(par1, par2);

this.isFull = par2; // This is really important; That was what I've forgotten.

}

 

@Override

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

        float var4 = 1.0F;

        double var5 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)var4;

        double var7 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par3EntityPlayer.yOffset;

        double var9 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)var4;

        boolean var11 = this.isFull == 0;

        MovingObjectPosition var12 = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, var11);

 

        if (var12 == null)

        {

            return par1ItemStack;

        }

        else

        {

            FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, var12);

            if (MinecraftForge.EVENT_BUS.post(event))

            {

                return par1ItemStack;

            }

 

            if (event.getResult() == Event.Result.ALLOW)

            {

                if (par3EntityPlayer.capabilities.isCreativeMode)

                {

                    return par1ItemStack;

                }

 

                if (--par1ItemStack.stackSize <= 0)

                {

                    return event.result;

                }

 

                if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result))

                {

                    par3EntityPlayer.dropPlayerItem(event.result);

                }

 

                return par1ItemStack;

            }

 

            if (var12.typeOfHit == EnumMovingObjectType.TILE)

            {

                int var13 = var12.blockX;

                int var14 = var12.blockY;

                int var15 = var12.blockZ;

 

                if (!par2World.canMineBlock(par3EntityPlayer, var13, var14, var15))

                {

                    return par1ItemStack;

                }

 

                if (this.isFull == 0)

                {

                    if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15, var12.sideHit, par1ItemStack))

                    {

                        return par1ItemStack;

                    }

 

                    if (par2World.getBlockMaterial(var13, var14, var15) == Material.water && par2World.getBlockMetadata(var13, var14, var15) == 0)

                    {

                        par2World.setBlockWithNotify(var13, var14, var15, 0);

 

                        if (par3EntityPlayer.capabilities.isCreativeMode)

                        {

                            return par1ItemStack;

                        }

 

                        if (--par1ItemStack.stackSize <= 0)

                        {

                            return new ItemStack(Tutorial.bucketGoldWater);

                        }

 

                        if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Tutorial.bucketGoldWater)))

                        {

                            par3EntityPlayer.dropPlayerItem(new ItemStack(Tutorial.bucketGoldWater.itemID, 1, 0));

                        }

 

                        return par1ItemStack;

                    }

                   

                }

                else

                {

                    if (this.isFull < 0)

                    {

                        return new ItemStack(Tutorial.bucketGoldEmpty);

                    }

 

                    if (var12.sideHit == 0)

                    {

                        --var14;

                    }

 

                    if (var12.sideHit == 1)

                    {

                        ++var14;

                    }

 

                    if (var12.sideHit == 2)

                    {

                        --var15;

                    }

 

                    if (var12.sideHit == 3)

                    {

                        ++var15;

                    }

 

                    if (var12.sideHit == 4)

                    {

                        --var13;

                    }

 

                    if (var12.sideHit == 5)

                    {

                        ++var13;

                    }

 

                    if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15, var12.sideHit, par1ItemStack))

                    {

                        return par1ItemStack;

                    }

 

                    if (this.tryPlaceContainedLiquid(par2World, var5, var7, var9, var13, var14, var15) && !par3EntityPlayer.capabilities.isCreativeMode)

                    {

                        return new ItemStack(Tutorial.bucketGoldEmpty);

                    }

                }

            }

            return par1ItemStack;

        }

    }

 

@Override

public String getTextureFile() {

return CommonProxy.TUTORIAL_ITEM_PNG;

}

 

}

Hint: With this code, you have a bucket which can take just water and nothing else.

 

Thank you gcewing!!!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • UPDATE: this seems to be an Arch-specific issue. Switching to Ubuntu server fixed EVERYTHING.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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