Java Code Examples for java.util.Random.nextFloat()

The following are Jave code examples for showing how to use nextFloat() of the java.util.Random class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: JVMStartupRunner.java   View Source Code Vote up 6 votes
/**
 * Returns {@code unscaledSize} value scaled by a random factor from
 * range (1, 2). If {@code unscaledSize} is not 0, then this
 * method will return value that won't be equal to {@code unscaledSize}.
 *
 * @param unscaledSize The value to be scaled.
 * @return {@code unscaledSize} value scaled by a factor from range (1, 2).
 */
private static long scaleCodeHeapSize(long unscaledSize) {
    Random random = Utils.getRandomInstance();

    long scaledSize = unscaledSize;
    while (scaledSize == unscaledSize && unscaledSize != 0) {
        float scale = 1.0f + random.nextFloat();
        scaledSize = (long) Math.ceil(scale * unscaledSize);
    }
    return scaledSize;
}
 
Example 2
Project: DecompiledMinecraft   File: BlockRedstoneRepeater.java   View Source Code Vote up 6 votes
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (this.isRepeaterPowered)
    {
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
        double d0 = (double)((float)pos.getX() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        double d1 = (double)((float)pos.getY() + 0.4F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        double d2 = (double)((float)pos.getZ() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        float f = -5.0F;

        if (rand.nextBoolean())
        {
            f = (float)(((Integer)state.getValue(DELAY)).intValue() * 2 - 1);
        }

        f = f / 16.0F;
        double d3 = (double)(f * (float)enumfacing.getFrontOffsetX());
        double d4 = (double)(f * (float)enumfacing.getFrontOffsetZ());
        worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
    }
}
 
Example 3
Project: logistimo-web-service   File: AuthenticationServiceImpl.java   View Source Code Vote up 6 votes
@Override
public String generatePassword(String id) {
  if (id == null || id.isEmpty()) {
    return null;
  }
  String password = null;
  // Take the first 4 letters of id
  if (id.length() <= 4) {
    password = id;
  } else {
    password = id.substring(0, 4);
  }
  // Generate a 3 digit random number
  Random r = new Random();
  r.setSeed(System.currentTimeMillis());
  float f = r.nextFloat();
  password += String.valueOf((int) ((f * 1000.0f) % 1000));
  return password;
}
 
Example 4
Project: harshencastle   File: ChestGenerator.java   View Source Code Vote up 6 votes
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {
	if(size.equals(BlockPos.ORIGIN) && rand.nextFloat() < this.chance)
	{
		worldIn.setBlockState(position, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.HORIZONTALS[rand.nextInt(4)]), 3);
		((TileEntityChest)worldIn.getTileEntity(position)).setLootTable(lootTable, rand.nextLong());
		return false;
	}
	for(int x = 0; x < size.getX(); x++)
		for(int z = 0; z < size.getZ(); z++)
			if(rand.nextFloat() < this.chance)
			{
				BlockPos blockpos = new BlockPos(position.add(x, 0, z));
				boolean flag = false;
				for(EnumFacing facing : EnumFacing.HORIZONTALS)
					if(worldIn.getBlockState(blockpos.offset(facing)).getBlock() == Blocks.CHEST)
						flag = true;
				if(flag || !worldIn.isAirBlock(blockpos))
					continue;
				if(setBlock)
					worldIn.setBlockState(blockpos, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.HORIZONTALS[rand.nextInt(4)]), 3);
				((TileEntityChest)worldIn.getTileEntity(blockpos)).setLootTable(lootTable, rand.nextLong());
			}
	return false;
}
 
Example 5
Project: prngine   File: PRNG.java   View Source Code Vote up 6 votes
/**
 * Returns a pseudo-random, uniformly distributed double value between
 * origin (inclusively) and bound (exclusively).
 *
 * @param origin lower bound for generated float value (inclusively)
 * @param bound upper bound for generated float value (exclusively)
 * @param random the random engine used for creating the random number.
 * @return a random float greater than or equal to {@code origin} and less
 *         than to {@code bound}
 * @throws IllegalArgumentException if {@code origin} is greater than or
 *         equal to {@code bound}
 * @throws NullPointerException if the given {@code random}
 *         engine is {@code null}.
 */
public static float nextFloat(
	final float origin, final float bound,
	final Random random
) {
	if (!(origin < bound)) {
		throw new IllegalArgumentException(format(
			"min >= max: %f >= %f.", origin, bound
		));
	}

	float value = random.nextFloat();
	if (origin < bound) {
		value = value*(bound - origin) + origin;
		if (value >= bound) {
			value = intBitsToFloat(floatToIntBits(bound) - 1);
		}
	}

	return value;
}
 
Example 6
Project: nat-network-transfer   File: TransferModule.java   View Source Code Vote up 5 votes
private File getDownloadFile(Uri targetUri) throws IOException {
    String fileName;
    Random random = new Random();
    float v = random.nextFloat();
    try {
        fileName = Util.getMD5("nat/transfer/download" + System.currentTimeMillis()) + v;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        fileName = "nat/transfer/download" + System.currentTimeMillis() + v;
    }
    File parentFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + targetUri.getPath());
    if (!parentFile.exists()) parentFile.mkdirs();

    return new File(parentFile, fileName);
}
 
Example 7
Project: summer17-android   File: Level2.java   View Source Code Vote up 5 votes
public void updateMushroom() {
    if (cam.position.x - cam.viewportWidth / 2 > mushroom.getPosObs().x + mushroom.getWidth()) {
        Random rand = new Random();
        float fluctuation = rand.nextFloat();
        float distance = (fluctuation * 2500) + GameTutorial.WIDTH;
        mushroom.reposition(mushroom.getPosObs().x + distance, 70);
        mushroomIsTouched = false;
    }
}
 
Example 8
Project: summer17-android   File: Level4.java   View Source Code Vote up 5 votes
public void updatePoops(){
    if (cam.position.x - cam.viewportWidth / 2 > poop.getPosObs().x + poop.getWidth()) {
        Random rand = new Random();
        float fluctuation = rand.nextFloat();
        float distance = (fluctuation * 1500) + GameTutorial.WIDTH;
        poop.reposition(poop.getPosObs().x + distance, 60);
        poopIsTouched = false;
    }
}
 
Example 9
Project: harshencastle   File: WorldGen.java   View Source Code Vote up 5 votes
private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chancesPerChunk, float chancesToSpawn, int minHeight, int maxHeight) 
{
	int heightDiff = maxHeight - minHeight + 1;
    for (int i = 0; i < chancesPerChunk; i ++) 
    	if(random.nextFloat() < chancesToSpawn)
    	{
    		int x = chunkX * 16 + random.nextInt(16);
	        int y = minHeight + random.nextInt(heightDiff);
	        int z = chunkZ * 16 + random.nextInt(16);
	        generator.generate(world, random, new BlockPos(x, y, z));
    	} 
}
 
Example 10
Project: angel   File: Utils.java   View Source Code Vote up 5 votes
public static float[] genFloatArray(int dim) {
  Random random = new Random(System.currentTimeMillis());
  float[] array = new float[dim];
  for (int i = 0; i < dim; i++)
    array[i] = random.nextFloat();

  return array;
}
 
Example 11
Project: morefurnaces   File: BlockMoreFurnaces.java   View Source Code Vote up 5 votes
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random)
{
    TileEntity te = world.getTileEntity(pos);
    if (te != null && te instanceof TileEntityIronFurnace)
    {
        TileEntityIronFurnace tef = (TileEntityIronFurnace) te;
        if (tef.isActive())
        {
            byte facing = tef.getFacing();
            float x = pos.getX() + 0.5F;
            float y = pos.getY() + 0.0F + random.nextFloat() * 6.0F / 16.0F;
            float z = pos.getZ() + 0.5F;
            float var10 = 0.52F;
            float var11 = random.nextFloat() * 0.6F - 0.3F;

            if (facing == 4)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x - var10, y, z + var11, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x - var10, y, z + var11, 0.0D, 0.0D, 0.0D);
            } else if (facing == 5)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var10, y, z + var11, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var10, y, z + var11, 0.0D, 0.0D, 0.0D);
            } else if (facing == 2)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var11, y, z - var10, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var11, y, z - var10, 0.0D, 0.0D, 0.0D);
            } else if (facing == 3)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var11, y, z + var10, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var11, y, z + var10, 0.0D, 0.0D, 0.0D);
            }
        }
    }
}
 
Example 12
Project: DecompiledMinecraft   File: BlockEndPortal.java   View Source Code Vote up 5 votes
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    double d0 = (double)((float)pos.getX() + rand.nextFloat());
    double d1 = (double)((float)pos.getY() + 0.8F);
    double d2 = (double)((float)pos.getZ() + rand.nextFloat());
    double d3 = 0.0D;
    double d4 = 0.0D;
    double d5 = 0.0D;
    worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
}
 
Example 13
Project: Backmemed   File: ComponentScatteredFeaturePieces.java   View Source Code Vote up 5 votes
public void selectBlocks(Random rand, int x, int y, int z, boolean p_75062_5_)
{
    if (rand.nextFloat() < 0.4F)
    {
        this.blockstate = Blocks.COBBLESTONE.getDefaultState();
    }
    else
    {
        this.blockstate = Blocks.MOSSY_COBBLESTONE.getDefaultState();
    }
}
 
Example 14
Project: CustomWorldGen   File: LayerEnderDragonDeath.java   View Source Code Vote up 4 votes
public void doRenderLayer(EntityDragon entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale)
{
    if (entitylivingbaseIn.deathTicks > 0)
    {
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer vertexbuffer = tessellator.getBuffer();
        RenderHelper.disableStandardItemLighting();
        float f = ((float)entitylivingbaseIn.deathTicks + partialTicks) / 200.0F;
        float f1 = 0.0F;

        if (f > 0.8F)
        {
            f1 = (f - 0.8F) / 0.2F;
        }

        Random random = new Random(432L);
        GlStateManager.disableTexture2D();
        GlStateManager.shadeModel(7425);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
        GlStateManager.disableAlpha();
        GlStateManager.enableCull();
        GlStateManager.depthMask(false);
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.0F, -1.0F, -2.0F);

        for (int i = 0; (float)i < (f + f * f) / 2.0F * 60.0F; ++i)
        {
            GlStateManager.rotate(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F + f * 90.0F, 0.0F, 0.0F, 1.0F);
            float f2 = random.nextFloat() * 20.0F + 5.0F + f1 * 10.0F;
            float f3 = random.nextFloat() * 2.0F + 1.0F + f1 * 2.0F;
            vertexbuffer.begin(6, DefaultVertexFormats.POSITION_COLOR);
            vertexbuffer.pos(0.0D, 0.0D, 0.0D).color(255, 255, 255, (int)(255.0F * (1.0F - f1))).endVertex();
            vertexbuffer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(0.0D, (double)f2, (double)(1.0F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            tessellator.draw();
        }

        GlStateManager.popMatrix();
        GlStateManager.depthMask(true);
        GlStateManager.disableCull();
        GlStateManager.disableBlend();
        GlStateManager.shadeModel(7424);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.enableTexture2D();
        GlStateManager.enableAlpha();
        RenderHelper.enableStandardItemLighting();
    }
}
 
Example 15
Project: TRAPPIST-1   File: SkyProviderTrappistOneC.java   View Source Code Vote up 4 votes
private void renderStars()
{
    final Random rand = new Random(10842L);
    final Tessellator var2 = Tessellator.instance;
    var2.startDrawingQuads();

    for (int starIndex = 0; starIndex < (ConfigManagerCore.moreStars ? 35000 : 6000); ++starIndex)
    {
        double var4 = rand.nextFloat() * 2.0F - 1.0F;
        double var6 = rand.nextFloat() * 2.0F - 1.0F;
        double var8 = rand.nextFloat() * 2.0F - 1.0F;
        final double var10 = 0.15F + rand.nextFloat() * 0.1F;
        double var12 = var4 * var4 + var6 * var6 + var8 * var8;

        if (var12 < 1.0D && var12 > 0.01D)
        {
            var12 = 1.0D / Math.sqrt(var12);
            var4 *= var12;
            var6 *= var12;
            var8 *= var12;
            final double var14 = var4 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var16 = var6 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var18 = var8 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var20 = Math.atan2(var4, var8);
            final double var22 = Math.sin(var20);
            final double var24 = Math.cos(var20);
            final double var26 = Math.atan2(Math.sqrt(var4 * var4 + var8 * var8), var6);
            final double var28 = Math.sin(var26);
            final double var30 = Math.cos(var26);
            final double var32 = rand.nextDouble() * Math.PI * 2.0D;
            final double var34 = Math.sin(var32);
            final double var36 = Math.cos(var32);

            for (int var38 = 0; var38 < 4; ++var38)
            {
                final double var39 = 0.0D;
                final double var41 = ((var38 & 2) - 1) * var10;
                final double var43 = ((var38 + 1 & 2) - 1) * var10;
                final double var47 = var41 * var36 - var43 * var34;
                final double var49 = var43 * var36 + var41 * var34;
                final double var53 = var47 * var28 + var39 * var30;
                final double var55 = var39 * var28 - var47 * var30;
                final double var57 = var55 * var22 - var49 * var24;
                final double var61 = var49 * var22 + var55 * var24;
                var2.addVertex(var14 + var57, var16 + var53, var18 + var61);
            }
        }
    }

    var2.draw();
}
 
Example 16
Project: Backmemed   File: RenderGlobal.java   View Source Code Vote up 4 votes
private void renderStars(VertexBuffer worldRendererIn)
{
    Random random = new Random(10842L);
    worldRendererIn.begin(7, DefaultVertexFormats.POSITION);

    for (int i = 0; i < 1500; ++i)
    {
        double d0 = (double)(random.nextFloat() * 2.0F - 1.0F);
        double d1 = (double)(random.nextFloat() * 2.0F - 1.0F);
        double d2 = (double)(random.nextFloat() * 2.0F - 1.0F);
        double d3 = (double)(0.15F + random.nextFloat() * 0.1F);
        double d4 = d0 * d0 + d1 * d1 + d2 * d2;

        if (d4 < 1.0D && d4 > 0.01D)
        {
            d4 = 1.0D / Math.sqrt(d4);
            d0 = d0 * d4;
            d1 = d1 * d4;
            d2 = d2 * d4;
            double d5 = d0 * 100.0D;
            double d6 = d1 * 100.0D;
            double d7 = d2 * 100.0D;
            double d8 = Math.atan2(d0, d2);
            double d9 = Math.sin(d8);
            double d10 = Math.cos(d8);
            double d11 = Math.atan2(Math.sqrt(d0 * d0 + d2 * d2), d1);
            double d12 = Math.sin(d11);
            double d13 = Math.cos(d11);
            double d14 = random.nextDouble() * Math.PI * 2.0D;
            double d15 = Math.sin(d14);
            double d16 = Math.cos(d14);

            for (int j = 0; j < 4; ++j)
            {
                double d17 = 0.0D;
                double d18 = (double)((j & 2) - 1) * d3;
                double d19 = (double)((j + 1 & 2) - 1) * d3;
                double d20 = 0.0D;
                double d21 = d18 * d16 - d19 * d15;
                double d22 = d19 * d16 + d18 * d15;
                double d23 = d21 * d12 + 0.0D * d13;
                double d24 = 0.0D * d12 - d21 * d13;
                double d25 = d24 * d9 - d22 * d10;
                double d26 = d22 * d9 + d24 * d10;
                worldRendererIn.pos(d5 + d25, d6 + d23, d7 + d26).endVertex();
            }
        }
    }
}
 
Example 17
Project: DecompiledMinecraft   File: LayerArrow.java   View Source Code Vote up 4 votes
public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale)
{
    int i = entitylivingbaseIn.getArrowCountInEntity();

    if (i > 0)
    {
        Entity entity = new EntityArrow(entitylivingbaseIn.worldObj, entitylivingbaseIn.posX, entitylivingbaseIn.posY, entitylivingbaseIn.posZ);
        Random random = new Random((long)entitylivingbaseIn.getEntityId());
        RenderHelper.disableStandardItemLighting();

        for (int j = 0; j < i; ++j)
        {
            GlStateManager.pushMatrix();
            ModelRenderer modelrenderer = this.field_177168_a.getMainModel().getRandomModelBox(random);
            ModelBox modelbox = (ModelBox)modelrenderer.cubeList.get(random.nextInt(modelrenderer.cubeList.size()));
            modelrenderer.postRender(0.0625F);
            float f = random.nextFloat();
            float f1 = random.nextFloat();
            float f2 = random.nextFloat();
            float f3 = (modelbox.posX1 + (modelbox.posX2 - modelbox.posX1) * f) / 16.0F;
            float f4 = (modelbox.posY1 + (modelbox.posY2 - modelbox.posY1) * f1) / 16.0F;
            float f5 = (modelbox.posZ1 + (modelbox.posZ2 - modelbox.posZ1) * f2) / 16.0F;
            GlStateManager.translate(f3, f4, f5);
            f = f * 2.0F - 1.0F;
            f1 = f1 * 2.0F - 1.0F;
            f2 = f2 * 2.0F - 1.0F;
            f = f * -1.0F;
            f1 = f1 * -1.0F;
            f2 = f2 * -1.0F;
            float f6 = MathHelper.sqrt_float(f * f + f2 * f2);
            entity.prevRotationYaw = entity.rotationYaw = (float)(Math.atan2((double)f, (double)f2) * 180.0D / Math.PI);
            entity.prevRotationPitch = entity.rotationPitch = (float)(Math.atan2((double)f1, (double)f6) * 180.0D / Math.PI);
            double d0 = 0.0D;
            double d1 = 0.0D;
            double d2 = 0.0D;
            this.field_177168_a.getRenderManager().renderEntityWithPosYaw(entity, d0, d1, d2, 0.0F, partialTicks);
            GlStateManager.popMatrix();
        }

        RenderHelper.enableStandardItemLighting();
    }
}
 
Example 18
Project: betaexpansion   File: TexturePortalFX.java   View Source Code Vote up 4 votes
public void init(int r)
{
	isCustom = true;
    res = r;
    imageData = new byte[r*r*4];
    portalTickCounter = 0;
    portalTextureData = new byte[32][r*r*4];
    Random random = new Random(100L);
    for(int i = 0; i < 32; i++)
    {
        for(int j = 0; j < r; j++)
        {
            for(int k = 0; k < r; k++)
            {
                float f = 0.0F;
                for(int l = 0; l < 2; l++)
                {
                    float f1 = l * (r/2);
                    float f2 = l * (r/2);
                    float f3 = (((float)j - f1) / r) * 2.0F;
                    float f4 = (((float)k - f2) / r) * 2.0F;
                    if(f3 < -1F)
                    {
                        f3 += 2.0F;
                    }
                    if(f3 >= 1.0F)
                    {
                        f3 -= 2.0F;
                    }
                    if(f4 < -1F)
                    {
                        f4 += 2.0F;
                    }
                    if(f4 >= 1.0F)
                    {
                        f4 -= 2.0F;
                    }
                    float f5 = f3 * f3 + f4 * f4;
                    float f6 = (float)Math.atan2(f4, f3) + ((((float)i / 32F) * 3.141593F * 2.0F - f5 * 10F) + (float)(l * 2)) * (float)(l * 2 - 1);
                    f6 = (MathHelper.sin(f6) + 1.0F) / 2.0F;
                    f6 /= f5 + 1.0F;
                    f += f6 * 0.5F;
                }

                f += random.nextFloat() * 0.1F;
                int i1 = (int)(f * 100F + 155F);
                int j1 = (int)(f * f * 200F + 55F);
                int k1 = (int)(f * f * f * f * 255F);
                int l1 = (int)(f * 100F + 155F);
                int i2 = k * r + j;
                portalTextureData[i][i2 * 4 + 0] = (byte)j1;
                portalTextureData[i][i2 * 4 + 1] = (byte)k1;
                portalTextureData[i][i2 * 4 + 2] = (byte)i1;
                portalTextureData[i][i2 * 4 + 3] = (byte)l1;
            }

        }

    }
}
 
Example 19
Project: DecompiledMinecraft   File: EnchantmentDurability.java   View Source Code Vote up 2 votes
/**
 * Used by ItemStack.attemptDamageItem. Randomly determines if a point of damage should be negated using the
 * enchantment level (par1). If the ItemStack is Armor then there is a flat 60% chance for damage to be negated no
 * matter the enchantment level, otherwise there is a 1-(par/1) chance for damage to be negated.
 */
public static boolean negateDamage(ItemStack p_92097_0_, int p_92097_1_, Random p_92097_2_)
{
    return p_92097_0_.getItem() instanceof ItemArmor && p_92097_2_.nextFloat() < 0.6F ? false : p_92097_2_.nextInt(p_92097_1_ + 1) > 0;
}
 
Example 20
Project: CustomWorldGen   File: EnchantmentDurability.java   View Source Code Vote up 2 votes
/**
 * Used by ItemStack.attemptDamageItem. Randomly determines if a point of damage should be negated using the
 * enchantment level (par1). If the ItemStack is Armor then there is a flat 60% chance for damage to be negated no
 * matter the enchantment level, otherwise there is a 1-(par/1) chance for damage to be negated.
 */
public static boolean negateDamage(ItemStack p_92097_0_, int p_92097_1_, Random p_92097_2_)
{
    return p_92097_0_.getItem() instanceof ItemArmor && p_92097_2_.nextFloat() < 0.6F ? false : p_92097_2_.nextInt(p_92097_1_ + 1) > 0;
}