Package com.minecolonies.core.colony
Class AnimalData
java.lang.Object
com.minecolonies.core.colony.AnimalData
- All Implemented Interfaces:
IAnimalData,net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
-
Constructor Summary
ConstructorsConstructorDescriptionAnimalData(int id, IColony colony) Create an AnimalData given an ID and colony. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the dirty flag for this animal data.voiddeserializeNBT(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbtTagCompound) Deserializes the animal data from nbt.floatReturns the current combat cooldown of the horse.@Nullable IBuildingGet the home building of the animal.intgetId()Get the unique ID of this animal.@NotNull net.minecraft.core.BlockPosGets the last position of the animal.@NotNull Optional<IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal>> Return the entity instance of the animal data.getOwner()Gets the owner of the animal.getUUID()Gets the globally unique identifier associated with this animal data.voidInitializes vital entity values from animal data.booleanisDirty()Returns if the instance is dirty.static IAnimalDataloadAnimalFromNBT(IColony colony, net.minecraft.nbt.CompoundTag nbt, @NotNull net.minecraft.core.HolderLookup.Provider provider) Loads this animal data from nbtvoidMarks this animal data as dirty and in need of syncing / saving.voidonRemoveBuilding(IBuilding building) Called when a building is removed.net.minecraft.nbt.CompoundTagserializeNBT(net.minecraft.core.HolderLookup.Provider provider) Serializes this animal data to nbt.voidserializeViewNetworkData(@NotNull net.minecraft.network.RegistryFriendlyByteBuf buf) Writes the animal data to a byte buf for transition.voidsetCombatCooldown(float newCooldown) Sets the combat cooldown of the horse.voidsetHomeBuilding(@Nullable IBuilding building) Sets the home building of the animal.voidsetLastPosition(net.minecraft.core.BlockPos lastPosition) Sets the last position of the animal.voidsetManagedAnimal(@Nullable IManagedAnimal<? extends net.minecraft.world.entity.animal.Animal> animal) Set the entity instance of the animal data.voidSets the owner of the animal.voidupdate(int tickRate) Updates the animal data.
-
Constructor Details
-
AnimalData
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:
updatein interfaceIAnimalData- Parameters:
tickRate- the tick rate.
-
initEntityValues
public void initEntityValues()Initializes vital entity values from animal data.- Specified by:
initEntityValuesin interfaceIAnimalData
-
loadAnimalFromNBT
public static IAnimalData loadAnimalFromNBT(IColony colony, net.minecraft.nbt.CompoundTag nbt, @NotNull net.minecraft.core.HolderLookup.Provider provider) Loads this animal data from nbt- Parameters:
colony- colony to load fornbt- nbt compound to read from- Returns:
- new AnimalData
-
serializeNBT
public net.minecraft.nbt.CompoundTag serializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider) Serializes this animal data to nbt.- Specified by:
serializeNBTin interfacenet.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>- Returns:
- A compound nbt containing the animal data.
-
deserializeNBT
public void deserializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag nbtTagCompound) Deserializes the animal data from nbt.- Specified by:
deserializeNBTin interfacenet.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>- Parameters:
nbtTagCompound- the nbt compound to read from.
-
serializeViewNetworkData
public void serializeViewNetworkData(@NotNull @NotNull net.minecraft.network.RegistryFriendlyByteBuf 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:
serializeViewNetworkDatain interfaceIAnimalData- Parameters:
buf- Buffer to write to.
-
getId
public int getId()Get the unique ID of this animal.- Specified by:
getIdin interfaceIAnimalData- Returns:
- the animal ID
-
getUUID
Gets the globally unique identifier associated with this animal data.- Specified by:
getUUIDin interfaceIAnimalData- Returns:
- the globally unique identifier associated with this animal data.
-
getOwner
Gets the owner of the animal.- Specified by:
getOwnerin interfaceIAnimalData- Returns:
- the owner of the animal, or null if the animal has no owner.
-
setOwner
Sets the owner of the animal.- Specified by:
setOwnerin interfaceIAnimalData- 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:
getManagedAnimalin interfaceIAnimalData- Returns:
Entityof 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:
setManagedAnimalin interfaceIAnimalData- 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:
markDirtyin interfaceIAnimalData
-
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:
clearDirtyin interfaceIAnimalData
-
isDirty
public boolean isDirty()Returns if the instance is dirty.- Specified by:
isDirtyin interfaceIAnimalData- Returns:
- True if dirty, otherwise false.
-
getHomeBuilding
Get the home building of the animal.- Specified by:
getHomeBuildingin interfaceIAnimalData- Returns:
- the home building, or null if the animal does not have a home building.
-
setHomeBuilding
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:
setHomeBuildingin interfaceIAnimalData- Parameters:
building- the new home building of the animal, or null to remove the animal's home building.
-
onRemoveBuilding
Called when a building is removed.- Specified by:
onRemoveBuildingin interfaceIAnimalData- 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:
setLastPositionin interfaceIAnimalData- 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:
getLastPositionin interfaceIAnimalData- 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:
getCombatCooldownin interfaceIAnimalData- Returns:
- the current combat cooldown of the horse
-
setCombatCooldown
public void setCombatCooldown(float newCooldown) Sets the combat cooldown of the horse.- Specified by:
setCombatCooldownin interfaceIAnimalData- Parameters:
newCooldown- the new combat cooldown of the horse
-