Class Colony

java.lang.Object
com.minecolonies.core.colony.Colony
All Implemented Interfaces:
IColony

public class Colony extends Object implements IColony
This class describes a colony and contains all the data and methods for manipulating a Colony.
  • Field Details

    • ticketedChunks

      public Set<Long> ticketedChunks
      List of loaded chunks for the colony.
    • lastOnlineTime

      public long lastOnlineTime
      Last time the server was online.
  • Method Details

    • updateAttackingPlayers

      public void updateAttackingPlayers()
      Updates the pvping playeres.
    • setColonyColor

      public void setColonyColor(net.minecraft.ChatFormatting colonyColor)
      Set up the colony color for team handling for pvp.
      Specified by:
      setColonyColor in interface IColony
      Parameters:
      colonyColor - the colony color.
    • setColonyFlag

      public void setColonyFlag(net.minecraft.world.level.block.entity.BannerPatternLayers colonyFlag)
      Set up the colony flag patterns for use in decorations etc
      Specified by:
      setColonyFlag in interface IColony
      Parameters:
      colonyFlag - the list of pattern-color pairs
    • loadColony

      @Nullable public static @Nullable Colony loadColony(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound, @Nullable @Nullable net.minecraft.server.level.ServerLevel world, @NotNull net.minecraft.core.HolderLookup.Provider provider)
      Load a saved colony.
      Parameters:
      compound - The NBT compound containing the colony's data.
      world - the world to load it for.
      provider -
      Returns:
      loaded colony.
    • read

      public void read(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound, @NotNull net.minecraft.core.HolderLookup.Provider provider)
      Read colony from saved data.
      Specified by:
      read in interface IColony
      Parameters:
      compound - compound to read from.
    • getEventHandler

      public ColonyPermissionEventHandler getEventHandler()
      Get the event handler assigned to the colony.
      Returns:
      the ColonyPermissionEventHandler.
    • write

      public net.minecraft.nbt.CompoundTag write(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound, @NotNull net.minecraft.core.HolderLookup.Provider provider)
      Write colony to save data.
      Specified by:
      write in interface IColony
      Parameters:
      compound - compound to write to.
    • getDimension

      public net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> getDimension()
      Returns the dimension ID.
      Specified by:
      getDimension in interface IColony
      Returns:
      Dimension ID.
    • isRemote

      public boolean isRemote()
      Description copied from interface: IColony
      Check if the colony is on the server or client.
      Specified by:
      isRemote in interface IColony
      Returns:
      true if so.
    • getResearchManager

      public IResearchManager getResearchManager()
      Description copied from interface: IColony
      Get the research manager.
      Specified by:
      getResearchManager in interface IColony
      Returns:
      the research manager object.
    • onWorldLoad

      public void onWorldLoad(@NotNull @NotNull net.minecraft.server.level.ServerLevel w)
      When the Colony's world is loaded, associate with it.
      Specified by:
      onWorldLoad in interface IColony
      Parameters:
      w - World object.
    • onWorldUnload

      public void onWorldUnload(@NotNull @NotNull net.minecraft.world.level.Level w)
      Unsets the world if the world unloads.
      Specified by:
      onWorldUnload in interface IColony
      Parameters:
      w - World object.
    • onServerTick

      public void onServerTick(@NotNull net.neoforged.neoforge.event.tick.ServerTickEvent.Pre event)
      Specified by:
      onServerTick in interface IColony
    • getWorkManager

      @NotNull public @NotNull IWorkManager getWorkManager()
      Get the Work Manager for the Colony.
      Specified by:
      getWorkManager in interface IColony
      Returns:
      WorkManager for the Colony.
    • getFreePositions

      public Set<net.minecraft.core.BlockPos> getFreePositions()
      Get a copy of the freePositions list.
      Returns:
      the list of free to interact positions.
    • getFreeBlocks

      public Set<net.minecraft.world.level.block.Block> getFreeBlocks()
      Get a copy of the freeBlocks list.
      Returns:
      the list of free to interact blocks.
    • addFreePosition

      public void addFreePosition(@NotNull @NotNull net.minecraft.core.BlockPos pos)
      Add a new free to interact position.
      Specified by:
      addFreePosition in interface IColony
      Parameters:
      pos - position to add.
    • addFreeBlock

      public void addFreeBlock(@NotNull @NotNull net.minecraft.world.level.block.Block block)
      Add a new free to interact block.
      Specified by:
      addFreeBlock in interface IColony
      Parameters:
      block - block to add.
    • removeFreePosition

      public void removeFreePosition(@NotNull @NotNull net.minecraft.core.BlockPos pos)
      Remove a free to interact position.
      Specified by:
      removeFreePosition in interface IColony
      Parameters:
      pos - position to remove.
    • removeFreeBlock

      public void removeFreeBlock(@NotNull @NotNull net.minecraft.world.level.block.Block block)
      Remove a free to interact block.
      Specified by:
      removeFreeBlock in interface IColony
      Parameters:
      block - state to remove.
    • onWorldTick

      public void onWorldTick(@NotNull net.neoforged.neoforge.event.tick.LevelTickEvent.Pre event)
      Any per-world-tick logic should be performed here. NOTE: If the Colony's world isn't loaded, it won't have a world tick. Use onServerTick for logic that should _always_ run.
      Specified by:
      onWorldTick in interface IColony
      Parameters:
      event - LevelTickEvent
    • shallUpdate

      public static boolean shallUpdate(net.minecraft.world.level.Level world, int averageTicks)
      Calculate randomly if the colony should update the citizens. By mean they update it at CLEANUP_TICK_INCREMENT.
      Parameters:
      world - the world.
      averageTicks - the average ticks to upate it.
      Returns:
      a boolean by random.
    • getCenter

      public net.minecraft.core.BlockPos getCenter()
      Returns the center of the colony.
      Specified by:
      getCenter in interface IColony
      Returns:
      Chunk Coordinates of the center of the colony.
    • getName

      public String getName()
      Description copied from interface: IColony
      Returns the name of the colony.
      Specified by:
      getName in interface IColony
      Returns:
      Name of the colony.
    • setName

      public void setName(String n)
      Sets the name of the colony. Marks dirty.
      Specified by:
      setName in interface IColony
      Parameters:
      n - new name.
    • getPermissions

      @NotNull public @NotNull Permissions getPermissions()
      Description copied from interface: IColony
      Returns the permissions of the colony.
      Specified by:
      getPermissions in interface IColony
      Returns:
      IPermissions of the colony.
    • isCoordInColony

      public boolean isCoordInColony(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColony
      Determine if a given chunk coordinate is considered to be within the colony's bounds.
      Specified by:
      isCoordInColony in interface IColony
      Parameters:
      w - World to check.
      pos - Block Position.
      Returns:
      True if inside colony, otherwise false.
    • getDistanceSquared

      public long getDistanceSquared(@NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColony
      Returns the squared (x, z) distance to the center.
      Specified by:
      getDistanceSquared in interface IColony
      Parameters:
      pos - Block Position.
      Returns:
      Squared distance to the center in (x, z) direction.
    • getID

      public int getID()
      Returns the ID of the colony.
      Specified by:
      getID in interface IColony
      Returns:
      Colony ID.
    • getLastContactInHours

      public int getLastContactInHours()
      Description copied from interface: IColony
      Get the last contact of a player to the colony in hours.
      Specified by:
      getLastContactInHours in interface IColony
      Returns:
      an integer with a describing value.
    • getWorld

      @Nullable public @Nullable net.minecraft.server.level.ServerLevel getWorld()
      Returns the world the colony is in.
      Specified by:
      getWorld in interface IColony
      Returns:
      World the colony is in.
    • getRequestManager

      @NotNull public @NotNull IRequestManager getRequestManager()
      Description copied from interface: IColony
      Get the current IRequestManager for this Colony. Returns null if the current Colony does not support the request system.
      Specified by:
      getRequestManager in interface IColony
      Returns:
      the IRequestManager for this colony, null if not supported.
    • markDirty

      public void markDirty()
      Marks the instance dirty.
      Specified by:
      markDirty in interface IColony
    • canBeAutoDeleted

      public boolean canBeAutoDeleted()
      Description copied from interface: IColony
      Called to check if the colony can be deleted by an automatic cleanup.
      Specified by:
      canBeAutoDeleted in interface IColony
      Returns:
      true if so.
    • getRequesterBuildingForPosition

      @Nullable public @Nullable IRequester getRequesterBuildingForPosition(@NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColony
      Method used to get a IRequester from a given Position. Is always a Building.
      Specified by:
      getRequesterBuildingForPosition in interface IColony
      Parameters:
      pos - The position to get the Building that acts as a requester.
      Returns:
      The IRequester from the position, or null.
    • getMessagePlayerEntities

      @NotNull public @NotNull List<net.minecraft.world.entity.player.Player> getMessagePlayerEntities()
      Description copied from interface: IColony
      Get the players in the colony which should receive the message.
      Specified by:
      getMessagePlayerEntities in interface IColony
      Returns:
      list of players
    • getImportantMessageEntityPlayers

      @NotNull public @NotNull List<net.minecraft.world.entity.player.Player> getImportantMessageEntityPlayers()
      Description copied from interface: IColony
      Returns a set of players receiving important messages for the colony.
      Specified by:
      getImportantMessageEntityPlayers in interface IColony
      Returns:
      set of players.
    • removeWorkOrderInView

      public void removeWorkOrderInView(int orderId)
      Send the message of a removed workOrder to the client.
      Parameters:
      orderId - the workOrder to remove.
    • addWayPoint

      public void addWayPoint(net.minecraft.core.BlockPos point, net.minecraft.world.level.block.state.BlockState block)
      Adds a waypoint to the colony.
      Specified by:
      addWayPoint in interface IColony
      Parameters:
      point - the waypoint to add.
      block - the block at the waypoint.
    • getOverallHappiness

      public double getOverallHappiness()
      Getter for overall happiness.
      Specified by:
      getOverallHappiness in interface IColony
      Returns:
      the overall happiness.
    • getWayPoints

      public Map<net.minecraft.core.BlockPos,net.minecraft.world.level.block.state.BlockState> getWayPoints()
      Get all the waypoints of the colony.
      Specified by:
      getWayPoints in interface IColony
      Returns:
      copy of hashmap.
    • setCanBeAutoDeleted

      public void setCanBeAutoDeleted(boolean canBeDeleted)
      This sets whether or not a colony can be automatically deleted Via command, or an on-tick check.
      Specified by:
      setCanBeAutoDeleted in interface IColony
      Parameters:
      canBeDeleted - whether the colony is able to be deleted automatically
    • getStructurePack

      public String getStructurePack()
      Getter for the default style of the colony.
      Specified by:
      getStructurePack in interface IColony
      Returns:
      the style string.
    • setStructurePack

      public void setStructurePack(String style)
      Setter for the default pack of the colony.
      Specified by:
      setStructurePack in interface IColony
      Parameters:
      style - the default string.
    • getServerBuildingManager

      public IRegisteredStructureManager getServerBuildingManager()
      Get the buildingmanager of the colony.
      Specified by:
      getServerBuildingManager in interface IColony
      Returns:
      the buildingManager.
    • getCommonBuildingManager

      public ICommonRegisteredStructureManager getCommonBuildingManager()
      Specified by:
      getCommonBuildingManager in interface IColony
    • getGraveManager

      public IGraveManager getGraveManager()
      Get the graveManager of the colony.
      Specified by:
      getGraveManager in interface IColony
      Returns:
      the graveManager.
    • getCitizenManager

      public ICitizenManager getCitizenManager()
      Get the citizenManager of the colony.
      Specified by:
      getCitizenManager in interface IColony
      Returns:
      the citizenManager.
    • getVisitorManager

      public IVisitorManager getVisitorManager()
      Get the visitor manager of the colony.
      Specified by:
      getVisitorManager in interface IColony
      Returns:
      the visitor manager.
    • getAnimalManager

      public IAnimalManager getAnimalManager()
      Get the animal manager of the colony.
      Specified by:
      getAnimalManager in interface IColony
      Returns:
      the animal manager.
    • getRaiderManager

      public IRaiderManager getRaiderManager()
      Get the barbManager of the colony.
      Specified by:
      getRaiderManager in interface IColony
      Returns:
      the barbManager.
    • getEventManager

      public IEventManager getEventManager()
      Description copied from interface: IColony
      Get the event manager of the colony.
      Specified by:
      getEventManager in interface IColony
      Returns:
      the event manager.
    • getStatisticsManager

      public IStatisticsManager getStatisticsManager()
      Description copied from interface: IColony
      Get the statistics manager of the colony.
      Specified by:
      getStatisticsManager in interface IColony
      Returns:
      the statistics manager.
    • getReproductionManager

      public IReproductionManager getReproductionManager()
      Description copied from interface: IColony
      Get the reproduction manager of the colony.
      Specified by:
      getReproductionManager in interface IColony
      Returns:
      the reproduction manager.
    • getEventDescriptionManager

      public IEventDescriptionManager getEventDescriptionManager()
      Description copied from interface: IColony
      Get the event description manager of the colony.
      Specified by:
      getEventDescriptionManager in interface IColony
      Returns:
      the event description manager.
    • getPackageManager

      public IColonyPackageManager getPackageManager()
      Get the packagemanager of the colony.
      Specified by:
      getPackageManager in interface IColony
      Returns:
      the manager.
    • getTravellingManager

      public TravellingManager getTravellingManager()
      Description copied from interface: IColony
      Get the travelling manager of the colony.
      Specified by:
      getTravellingManager in interface IColony
      Returns:
      the travelling manager.
    • getConnectionManager

      public IColonyConnectionManager getConnectionManager()
      Description copied from interface: IColony
      Get the connection manager of the colony.
      Specified by:
      getConnectionManager in interface IColony
      Returns:
      the connection manager.
    • getVisitingPlayers

      public com.google.common.collect.ImmutableList<net.minecraft.world.entity.player.Player> getVisitingPlayers()
      Get all visiting players.
      Returns:
      the list.
    • addVisitingPlayer

      public void addVisitingPlayer(net.minecraft.world.entity.player.Player player)
      Description copied from interface: IColony
      Add a visiting player.
      Specified by:
      addVisitingPlayer in interface IColony
      Parameters:
      player - the player.
    • removeVisitingPlayer

      public void removeVisitingPlayer(net.minecraft.world.entity.player.Player player)
      Description copied from interface: IColony
      Remove a visiting player.
      Specified by:
      removeVisitingPlayer in interface IColony
      Parameters:
      player - the player.
    • getColonyTag

      public net.minecraft.nbt.CompoundTag getColonyTag()
      Get the NBT tag of the colony.
      Specified by:
      getColonyTag in interface IColony
      Returns:
      the tag of it.
    • isValidAttackingPlayer

      public boolean isValidAttackingPlayer(net.minecraft.world.entity.player.Player player)
      Is player part of a wave trying to invade the colony?
      Specified by:
      isValidAttackingPlayer in interface IColony
      Parameters:
      player - the player to check..
      Returns:
      true if so.
    • isValidAttackingGuard

      public boolean isValidAttackingGuard(AbstractEntityCitizen entity)
      Check if attack of guard is valid.
      Specified by:
      isValidAttackingGuard in interface IColony
      Parameters:
      entity - the guard entity.
      Returns:
      true if so.
    • addGuardToAttackers

      public void addGuardToAttackers(AbstractEntityCitizen IEntityCitizen, net.minecraft.world.entity.player.Player player)
      Add a guard to the list of attacking guards.
      Specified by:
      addGuardToAttackers in interface IColony
      Parameters:
      IEntityCitizen - the citizen to add.
    • isColonyUnderAttack

      public boolean isColonyUnderAttack()
      Check if the colony is currently under attack by another player.
      Specified by:
      isColonyUnderAttack in interface IColony
      Returns:
      true if so.
    • getTeamColonyColor

      public net.minecraft.ChatFormatting getTeamColonyColor()
      Getter for the colony team color.
      Specified by:
      getTeamColonyColor in interface IColony
      Returns:
      the ChatFormatting enum color.
    • getColonyFlag

      public net.minecraft.world.level.block.entity.BannerPatternLayers getColonyFlag()
      Getter for the colony flag patterns
      Specified by:
      getColonyFlag in interface IColony
      Returns:
      the list of pattern-color pairs
    • setDirty

      public void setDirty(boolean dirty)
      Set the colony to be dirty.
      Parameters:
      dirty - if dirty.
    • usedMercenaries

      public void usedMercenaries()
      Save the time when mercenaries are used, to set a cooldown.
      Specified by:
      usedMercenaries in interface IColony
    • getMercenaryUseTime

      public long getMercenaryUseTime()
      Get the last time mercenaries were used.
      Specified by:
      getMercenaryUseTime in interface IColony
      Returns:
      the mercenary use time.
    • useAdditionalChildTime

      public boolean useAdditionalChildTime(int amount)
      Description copied from interface: IColony
      Tries to use a given amount of additional growth-time for childs.
      Specified by:
      useAdditionalChildTime in interface IColony
      Parameters:
      amount - amount to use
      Returns:
      true if used up.
    • updateHasChilds

      public void updateHasChilds()
      Description copied from interface: IColony
      Sets whether the colony has a child.
      Specified by:
      updateHasChilds in interface IColony
    • addLoadedChunk

      public void addLoadedChunk(long chunkPos, net.minecraft.world.level.chunk.LevelChunk chunk)
      Description copied from interface: IColony
      Adds a loaded chunk to the colony list
      Specified by:
      addLoadedChunk in interface IColony
      Parameters:
      chunkPos - chunk to add
    • removeLoadedChunk

      public void removeLoadedChunk(long chunkPos)
      Description copied from interface: IColony
      Adds a chunk from the colony list
      Specified by:
      removeLoadedChunk in interface IColony
      Parameters:
      chunkPos - chunk to remove
    • getLoadedChunkCount

      public int getLoadedChunkCount()
      Description copied from interface: IColony
      Returns the amount of loaded chunks
      Specified by:
      getLoadedChunkCount in interface IColony
      Returns:
      amount of chunks
    • getLoadedChunks

      public Set<Long> getLoadedChunks()
      Specified by:
      getLoadedChunks in interface IColony
    • getState

      public ColonyState getState()
      Description copied from interface: IColony
      Returns the colonies current state.
      Specified by:
      getState in interface IColony
      Returns:
      the state.
    • isActive

      public boolean isActive()
      Description copied from interface: IColony
      Is the colony active currently.
      Specified by:
      isActive in interface IColony
      Returns:
      true if so.
    • isDay

      public boolean isDay()
      Description copied from interface: IColony
      Whether it is day for the colony
      Specified by:
      isDay in interface IColony
      Returns:
      true if it is day
    • getTicketedChunks

      public Set<Long> getTicketedChunks()
      Description copied from interface: IColony
      Get the set of chunk positions which the colony is loading through tickets
      Specified by:
      getTicketedChunks in interface IColony
      Returns:
      set of positions
    • setTextureStyle

      public void setTextureStyle(String style)
      Description copied from interface: IColony
      Set the texture style of the colony.
      Specified by:
      setTextureStyle in interface IColony
      Parameters:
      style - the style to set.
    • getTextureStyleId

      public String getTextureStyleId()
      Description copied from interface: IColony
      Get the colony style.
      Specified by:
      getTextureStyleId in interface IColony
      Returns:
      the string id of the style.
    • setNameStyle

      public void setNameStyle(String style)
      Description copied from interface: IColony
      Set the colony name style.
      Specified by:
      setNameStyle in interface IColony
      Parameters:
      style - the string id of the style.
    • getNameStyle

      public String getNameStyle()
      Description copied from interface: IColony
      Get the colony name style.
      Specified by:
      getNameStyle in interface IColony
      Returns:
      the string id of the style.
    • getCitizenNameFile

      public CitizenNameFile getCitizenNameFile()
      Description copied from interface: IColony
      Get the matching citizen name file of the colony .
      Specified by:
      getCitizenNameFile in interface IColony
      Returns:
      the matching file.
    • isTicketedChunksDirty

      public boolean isTicketedChunksDirty()
      Check if we need to update the view's chunk ticket info
      Returns:
      true if dirty.
    • getDay

      public int getDay()
      Description copied from interface: IColony
      Get the current day of the colony.
      Specified by:
      getDay in interface IColony
      Returns:
      the current day progress of the colony.
    • getQuestManager

      public IQuestManager getQuestManager()
      Description copied from interface: IColony
      Get the quest manager of the colony.
      Specified by:
      getQuestManager in interface IColony
      Returns:
      the quest manager.
    • getCitizen

      public ICitizen getCitizen(int id)
      Description copied from interface: IColony
      Get citizen from colony.
      Specified by:
      getCitizen in interface IColony
      Parameters:
      id - the id of the cit.
      Returns:
      the cit.
    • getSettings

      public ISettingsModule getSettings()
      Description copied from interface: IColony
      Get the colony level settings module.
      Specified by:
      getSettings in interface IColony
      Returns:
      the settings module.
    • getClaimData

      public it.unimi.dsi.fastutil.longs.Long2ObjectMap<ChunkClaimData> getClaimData()
      Get the claim data from the colony.
      Returns:
      the claim data map.
    • claimNewChunk

      public IChunkClaimData claimNewChunk(net.minecraft.world.level.ChunkPos pos)
    • setDimensionId

      public void setDimensionId(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimensionId)
      Sets the dimension ID, use with care!
      Parameters:
      dimensionId -