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.

[1.7.2] [~Solved] How to set 'damageDrop' (with chance) depending on 'itemDrop'?

Featured Replies

Posted

My block has got this two drops:

@Override
public Item getItemDropped(int par1, Random rand, int par3)
{
	if(rand.nextInt(10) == 0)
	{
		return Item.getItemFromBlock(Blocks.ToLSapling);
	}

	else
	{
		return Item.getItemFromBlock(net.minecraft.init.Blocks.sapling);
	}
}

 

The

net.minecraft.init.Blocks.sapling

block has 6 subtypes, and i want my block to drop all of them, not at the same time, one each time, and also with a random chance, like:

@Override
public int damageDropped(int par1)
{
	if(itemDropped == net.minecraft.init.Blocks.sapling)
	{
		return rand.nextInt(5);
	}

	else
	{
		return 0;
	}
}

 

But I've not found any

itemDropped

method or field, and also there is no

Random rand

parameter on the

damageDropped

method

 

Thanks for helping

private Random;

<-- declare at the top of your class (or bottom, however you like to do it)

 

Then in your block constructor, add:

 

this.random = new Random();

 

^ That's how you get a random instance. :)

 

Also, as a suggestion, I would use the Forge method

getDrops(world, x, y, z, metadata, fortune)

. It's much more versatile.

  • Author

private Random;

<-- declare at the top of your class (or bottom, however you like to do it)

 

Then in your block constructor, add:

 

this.random = new Random();

 

^ That's how you get a random instance. :)

 

Also, as a suggestion, I would use the Forge method

getDrops(world, x, y, z, metadata, fortune)

. It's much more versatile.

 

Ok, i've witten this code, but now it only drops vanilla saplings with metadata 0 (oak sapling):

    private Random random = new Random();

    @Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
    {
    	ArrayList<ItemStack> drops = new ArrayList<ItemStack>();

    	if (random.nextInt(10) == 0)
    	{
    		drops.add(new ItemStack(Blocks.ToLSapling));
    	}

    	else
    	{
    		drops.add(new ItemStack(net.minecraft.init.Blocks.sapling, 1, random.nextInt(5)));
    	}

    	return drops;
    }

 

Please tell me if made any mistake.

 

Thanks

  • Author

Are you absolutely sure? What you have there is basically a 1 in 10 chance for your sapling and then an equal chance for all vanilla saplings (except dark oak).

That means you might very well get like a couple oak saplings in a row.

 

Yes, i am.

The problem is that the method

damageDropped

from the extended class (net.minecraft.block.BlockLeaves) was setting the damage to 0.

 

But i don't know how to fix it  :(

  • Author

I've solved it by another way (which seems to work):

 

private Random random = new Random();

private Item itemDropped = null;
private int damageDropped;

@Override
public Item getItemDropped(int par1, Random rand, int par3)
{
	if(rand.nextInt(10) == 0)
	{
		if(rand.nextInt(10) == 0)
		{
			itemDropped = Item.getItemFromBlock(Blocks.ToLSapling);
		}

		else
		{
			itemDropped = Item.getItemFromBlock(net.minecraft.init.Blocks.sapling);
		}
	}

	return itemDropped;
}

@Override
public int damageDropped(int par1)
{
	if(itemDropped == Item.getItemFromBlock(Blocks.ToLSapling))
	{
		damageDropped = 0;
	}

	else
	{
		damageDropped = random.nextInt(6);
	}

	return damageDropped;
}

 

But any way, thanks to every one who helped

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.