Jump to content

Recommended Posts

Posted

I am trying to make a custom tool which can harvest ice and it will drop as an item, as it does with silk touch in the vanilla game, however I want to do this without adding enchantments to the custom tool, the code I'm using is as follows:

 

 

public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
    {
        if(par2Block == Block.ice)
        {
        	return 5.0F;
        }
        
        else return 0.5F;
    }

 public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
    {
        if (par3 != Block.ice.blockID)
        {
            return super.onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase);
        }
        else
        {
            return true;
        }
    }

 public boolean canHarvestBlock(Block par1Block)
    {
        if(par1Block.blockID == Block.ice.blockID)
        {
        	return true;
        }
        
        else
        {
        	return false;
        }
    }

 

 

I am making the tool only to harvest ice, can someone point out my mistake or what I am missing in my item code?

 

Ethyl

Posted

I'm very new to modding so I'm unsure of how exactly to do that, I've been looking at the shears code, I'm guessing I need to use the following:

 

 

float f = 0.7F;
                    double d  = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                    double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                    double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                    EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
                    entityitem.delayBeforeCanPickup = 10;
                    player.worldObj.spawnEntityInWorld(entityitem);

 

 

however I am unsure as to how to make the entity item have the ice block data?

Posted

I am now using this code but still no luck, am I missing something?

 

 

public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
    {
        if (par3 == Block.ice.blockID)
        {
        	Random rand = new Random();
        	 float f = 0.7F;
                double d  = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
                EntityItem entityitem = new EntityItem(par7EntityLivingBase.worldObj, (double)par4 + d, (double)par5 + d1, (double)par6 + d2, new ItemStack(Block.ice.blockID,1,0));
                entityitem.delayBeforeCanPickup = 10;
                par7EntityLivingBase.worldObj.spawnEntityInWorld(entityitem);
                par2World.setBlock(par4, par5, par6, 0);
                return true;
        }    
            
        else
        {
        	return false;
        }
    }

 

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.