Class AnimalManager

java.lang.Object
com.minecolonies.core.colony.managers.AnimalManager
All Implemented Interfaces:
IAnimalManager

public class AnimalManager extends Object implements IAnimalManager
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static String
    NBT Tags
    static String
     
    static String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the dirty flag of the Animal Manager, which will prevent it from re-saving to disk when the colony is saved.
    createAndRegisterAnimalData(IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> managedAnimal)
    Creates and registers a new animal data.
    getAnimal(int id)
    Get the animal data by ID.
    Gets a list of all animal data managed by this animal manager.
    getAnimalsOfClassByHome(Class<? extends net.minecraft.world.entity.animal.Animal> animalClass, @Nullable IBuilding home)
    Gets a list of all animal data of a certain class, with the specified home (or if home is null, all animals of that class).
    int
    Get the current number of managed animals, might be bigger then
    invalid reference
    #getMaxCitizens()
    void
    Marks the Animal Manager as dirty, which will cause it to update and save to disk when the colony is saved.
    protected boolean
    matchesHome(IBuilding checkHome, IAnimalData data)
    Checks if the given home matches the home of the given animal data.
    void
    Actions to execute on a colony tick.
    void
    read(net.minecraft.core.HolderLookup.Provider provider, @NotNull net.minecraft.nbt.CompoundTag compound)
    Read the animal data from nbt.
    void
    registerAnimal(IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> animal)
    Registers a managed animal with the colony.
    void
    sendPackets(@NotNull Set<net.minecraft.server.level.ServerPlayer> closeSubscribers, @NotNull Set<net.minecraft.server.level.ServerPlayer> newSubscribers)
    Send the necessary packets to subscribers.
    boolean
    tickAnimalData(int tickRate)
    Actions to execute on a tick.
    void
    write(net.minecraft.core.HolderLookup.Provider provider, @NotNull net.minecraft.nbt.CompoundTag compoundNBT)
    Write the animal information to nbt.

    Methods inherited from class java.lang.Object

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

    • TAG_ANIMAL_MANAGER

      public static String TAG_ANIMAL_MANAGER
      NBT Tags
    • TAG_ANIMALS

      public static String TAG_ANIMALS
    • TAG_NEXTID

      public static String TAG_NEXTID
  • Constructor Details

    • AnimalManager

      public AnimalManager(IColony colony)
  • Method Details

    • registerAnimal

      public void registerAnimal(IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> animal)
      Registers a managed animal with the colony. If the animal ID is 0 or the animal data associated with the ID is null, the animal is removed from the world. If the animal UUID does not match the UUID of the data, the animal is removed from the world. If an existing managed animal with the same ID is found, the existing animal is removed from the world if it is alive. If the animal is not added to the world, it is removed from the world and a warn message is logged.
      Specified by:
      registerAnimal in interface IAnimalManager
      Parameters:
      animal - the managed animal to register
    • getAnimals

      public List<IAnimalData> getAnimals()
      Gets a list of all animal data managed by this animal manager.
      Specified by:
      getAnimals in interface IAnimalManager
      Returns:
      a list of all animal data managed by this animal manager.
    • getAnimalsOfClassByHome

      public List<IAnimalData> getAnimalsOfClassByHome(Class<? extends net.minecraft.world.entity.animal.Animal> animalClass, @Nullable @Nullable IBuilding home)
      Gets a list of all animal data of a certain class, with the specified home (or if home is null, all animals of that class).
      Specified by:
      getAnimalsOfClassByHome in interface IAnimalManager
      Parameters:
      animalClass - the class of animals to get.
      home - the home building of the animals to get, or null to get all animals of that class.
      Returns:
      a list of all animal data of the specified class, with the specified home (or all animals of that class if home is null).
    • matchesHome

      protected boolean matchesHome(IBuilding checkHome, IAnimalData data)
      Checks if the given home matches the home of the given animal data. If the given home is null, this method returns true.
      Parameters:
      checkHome - the home to check against.
      data - the animal data to check.
      Returns:
      true if the given home matches the home of the given animal data, false otherwise.
    • getCurrentAnimalCount

      public int getCurrentAnimalCount()
      Get the current number of managed animals, might be bigger then
      invalid reference
      #getMaxCitizens()
      Specified by:
      getCurrentAnimalCount in interface IAnimalManager
      Returns:
      The current number of managed animals
    • createAndRegisterAnimalData

      public IAnimalData createAndRegisterAnimalData(IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> managedAnimal)
      Creates and registers a new animal data. This method also ensures that IDs are getting reused. That's needed to prevent bugs when calling IDs that are not used.
      Specified by:
      createAndRegisterAnimalData in interface IAnimalManager
      Returns:
      The newly created animal data.
    • getAnimal

      public IAnimalData getAnimal(int id)
      Get the animal data by ID.
      Specified by:
      getAnimal in interface IAnimalManager
      Parameters:
      id - The animal ID.
      Returns:
      The animal data, or null if not found.
    • read

      public void read(@NotNull net.minecraft.core.HolderLookup.Provider provider, @NotNull @NotNull net.minecraft.nbt.CompoundTag compound)
      Read the animal data from nbt.
      Specified by:
      read in interface IAnimalManager
      Parameters:
      compound - the compound to read it from.
    • write

      public void write(@NotNull net.minecraft.core.HolderLookup.Provider provider, @NotNull @NotNull net.minecraft.nbt.CompoundTag compoundNBT)
      Write the animal information to nbt.
      Specified by:
      write in interface IAnimalManager
      Parameters:
      compoundNBT - the compound to write it to.
      Throws:
      UnsupportedOperationException - if not implemented.
    • onColonyTick

      public void onColonyTick(IColony colony)
      Description copied from interface: IAnimalManager
      Actions to execute on a colony tick.
      Specified by:
      onColonyTick in interface IAnimalManager
      Parameters:
      colony - the event.
    • tickAnimalData

      public boolean tickAnimalData(int tickRate)
      Description copied from interface: IAnimalManager
      Actions to execute on a tick.
      Specified by:
      tickAnimalData in interface IAnimalManager
      Parameters:
      tickRate - the event.
    • markDirty

      public void markDirty()
      Marks the Animal Manager as dirty, which will cause it to update and save to disk when the colony is saved.
      Specified by:
      markDirty in interface IAnimalManager
    • clearDirty

      public void clearDirty()
      Clear the dirty flag of the Animal Manager, which will prevent it from re-saving to disk when the colony is saved.
      Specified by:
      clearDirty in interface IAnimalManager
    • sendPackets

      public void sendPackets(@NotNull @NotNull Set<net.minecraft.server.level.ServerPlayer> closeSubscribers, @NotNull @NotNull Set<net.minecraft.server.level.ServerPlayer> newSubscribers)
      Send the necessary packets to subscribers.
      Specified by:
      sendPackets in interface IAnimalManager
      Parameters:
      closeSubscribers - players that were subscribed but are now out of range
      newSubscribers - players that have just come into range and need data