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

Harvest setting will only affect damage done to the item.

To drop the item, spawn an EntityItem with the block data.

  • Author

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?

Yes, this code will spawn an EntityItem.

The only data useful for the ice block is its id, Block.ice.blockID.

Make it so the ItemStack in EntityItem has this blockID.

  • Author

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

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.