Class AnimalData

java.lang.Object
com.minecolonies.core.colony.AnimalData
All Implemented Interfaces:
IAnimalData, net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>

public class AnimalData extends Object implements IAnimalData
  • Constructor Details

    • AnimalData

      public AnimalData(int id, IColony colony)
      Create an AnimalData given an ID and colony.
      Parameters:
      id - ID of the Citizen.
      colony - Colony the Citizen belongs to.
  • Method Details

    • update

      public void update(int tickRate)
      Updates the animal data. This method is called every tick and is responsible for updating the animal data. It currently does nothing, but may be used in the future for tick-based animal management.
      Specified by:
      update in interface IAnimalData
      Parameters:
      tickRate - the tick rate.
    • initEntityValues

      public void initEntityValues()
      Initializes vital entity values from animal data.
      Specified by:
      initEntityValues in interface IAnimalData
    • loadAnimalFromNBT

      public static IAnimalData loadAnimalFromNBT(IColony colony, net.minecraft.nbt.CompoundTag nbt)
      Loads this animal data from nbt
      Parameters:
      colony - colony to load for
      nbt - nbt compound to read from
      Returns:
      new AnimalData
    • serializeNBT

      public net.minecraft.nbt.CompoundTag serializeNBT()
      Serializes this animal data to nbt.
      Specified by:
      serializeNBT in interface net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
      Returns:
      A compound nbt containing the animal data.
    • deserializeNBT

      public void deserializeNBT(net.minecraft.nbt.CompoundTag nbtTagCompound)
      Deserializes the animal data from nbt.
      Specified by:
      deserializeNBT in interface net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
      Parameters:
      nbtTagCompound - the nbt compound to read from.
    • serializeViewNetworkData

      public void serializeViewNetworkData(@NotNull @NotNull net.minecraft.network.FriendlyByteBuf buf)
      Writes the animal data to a byte buf for transition. This method first calls the superclass's implementation, then writes the recruit cost and the count of the recruit cost to the byte buf.
      Specified by:
      serializeViewNetworkData in interface IAnimalData
      Parameters:
      buf - Buffer to write to.
    • getId

      public int getId()
      Get the unique ID of this animal.
      Specified by:
      getId in interface IAnimalData
      Returns:
      the animal ID
    • getUUID

      public UUID getUUID()
      Gets the globally unique identifier associated with this animal data.
      Specified by:
      getUUID in interface IAnimalData
      Returns:
      the globally unique identifier associated with this animal data.
    • getOwner

      public UUID getOwner()
      Gets the owner of the animal.
      Specified by:
      getOwner in interface IAnimalData
      Returns:
      the owner of the animal, or null if the animal has no owner.
    • setOwner

      public void setOwner(UUID owner)
      Sets the owner of the animal.
      Specified by:
      setOwner in interface IAnimalData
      Parameters:
      owner - the new owner of the animal
    • getManagedAnimal

      @NotNull public @NotNull Optional<IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal>> getManagedAnimal()
      Return the entity instance of the animal data. Respawn the animal if needed.
      Specified by:
      getManagedAnimal in interface IAnimalData
      Returns:
      Entity of the animal data.
    • setManagedAnimal

      public void setManagedAnimal(@Nullable @Nullable IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> animal)
      Set the entity instance of the animal data.
      Specified by:
      setManagedAnimal in interface IAnimalData
      Parameters:
      animal - the animal entity.
    • markDirty

      public void markDirty()
      Marks this animal data as dirty and in need of syncing / saving.

      This method sets the dirty flag to true, indicating that the animal data has been modified and needs to be saved or synced with the client.

      Specified by:
      markDirty in interface IAnimalData
    • clearDirty

      public void clearDirty()
      Clears the dirty flag for this animal data.

      This method marks the animal data as not needing to be synced with the client.

      Specified by:
      clearDirty in interface IAnimalData
    • isDirty

      public boolean isDirty()
      Returns if the instance is dirty.
      Specified by:
      isDirty in interface IAnimalData
      Returns:
      True if dirty, otherwise false.
    • getHomeBuilding

      @Nullable public @Nullable IBuilding getHomeBuilding()
      Get the home building of the animal.
      Specified by:
      getHomeBuilding in interface IAnimalData
      Returns:
      the home building, or null if the animal does not have a home building.
    • setHomeBuilding

      public void setHomeBuilding(@Nullable @Nullable IBuilding building)
      Sets the home building of the animal.

      This method removes the animal from the current home building and adds it to the new home building.

      If the animal's home building is changed, the animal's bed position is reset to zero.

      If the animal's entity is present and has a null colony job, the animal's job handler model is reset to null.

      Specified by:
      setHomeBuilding in interface IAnimalData
      Parameters:
      building - the new home building of the animal, or null to remove the animal's home building.
    • onRemoveBuilding

      public void onRemoveBuilding(IBuilding building)
      Called when a building is removed.
      Specified by:
      onRemoveBuilding in interface IAnimalData
      Parameters:
      building - the building that was removed.
    • setLastPosition

      public void setLastPosition(net.minecraft.core.BlockPos lastPosition)
      Sets the last position of the animal.
      Specified by:
      setLastPosition in interface IAnimalData
      Parameters:
      lastPosition - the last position of the animal.
    • getLastPosition

      @NotNull public @NotNull net.minecraft.core.BlockPos getLastPosition()
      Gets the last position of the animal.
      Specified by:
      getLastPosition in interface IAnimalData
      Returns:
      the last position of the animal.
    • getCombatCooldown

      public float getCombatCooldown()
      Returns the current combat cooldown of the horse. A higher value means the horse is currently less ready for combat.
      Specified by:
      getCombatCooldown in interface IAnimalData
      Returns:
      the current combat cooldown of the horse
    • setCombatCooldown

      public void setCombatCooldown(float newCooldown)
      Sets the combat cooldown of the horse.
      Specified by:
      setCombatCooldown in interface IAnimalData
      Parameters:
      newCooldown - the new combat cooldown of the horse