Class CitizenManager

java.lang.Object
com.minecolonies.core.colony.managers.CitizenManager
All Implemented Interfaces:
ICitizenManager, IEntityManager

public class CitizenManager extends Object implements ICitizenManager
  • Constructor Details

    • CitizenManager

      public CitizenManager(Colony colony)
      Creates the Citizenmanager for a colony.
      Parameters:
      colony - the colony.
  • Method Details

    • registerCivilian

      public void registerCivilian(AbstractCivilianEntity entity)
      Description copied from interface: IEntityManager
      Register a civilian entity with the colony
      Specified by:
      registerCivilian in interface IEntityManager
      Parameters:
      entity - civilian to register
    • unregisterCivilian

      public void unregisterCivilian(AbstractCivilianEntity entity)
      Description copied from interface: IEntityManager
      Unregiters a civilian with the colony
      Specified by:
      unregisterCivilian in interface IEntityManager
      Parameters:
      entity - civilian to unregister
    • read

      public void read(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound)
      Description copied from interface: IEntityManager
      Read the civilian from nbt.
      Specified by:
      read in interface IEntityManager
      Parameters:
      compound - the compound to read it from.
    • write

      public void write(@NotNull @NotNull net.minecraft.nbt.CompoundTag compoundNBT)
      Description copied from interface: IEntityManager
      Write the civilian to nbt.
      Specified by:
      write in interface IEntityManager
      Parameters:
      compoundNBT - the compound to write it to.
    • sendPackets

      public void sendPackets(@NotNull @NotNull Set<net.minecraft.server.level.ServerPlayer> closeSubscribers, @NotNull @NotNull Set<net.minecraft.server.level.ServerPlayer> newSubscribers)
      Description copied from interface: IEntityManager
      Sends packages to update the civilian.
      Specified by:
      sendPackets in interface IEntityManager
      Parameters:
      closeSubscribers - the existing subscribers.
      newSubscribers - new subscribers
    • spawnOrCreateCivilian

      public <T extends ICivilianData> T spawnOrCreateCivilian(T data, net.minecraft.world.level.Level world, List<net.minecraft.core.BlockPos> spawnPositions, boolean force)
      Description copied from interface: IEntityManager
      Spawns a civilian with the specific civilian data.
      Specified by:
      spawnOrCreateCivilian in interface IEntityManager
      Parameters:
      data - Data to use when spawn, null when new generation.
      world - THe world.
      spawnPositions - the positions to spawn it at, tried in order.
      force - True to skip max civilian test, false when not.
      Returns:
      the new civilian.
    • createAndRegisterCivilianData

      public ICitizenData createAndRegisterCivilianData()
      Description copied from interface: IEntityManager
      Creates Civilian Data for a new civilian
      Specified by:
      createAndRegisterCivilianData in interface ICitizenManager
      Specified by:
      createAndRegisterCivilianData in interface IEntityManager
      Returns:
      new ICivilianData
    • resurrectCivilianData

      public ICitizenData resurrectCivilianData(@NotNull @NotNull net.minecraft.nbt.CompoundTag compoundNBT, boolean resetId, @NotNull @NotNull net.minecraft.world.level.Level world, net.minecraft.core.BlockPos spawnPos)
      Description copied from interface: ICitizenManager
      Resurrect a citizen from its saved NBT.
      Specified by:
      resurrectCivilianData in interface ICitizenManager
      Parameters:
      compoundNBT - the saved citizen NBT
      resetId - if true, will calculate a new citizen ID
      spawnPos - position where to resurrect the citizen
      Returns:
      the citizenData of the resurrected citizen
    • removeCivilian

      public void removeCivilian(@NotNull @NotNull ICivilianData citizen)
      Description copied from interface: IEntityManager
      Removes a civilian from the colony.
      Specified by:
      removeCivilian in interface IEntityManager
      Parameters:
      citizen - data to remove.
    • getJoblessCitizen

      public ICitizenData getJoblessCitizen()
      Description copied from interface: ICitizenManager
      Get the first unemployed citizen.
      Specified by:
      getJoblessCitizen in interface ICitizenManager
      Returns:
      Citizen with no current job.
    • calculateMaxCitizens

      public void calculateMaxCitizens()
      Description copied from interface: ICitizenManager
      Recalculates how many citizen can be in the colony.
      Specified by:
      calculateMaxCitizens in interface ICitizenManager
    • spawnOrCreateCitizen

      public void spawnOrCreateCitizen()
      Spawn a brand new Citizen.
      Specified by:
      spawnOrCreateCitizen in interface ICitizenManager
    • getCivilianDataMap

      @NotNull public @NotNull Map<Integer,ICivilianData> getCivilianDataMap()
      Description copied from interface: IEntityManager
      Returns a map of civilian in the colony. The map has ID as key, and civilian data as value.
      Specified by:
      getCivilianDataMap in interface IEntityManager
      Returns:
      Map of civilian in the colony, with as key the civilian ID, and as value the civilian data.
    • markDirty

      public void markDirty()
      Description copied from interface: IEntityManager
      Marks civilian data dirty.
      Specified by:
      markDirty in interface IEntityManager
    • getCivilian

      public ICitizenData getCivilian(int citizenId)
      Description copied from interface: IEntityManager
      Get civilian by ID.
      Specified by:
      getCivilian in interface ICitizenManager
      Specified by:
      getCivilian in interface IEntityManager
      Parameters:
      citizenId - ID of the civilian.
      Returns:
      ICivilianData associated with the ID, or null if it was not found.
    • clearDirty

      public void clearDirty()
      Description copied from interface: IEntityManager
      Clear dirty from all buildings.
      Specified by:
      clearDirty in interface IEntityManager
    • getCitizens

      public List<ICitizenData> getCitizens()
      Description copied from interface: ICitizenManager
      Get all citizens.
      Specified by:
      getCitizens in interface ICitizenManager
      Returns:
      a copy of the list of citizens.
    • getMaxCitizens

      public int getMaxCitizens()
      Description copied from interface: ICitizenManager
      Get max citizens of the colony.
      Specified by:
      getMaxCitizens in interface ICitizenManager
      Returns:
      the amount.
    • getPotentialMaxCitizens

      public int getPotentialMaxCitizens()
      Description copied from interface: ICitizenManager
      Get potential max citizens of the colony. The potential considers all available beds including not assigned guard towers.
      Specified by:
      getPotentialMaxCitizens in interface ICitizenManager
      Returns:
      the amount.
    • maxCitizensFromResearch

      public double maxCitizensFromResearch()
      Description copied from interface: ICitizenManager
      Get the max citizens based on the research.
      Specified by:
      maxCitizensFromResearch in interface ICitizenManager
      Returns:
      the max.
    • getCurrentCitizenCount

      public int getCurrentCitizenCount()
      Get the current amount of citizens, might be bigger then getMaxCitizens()
      Specified by:
      getCurrentCitizenCount in interface ICitizenManager
      Returns:
      The current amount of citizens in the colony.
    • setMaxCitizens

      public void setMaxCitizens(int newMaxCitizens)
      Description copied from interface: ICitizenManager
      Set the new max citizens.
      Specified by:
      setMaxCitizens in interface ICitizenManager
      Parameters:
      newMaxCitizens - the amount to set.
    • setPotentialMaxCitizens

      public void setPotentialMaxCitizens(int newPotentialMax)
      Description copied from interface: ICitizenManager
      Set the new potential max citizens. The potential considers all available beds including not assigned guard towers.
      Specified by:
      setPotentialMaxCitizens in interface ICitizenManager
      Parameters:
      newPotentialMax - the potential amount to set.
    • injectModifier

      public void injectModifier(IHappinessModifier modifier)
      Description copied from interface: ICitizenManager
      Inject a modifier into all citizens
      Specified by:
      injectModifier in interface ICitizenManager
      Parameters:
      modifier - the modifier.
    • checkCitizensForHappiness

      public void checkCitizensForHappiness()
      Description copied from interface: ICitizenManager
      Check for the citizen happiness and update the colony happiness with it.
      Specified by:
      checkCitizensForHappiness in interface ICitizenManager
    • tickCitizenData

      public boolean tickCitizenData(int tickRate)
      Description copied from interface: ICitizenManager
      Tick the citizen data of all active citizens.
      Specified by:
      tickCitizenData in interface ICitizenManager
    • onColonyTick

      public void onColonyTick(IColony colony)
      Updates the citizen entities when needed and spawn the initial citizens on colony tick.
      Specified by:
      onColonyTick in interface IEntityManager
      Parameters:
      colony - the colony being ticked.
    • updateCitizenMourn

      public void updateCitizenMourn(ICitizenData data, boolean mourn)
      Description copied from interface: ICitizenManager
      Call this to set all the citizens in the colony to mourn or not.
      Specified by:
      updateCitizenMourn in interface ICitizenManager
      mourn - boolean to indicate if citizen should mourn or not
    • getRandomCitizen

      public ICitizenData getRandomCitizen()
      Description copied from interface: ICitizenManager
      Get a random citizen.
      Specified by:
      getRandomCitizen in interface ICitizenManager
      Returns:
      the random citizen.
    • updateCitizenSleep

      public void updateCitizenSleep(boolean sleep)
      Description copied from interface: ICitizenManager
      Call this to set all citizens asleep
      Specified by:
      updateCitizenSleep in interface ICitizenManager
      Parameters:
      sleep - boolean to indicate whether the citizens are all asleep
    • onCitizenSleep

      public void onCitizenSleep()
      Description copied from interface: ICitizenManager
      Call this when citizens sleep
      Specified by:
      onCitizenSleep in interface ICitizenManager
    • onWakeUp

      public void onWakeUp()
      Description copied from interface: ICitizenManager
      Called in the morning.
      Specified by:
      onWakeUp in interface ICitizenManager
    • afterBuildingLoad

      public void afterBuildingLoad()
      Description copied from interface: ICitizenManager
      Post building load actions
      Specified by:
      afterBuildingLoad in interface ICitizenManager
    • onFlagChange

      public void onFlagChange()
      Description copied from interface: ICitizenManager
      Called when flag is changed
      Specified by:
      onFlagChange in interface ICitizenManager