Java Code Examples for net.minecraft.util.MathHelper.getRandomIntegerInRange()

The following are Jave code examples for showing how to use getRandomIntegerInRange() of the net.minecraft.util.MathHelper class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: BaseClient   File: MusicTicker.java   Source Code and License Vote up 6 votes
/**
 * Like the old updateEntity(), except more generic.
 */
public void update()
{
    MusicTicker.MusicType musicticker$musictype = this.mc.getAmbientMusicType();

    if (this.currentMusic != null)
    {
        if (!musicticker$musictype.getMusicLocation().equals(this.currentMusic.getSoundLocation()))
        {
            this.mc.getSoundHandler().stopSound(this.currentMusic);
            this.timeUntilNextMusic = MathHelper.getRandomIntegerInRange(this.rand, 0, musicticker$musictype.getMinDelay() / 2);
        }

        if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
        {
            this.currentMusic = null;
            this.timeUntilNextMusic = Math.min(MathHelper.getRandomIntegerInRange(this.rand, musicticker$musictype.getMinDelay(), musicticker$musictype.getMaxDelay()), this.timeUntilNextMusic);
        }
    }

    if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
    {
        this.func_181558_a(musicticker$musictype);
    }
}
 
Example 2
Project: BaseClient   File: MusicTicker.java   Source Code and License Vote up 6 votes
/**
 * Like the old updateEntity(), except more generic.
 */
public void update()
{
    MusicTicker.MusicType musicticker$musictype = this.mc.getAmbientMusicType();

    if (this.currentMusic != null)
    {
        if (!musicticker$musictype.getMusicLocation().equals(this.currentMusic.getSoundLocation()))
        {
            this.mc.getSoundHandler().stopSound(this.currentMusic);
            this.timeUntilNextMusic = MathHelper.getRandomIntegerInRange(this.rand, 0, musicticker$musictype.getMinDelay() / 2);
        }

        if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
        {
            this.currentMusic = null;
            this.timeUntilNextMusic = Math.min(MathHelper.getRandomIntegerInRange(this.rand, musicticker$musictype.getMinDelay(), musicticker$musictype.getMaxDelay()), this.timeUntilNextMusic);
        }
    }

    if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
    {
        this.func_181558_a(musicticker$musictype);
    }
}
 
Example 3
Project: BaseClient   File: BlockOre.java   Source Code and License Vote up 5 votes
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);

    if (this.getItemDropped(state, worldIn.rand, fortune) != Item.getItemFromBlock(this))
    {
        int i = 0;

        if (this == Blocks.coal_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 0, 2);
        }
        else if (this == Blocks.diamond_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.emerald_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.lapis_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }
        else if (this == Blocks.quartz_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }

        this.dropXpOnBlockBreak(worldIn, pos, i);
    }
}
 
Example 4
Project: BaseClient   File: EntityVillager.java   Source Code and License Vote up 5 votes
public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
{
    Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)];
    int i = MathHelper.getRandomIntegerInRange(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
    ItemStack itemstack = Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, i));
    int j = 2 + random.nextInt(5 + i * 10) + 3 * i;

    if (j > 64)
    {
        j = 64;
    }

    recipeList.add(new MerchantRecipe(new ItemStack(Items.book), new ItemStack(Items.emerald, j), itemstack));
}
 
Example 5
Project: BaseClient   File: BlockCrops.java   Source Code and License Vote up 5 votes
public void grow(World worldIn, BlockPos pos, IBlockState state)
{
    int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);

    if (i > 7)
    {
        i = 7;
    }

    worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i)), 2);
}
 
Example 6
Project: BaseClient   File: BlockOre.java   Source Code and License Vote up 5 votes
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);

    if (this.getItemDropped(state, worldIn.rand, fortune) != Item.getItemFromBlock(this))
    {
        int i = 0;

        if (this == Blocks.coal_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 0, 2);
        }
        else if (this == Blocks.diamond_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.emerald_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.lapis_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }
        else if (this == Blocks.quartz_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }

        this.dropXpOnBlockBreak(worldIn, pos, i);
    }
}
 
Example 7
Project: BaseClient   File: BlockStem.java   Source Code and License Vote up 4 votes
public void growStem(World worldIn, BlockPos pos, IBlockState state)
{
    int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
    worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(Math.min(7, i))), 2);
}
 
Example 8
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static int nextInt(Random p_nextInt_0_, int p_nextInt_1_, int p_nextInt_2_)
{
    return MathHelper.getRandomIntegerInRange(p_nextInt_0_, p_nextInt_1_, p_nextInt_2_);
}
 
Example 9
Project: BaseClient   File: BlockStem.java   Source Code and License Vote up 4 votes
public void growStem(World worldIn, BlockPos pos, IBlockState state) {
	int i = ((Integer) state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
	worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(Math.min(7, i))), 2);
}