Jump to content

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


SackCastellon

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.