Java Code Examples for net.minecraft.entity.item.EntityItem#playSound()

The following examples show how to use net.minecraft.entity.item.EntityItem#playSound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemHeavyChain.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block instanceof BlockCauldron && side == 1 && itemStack.getItemDamage() == 0) {
        int waterLevel = BlockCauldron.func_150027_b(meta);
        if (waterLevel == 0)
            return false;

        ItemStack newItem = new ItemStack(ModBlocks.heavyChain, 1, 3);
        itemStack.stackSize--;

        EntityItem itemEntity = new EntityItem(world, x + .5, y + 1.5, z + .5, newItem);
        itemEntity.playSound("random.splash", 0.25F, 1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.4F);

        world.spawnEntityInWorld(itemEntity);
        return true;
    }

    return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
 
Example 2
Source File: ItemLatticeMetal.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block instanceof BlockCauldron && side == 1 && itemStack.getItemDamage() == 0) {
        int waterLevel = BlockCauldron.func_150027_b(meta);
        if (waterLevel == 0)
            return false;

        ItemStack newItem = new ItemStack(ModBlocks.latticeMetal, 1, 1);
        itemStack.stackSize--;

        EntityItem itemEntity = new EntityItem(world, x + .5, y + 1.5, z + .5, newItem);
        itemEntity.playSound("random.splash", 0.25F, 1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.4F);

        world.spawnEntityInWorld(itemEntity);
        return true;
    }

    return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
 
Example 3
Source File: ItemLightChain.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block instanceof BlockCauldron && side == 1 && itemStack.getItemDamage() == 0) {
        int waterLevel = BlockCauldron.func_150027_b(meta);
        if (waterLevel == 0)
            return false;

        ItemStack newItem = new ItemStack(ModBlocks.lightChain, 1, 3);
        itemStack.stackSize--;

        EntityItem itemEntity = new EntityItem(world, x + .5, y + 1.5, z + .5, newItem);
        itemEntity.playSound("random.splash", 0.25F, 1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.4F);

        world.spawnEntityInWorld(itemEntity);
        return true;
    }

    return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
 
Example 4
Source File: BlockFlyingFlower.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.FLYING_FLOWER_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = (rand.nextFloat() - 0.5F) / 4F;
        plant.motionY = rand.nextFloat() * 0.2F;
        plant.motionZ = (rand.nextFloat() - 0.5F) / 4F;
        plant.lifespan = 1200;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, 4, 3);
    }
}
 
Example 5
Source File: BlockHeliumPlant.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.HELIUM_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.2D, z + 0.5D, seed);
        plant.motionX = rand.nextFloat() - 0.5F;
        plant.motionY = -1.0F;
        plant.motionZ = rand.nextFloat() - 0.5F;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, 4, 3);
    }
}
 
Example 6
Source File: BlockFireFlower.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(world.getBlockMetadata(x, y, z) == 14) {
        world.setBlockMetadataWithNotify(x, y, z, 11, 3);
        if(!world.isRemote) {
            ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.FIRE_FLOWER_DAMAGE);
            EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
            plant.motionX = (rand.nextFloat() - 0.5F) / 2;
            plant.motionY = 0.5F;
            plant.motionZ = (rand.nextFloat() - 0.5F) / 2;
            plant.lifespan = 300;
            ItemPlasticPlants.markInactive(plant);
            world.spawnEntityInWorld(plant);
            plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        }
    } else {
        world.setBlockMetadataWithNotify(x, y, z, 14, 2);
        world.scheduleBlockUpdate(x, y, z, this, 60);
    }
}
 
Example 7
Source File: BlockPropulsionPlant.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.PROPULSION_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = (rand.nextDouble() * 0.3D + 0.1D) * rand.nextInt(2) == 0 ? 1 : -1;
        plant.motionY = 0.1F;
        plant.motionZ = (rand.nextDouble() * 0.3D + 0.1D) * rand.nextInt(2) == 0 ? 1 : -1;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 8
Source File: BlockBurstPlant.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.BURST_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = rand.nextFloat() - 0.5F;
        plant.motionY = 1.0F;
        plant.motionZ = rand.nextFloat() - 0.5F;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 9
Source File: BlockRepulsionPlant.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.REPULSION_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = (rand.nextFloat() - 0.5F) / 2;
        plant.motionY = 0.7F;
        plant.motionZ = (rand.nextFloat() - 0.5F) / 2;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 10
Source File: BlockEnderPlant.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        for(int i = 0; i < 50; i++) {
            int randX = x + rand.nextInt(30) - 15;
            int randY = y + rand.nextInt(8);
            int randZ = z + rand.nextInt(30) - 15;
            Block block = world.getBlock(randX, randY, randZ);
            if(!block.getMaterial().blocksMovement()) {
                ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.ENDER_PLANT_DAMAGE);
                EntityItem plant = new EntityItem(world, randX + 0.5D, randY + 0.5D, randZ + 0.5D, seed);
                // plant.motionX = plant.motionY = plant.motionZ = 0;
                plant.lifespan = 300;
                ItemPlasticPlants.markInactive(plant);
                world.spawnEntityInWorld(plant);
                plant.playSound("mob.endermen.portal", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                short short1 = 128;
                for(int j = 0; j < short1; ++j) {
                    double d6 = j / (short1 - 1.0D);
                    float f = (rand.nextFloat() - 0.5F) * 0.2F;
                    float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
                    float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
                    double d7 = x + 0.5D + (plant.posX - (x + 0.5D)) * d6 + (rand.nextDouble() - 0.5D);
                    double d8 = y + 0.5D + (plant.posY - (y + 0.5D)) * d6 + rand.nextDouble();
                    double d9 = z + 0.5D + (plant.posZ - (z + 0.5D)) * d6 + (rand.nextDouble() - 0.5D);
                    NetworkHandler.sendToAllAround(new PacketSpawnParticle("portal", d7, d8, d9, f, f1, f2), world);
                }
                world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
                break;
            }
        }

    }
}
 
Example 11
Source File: ItemPlasticPlants.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onEntityItemUpdate(EntityItem entityItem){
    MotionProperties motProps = (MotionProperties)entityItem.getExtendedProperties("plasticPlant");
    double oldMotionX = entityItem.motionX;
    double oldMotionY = entityItem.motionY;
    double oldMotionZ = entityItem.motionZ;
    if(motProps != null) {
        oldMotionX = motProps.oldMotionX;
        oldMotionY = motProps.oldMotionY;
        oldMotionZ = motProps.oldMotionZ;
    }

    ItemStack stack = entityItem.getEntityItem();
    int itemDamage = stack.getItemDamage();

    if(motProps == null && (itemDamage % 16 == ItemPlasticPlants.PROPULSION_PLANT_DAMAGE || itemDamage % 16 == ItemPlasticPlants.REPULSION_PLANT_DAMAGE)) {
        motProps = new MotionProperties();
        entityItem.registerExtendedProperties("plasticPlant", motProps);
    }
    if(motProps != null) motProps.update(entityItem);

    boolean isDelayOver = isActive(entityItem) || entityItem.age > 60 && entityItem.delayBeforeCanPickup == 0;
    if(entityItem.onGround || Math.abs(entityItem.motionY) < 0.13D && (itemDamage % 16 == ItemPlasticPlants.HELIUM_PLANT_DAMAGE || itemDamage % 16 == ItemPlasticPlants.SQUID_PLANT_DAMAGE)) {
        if(!handleRepulsionBehaviour(entityItem, oldMotionX, oldMotionY, oldMotionZ)) return false;
        if(!handlePropulsionBehaviour(entityItem, oldMotionX, oldMotionZ)) return false;
        if(!entityItem.worldObj.isRemote) {
            Block blockID = getPlantBlockIDFromSeed(itemDamage % 16);
            int landedBlockX = (int)Math.floor(entityItem.posX);// - 0.5F);
            int landedBlockY = (int)Math.floor(entityItem.posY);
            int landedBlockZ = (int)Math.floor(entityItem.posZ);// - 0.5F);

            boolean canSustain = false;

            canSustain = ((BlockPneumaticPlantBase)blockID).canBlockStay(entityItem.worldObj, landedBlockX, landedBlockY, landedBlockZ);
            if(itemDamage % 16 == ItemPlasticPlants.FIRE_FLOWER_DAMAGE && !canSustain && !isInChamber(entityItem.worldObj.getBlock(landedBlockX, landedBlockY - 1, landedBlockZ)) && net.minecraft.init.Blocks.fire.canPlaceBlockAt(entityItem.worldObj, landedBlockX, landedBlockY, landedBlockZ) && entityItem.worldObj.isAirBlock(landedBlockX, landedBlockY, landedBlockZ)) {
                entityItem.worldObj.setBlock(landedBlockX, landedBlockY, landedBlockZ, net.minecraft.init.Blocks.fire);
            }

            if(canSustain && isDelayOver) {
                if(entityItem.worldObj.isAirBlock(landedBlockX, landedBlockY, landedBlockZ)) {

                    entityItem.worldObj.setBlock(landedBlockX, landedBlockY, landedBlockZ, blockID, itemDamage > 15 || !isActive(entityItem) ? 0 : 7, 3);

                    entityItem.playSound("mob.chicken.plop", 1.0F, (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
                    for(int i = 0; i < 10; i++) {
                        spawnParticle(entityItem.worldObj, "explode", entityItem.posX + rand.nextDouble() - 0.5D, entityItem.posY + rand.nextDouble() - 0.5D, entityItem.posZ + rand.nextDouble() - 0.5D, 0.0D, 0.0D, 0.0D);
                    }
                    if(stack.stackSize == 1) {
                        entityItem.setDead();
                    } else {
                        stack.stackSize--;
                    }
                }
            }
        }
    }

    // when the entity on the ground check whether the block beneath it is
    // dirt, and the block above it is air, if yes, then plant it.
    if(itemDamage % 16 == ItemPlasticPlants.SQUID_PLANT_DAMAGE && entityItem.worldObj.isMaterialInBB(entityItem.boundingBox.contract(0.003D, 0.003D, 0.003D), Material.water)) {
        entityItem.motionY += 0.06D;
    }
    if(itemDamage % 16 == ItemPlasticPlants.HELIUM_PLANT_DAMAGE) {
        entityItem.motionY += 0.08D;
    }
    if(itemDamage % 16 == ItemPlasticPlants.FLYING_FLOWER_DAMAGE) {
        entityItem.motionY += 0.04D;
        if(entityItem.age % 60 == 0) {
            entityItem.motionX += (rand.nextDouble() - 0.5D) * 0.1D;
            entityItem.motionY += (rand.nextDouble() - 0.6D) * 0.1D;
            entityItem.motionZ += (rand.nextDouble() - 0.5D) * 0.1D;
        }
    }
    return false;
}