Class AnimalManager
java.lang.Object
com.minecolonies.core.colony.managers.AnimalManager
- All Implemented Interfaces:
IAnimalManager
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear 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).intGet the current number of managed animals, might be bigger theninvalid reference
#getMaxCitizens()voidMarks the Animal Manager as dirty, which will cause it to update and save to disk when the colony is saved.protected booleanmatchesHome(IBuilding checkHome, IAnimalData data) Checks if the given home matches the home of the given animal data.voidonColonyTick(IColony colony) Actions to execute on a colony tick.voidread(net.minecraft.core.HolderLookup.Provider provider, @NotNull net.minecraft.nbt.CompoundTag compound) Read the animal data from nbt.voidregisterAnimal(IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> animal) Registers a managed animal with the colony.voidsendPackets(@NotNull Set<net.minecraft.server.level.ServerPlayer> closeSubscribers, @NotNull Set<net.minecraft.server.level.ServerPlayer> newSubscribers) Send the necessary packets to subscribers.booleantickAnimalData(int tickRate) Actions to execute on a tick.voidwrite(net.minecraft.core.HolderLookup.Provider provider, @NotNull net.minecraft.nbt.CompoundTag compoundNBT) Write the animal information to nbt.
-
Field Details
-
TAG_ANIMAL_MANAGER
NBT Tags -
TAG_ANIMALS
-
TAG_NEXTID
-
-
Constructor Details
-
AnimalManager
-
-
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:
registerAnimalin interfaceIAnimalManager- Parameters:
animal- the managed animal to register
-
getAnimals
Gets a list of all animal data managed by this animal manager.- Specified by:
getAnimalsin interfaceIAnimalManager- 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:
getAnimalsOfClassByHomein interfaceIAnimalManager- 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
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 theninvalid reference
#getMaxCitizens()- Specified by:
getCurrentAnimalCountin interfaceIAnimalManager- 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:
createAndRegisterAnimalDatain interfaceIAnimalManager- Returns:
- The newly created animal data.
-
getAnimal
Get the animal data by ID.- Specified by:
getAnimalin interfaceIAnimalManager- 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:
readin interfaceIAnimalManager- 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:
writein interfaceIAnimalManager- Parameters:
compoundNBT- the compound to write it to.- Throws:
UnsupportedOperationException- if not implemented.
-
onColonyTick
Description copied from interface:IAnimalManagerActions to execute on a colony tick.- Specified by:
onColonyTickin interfaceIAnimalManager- Parameters:
colony- the event.
-
tickAnimalData
public boolean tickAnimalData(int tickRate) Description copied from interface:IAnimalManagerActions to execute on a tick.- Specified by:
tickAnimalDatain interfaceIAnimalManager- 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:
markDirtyin interfaceIAnimalManager
-
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:
clearDirtyin interfaceIAnimalManager
-
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:
sendPacketsin interfaceIAnimalManager- Parameters:
closeSubscribers- players that were subscribed but are now out of rangenewSubscribers- players that have just come into range and need data
-