Class Utils

java.lang.Object
com.jeff.pets.client.Utils

public class Utils extends Object
A utility class used mainly in Central and misc rendering classes. Contains various shortcuts and utilities for spawning, despawning, and avoiding NullPointerExceptions, as well as a shortcut to Identifier.fromNamespaceAndPath(String, String).
Since:
0.8.0 (Minecraft Earth Mob Pack)
See Also:
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • summonPet

      public static void summonPet(AbstractPet entity, String entityName)
      Used to summon a pet.
      Parameters:
      entity - the entity to be summoned.
      entityName - the name to set the custom entity to. (Technically not required since we use a method to refresh the names in Central, but still). returns if the entity, player, or world is null
    • summonPet

      public static void summonPet(AbstractPet entity, String entityName, net.minecraft.world.entity.player.Player player)
    • checkName

      public static void checkName(String activePet, AbstractPet entity, String petName)
      The method used in Central.refreshPetNames(). Checks whether the entities' name is equal to the name in the config, and assigns it the correct name if not. Additionally, this method provides a layer of safety that ensures that Minecraft will not throw a NullPointerException if entity is null.
      Parameters:
      activePet - The activePet value that matches entity
      entity - The pet of which the name is checked.
      petName - The CONFIG.x name that matches entity that the entities' current name is checked off of.
    • checkNullString

      public static String checkNullString(String s)
      Checks if the string is null and sets it to an empty - but not null String - if it is.
      Parameters:
      s - The String to check if it is null.
      Returns:
      If the string is null, the new empty String is returned. If the string is not null, simply returns s.
    • checkNullString

      public static String checkNullString(String s, String defaultSkin)
      Similar to the checkNullString method above, but takes a default value instead of setting the String to an empty String. Used to set the CONFIG.xSkin values to a default value and avoid NullPointerExceptions.
      Parameters:
      s - The string to check if it null.
      defaultSkin - The default value to set s to if s is null.
      Returns:
      If the string is null, defaultSkin is returned. If the string is not null, simply returns s.
    • withModNamespace

      public static net.minecraft.resources.Identifier withModNamespace(String path)
      Used as a shortcut to Identifier.fromNamespaceAndPath(String, String), and sets the parameter namespace with PetsInitializer.MOD_ID.
      Parameters:
      path - The String that goes in the path parameter.
      Returns:
      Identifier.fromNamespaceAndPath(String, String), with the parameter namespace set to PetsInitializer.MOD_ID and the parameter path set to the user's input
    • despawnEntity

      public static void despawnEntity(net.minecraft.world.entity.Entity e)
      Despawns the inputted pet if e is not null.
      Parameters:
      e - The entity to despawn
    • setActivePet

      public static void setActivePet(net.minecraft.world.entity.Entity e, String s)
      Sets the active pet in PetsConfig.activePet as well as in Central.summonedEntity
      Parameters:
      e - The entity to be summoned and added to Central.summonedEntity
      s - The value to set PetsConfig.activePet to that matches e
    • getBlockFromString

      public static net.minecraft.world.level.block.Block getBlockFromString(String string)
    • getPet

      public static AbstractPet getPet(String string)
    • getActivePetName

      public static String getActivePetName()
    • setActivePetName

      public static void setActivePetName(String name)
    • getActivePetSkin

      public static String getActivePetSkin()
    • setActivePetSkin

      public static boolean setActivePetSkin(String skin)
    • capitalize

      public static String capitalize(String s)
    • getAllBlocks

      public static List<String> getAllBlocks()