Class CommonTasks

java.lang.Object
net.dillon.dillonlib.task.CommonTasks

public class CommonTasks extends Object
Common tasks that can be used in your mod.
Since:
1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    executeIfPlayer(net.minecraft.world.entity.player.Player player, Consumer<net.minecraft.world.entity.player.Player> playerConsumer)
    Executes a task for a Player if they aren't null.
    static void
    executeIftLevel(net.minecraft.world.level.Level l, Consumer<net.minecraft.world.level.Level> levelConsumer)
    Executes a task of the current Level if it isn't null.
    static List
    getEntitiesWithinRange(net.minecraft.world.level.Level world, Class<? extends net.minecraft.world.entity.LivingEntity> entityListOf, net.minecraft.world.entity.LivingEntity startingPoint, List<Integer> xyz, Predicate<? super net.minecraft.world.entity.LivingEntity> selector)
     
    static net.minecraft.world.item.ItemStack
    getItemBySlot(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.EquipmentSlot slot)
     
    static net.minecraft.world.item.ItemStack
    getMainHandStack(net.minecraft.world.entity.player.Player player)
     
    static net.minecraft.world.item.ItemStack
    getOffHandStack(net.minecraft.world.entity.player.Player player)
     
    static boolean
    hasEffect(net.minecraft.world.item.ItemStack stack, String potionName)
     
    static boolean
    hasEnchantment(Predicate<net.minecraft.world.item.ItemStack> validStack, net.minecraft.resources.ResourceKey<net.minecraft.world.item.enchantment.Enchantment> enchantment, net.minecraft.world.item.ItemStack stack)
     
    static void
    playSoundFromLiving(net.minecraft.world.entity.LivingEntity living, net.minecraft.sounds.SoundEvent sound, net.minecraft.sounds.SoundSource source)
    Plays a sound to a LivingEntity.
    static void
    playSoundFromLiving(net.minecraft.world.entity.LivingEntity living, net.minecraft.sounds.SoundEvent sound, net.minecraft.sounds.SoundSource source, float volume, float pitch)
    Plays a sound to a LivingEntity, with a custom volume and pitch.
    static void
    schedule(int delayTicks, Runnable task)
    Schedules a task (executes after delayTicks).
    static void
    sendOverlayMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message)
    Sends an overlay message to a Player.
    static void
    sendSystemMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message)
    Sends a system message to a Player.
    static void
    sendUpdateMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component modName, String linkToUpdate, int textColor)
    Sends a message to the player indicating their mod requires an update.
    static void
    tickTasks(net.minecraft.server.MinecraftServer server)
    Tick the task delay, and then execute.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CommonTasks

      public CommonTasks()
  • Method Details

    • schedule

      public static void schedule(int delayTicks, Runnable task)
      Schedules a task (executes after delayTicks).
    • tickTasks

      public static void tickTasks(net.minecraft.server.MinecraftServer server)
      Tick the task delay, and then execute.
    • sendOverlayMessage

      public static void sendOverlayMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message)
      Sends an overlay message to a Player.
    • sendSystemMessage

      public static void sendSystemMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component message)
      Sends a system message to a Player.
    • sendUpdateMessage

      public static void sendUpdateMessage(net.minecraft.world.entity.player.Player player, net.minecraft.network.chat.Component modName, String linkToUpdate, int textColor)
      Sends a message to the player indicating their mod requires an update.
    • playSoundFromLiving

      public static void playSoundFromLiving(net.minecraft.world.entity.LivingEntity living, net.minecraft.sounds.SoundEvent sound, net.minecraft.sounds.SoundSource source)
      Plays a sound to a LivingEntity.
    • playSoundFromLiving

      public static void playSoundFromLiving(net.minecraft.world.entity.LivingEntity living, net.minecraft.sounds.SoundEvent sound, net.minecraft.sounds.SoundSource source, float volume, float pitch)
      Plays a sound to a LivingEntity, with a custom volume and pitch.
    • executeIfPlayer

      public static void executeIfPlayer(net.minecraft.world.entity.player.Player player, Consumer<net.minecraft.world.entity.player.Player> playerConsumer)
      Executes a task for a Player if they aren't null.
    • executeIftLevel

      public static void executeIftLevel(net.minecraft.world.level.Level l, Consumer<net.minecraft.world.level.Level> levelConsumer)
      Executes a task of the current Level if it isn't null.
    • getMainHandStack

      public static net.minecraft.world.item.ItemStack getMainHandStack(net.minecraft.world.entity.player.Player player)
      Returns:
      the player's main hand stack.
    • getOffHandStack

      public static net.minecraft.world.item.ItemStack getOffHandStack(net.minecraft.world.entity.player.Player player)
      Returns:
      the player's offhand stack.
    • getItemBySlot

      public static net.minecraft.world.item.ItemStack getItemBySlot(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.EquipmentSlot slot)
      Returns:
      the item in the given slot.
    • hasEnchantment

      public static boolean hasEnchantment(Predicate<net.minecraft.world.item.ItemStack> validStack, net.minecraft.resources.ResourceKey<net.minecraft.world.item.enchantment.Enchantment> enchantment, net.minecraft.world.item.ItemStack stack)
      Returns:
      if the stack has an enchantment.
    • hasEffect

      public static boolean hasEffect(net.minecraft.world.item.ItemStack stack, String potionName)
      Returns:
      if the stack has a potion component.
    • getEntitiesWithinRange

      public static List getEntitiesWithinRange(net.minecraft.world.level.Level world, Class<? extends net.minecraft.world.entity.LivingEntity> entityListOf, net.minecraft.world.entity.LivingEntity startingPoint, List<Integer> xyz, Predicate<? super net.minecraft.world.entity.LivingEntity> selector)
      Parameters:
      world - level reference
      entityListOf - the list of entities to return, by class
      startingPoint - the entity that the game should start searching from
      xyz - an array of the maximum x, y, and z search radius
      Returns:
      a raw List of entities (excluding named entities) within a specified range, and a custom predicate.