R/extractMobNames.R

#' Extract mob names from mob stat ID
#' 
#' Extract common mob names from a list of mob stats. Uses \code{strings.mobs} for 
#' substitutions of some mob names.
#' @keywords entities
#' @param stat The mob stat(s) from which mob names should be extracted
#' @param mobData Dataset of descirptive strings, defaults to \link[wurstmineR]{strings.mobs}
#' @return Vector of mob names, adjusted for readability
#' @export
#' @note Required to produce \code{mobStats}, see \link[wurstmineR]{getMobStats}
#' @examples
#' extractMobNames(stat = "killEntity.PigZombie", mobData = wurstmineR::strings.mobs)
extractMobNames <- function(stat = NULL, mobData = NULL){
  if (is.null(mobData)){
    mobData <- wurstmineR::strings.mobs
  }
  mob <- sub("entityKilledBy.", "", stat)
  mob <- sub("killEntity.", "", mob)
  mob <- lapply(mob, function(mob){
    if (mob %in% mobData$id){
      sub(mob, mobData$name[mobData$id == mob], mob)
    } else {mob}
  })
  mob <- unlist(mob)
  return(mob)
}
jemus42/wurstmineR documentation built on May 19, 2019, 4:03 a.m.