So I know gravel has a 10% chance of dropping flint. The code for that is this:
public int idDropped(int i, Random random)
{
if(random.nextInt(10) == 0)
{
return Item.flint.shiftedIndex;
} else
{
return blockID;
}
}
So explain to an idiot why if(random.nextInt(10) == 0) means 10%, and how I can change that to be higher or lower for my custom block.
Also, how would you make it so if the block doesn't drop flint, it doesn't drop anything? I am trying to make a block that drops random quantities of random items when destroyed, or drops nothing at all. Little help?
Random.nextInt(x) will return a number (integers only, hence the name) from 0 to x. I'm actually not sure if the upper bound is x or x-1; I'd expect x but that would actually make flint 1/11 chance (on the other hand who cares if it's 10% or 9%); I'm going to assume for the sake of argument here that x is the upper bound. So if I do "random.nextInt(3)", my possible outcomes are 0, 1, 2, or 3. Since 0 is one of the four possible outputs, that is a 1/4 or 25% chance. You can logically follow that nextInt(10) would have 11 possible outputs, and thus 0 is only one of the eleven, or 1/11 chance.
If you want to not drop anything, you can return -1 from idDropped or 0 from quantityDropped.
Random.nextInt(x) will return a number (integers only, hence the name) from 0 to x. I'm actually not sure if the upper bound is x or x-1; I'd expect x but that would actually make flint 1/11 chance (on the other hand who cares if it's 10% or 9%); I'm going to assume for the sake of argument here that x is the upper bound. So if I do "random.nextInt(3)", my possible outcomes are 0, 1, 2, or 3. Since 0 is one of the four possible outputs, that is a 1/4 or 25% chance. You can logically follow that nextInt(10) would have 11 possible outputs, and thus 0 is only one of the eleven, or 1/11 chance.
If you want to not drop anything, you can return -1 from idDropped or 0 from quantityDropped.
rand.nextInt(x) actually returns a number from 0 to (x - 1). The x describes the range of possible outcomes (if x is 10, there are 10 possible outcomes).
Rollback Post to RevisionRollBack
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then. WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
rand.nextInt(x) actually returns a number from 0 to (x - 1). The x describes the range of possible outcomes (if x is 10, there are 10 possible outcomes).
I take it you're new to this programming thing? :smile.gif: == is a test for equality. It will return true if the two sides are equal, so it will only be true if the nextInt call returns 0 as 1 (etc) is not equal to 0.
So explain to an idiot why if(random.nextInt(10) == 0) means 10%, and how I can change that to be higher or lower for my custom block.
Also, how would you make it so if the block doesn't drop flint, it doesn't drop anything? I am trying to make a block that drops random quantities of random items when destroyed, or drops nothing at all. Little help?
If you want to not drop anything, you can return -1 from idDropped or 0 from quantityDropped.
INFORMATION WANTS TO BE WRONG
rand.nextInt(x) actually returns a number from 0 to (x - 1). The x describes the range of possible outcomes (if x is 10, there are 10 possible outcomes).
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then.
WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
Huh, guess I was wrong. Thanks!
INFORMATION WANTS TO BE WRONG
I take it you're new to this programming thing? :smile.gif: == is a test for equality. It will return true if the two sides are equal, so it will only be true if the nextInt call returns 0 as 1 (etc) is not equal to 0.
INFORMATION WANTS TO BE WRONG