Class ColonyManager

java.lang.Object
com.minecolonies.core.colony.ColonyManager
All Implemented Interfaces:
IColonyManager

public final class ColonyManager extends Object implements IColonyManager
Singleton class that links colonies to minecraft.
  • Constructor Details

    • ColonyManager

      public ColonyManager()
  • Method Details

    • createColony

      public IColony createColony(@NotNull @NotNull net.minecraft.world.level.Level w, net.minecraft.core.BlockPos pos, @NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull String colonyName, @NotNull @NotNull String pack)
      Description copied from interface: IColonyManager
      Create a new Colony in the given world and at that location.
      Specified by:
      createColony in interface IColonyManager
      Parameters:
      w - World of the colony.
      pos - Coordinate of the center of the colony.
      player - the player that creates the colony - owner.
      colonyName - the initial colony name.
      pack - the default pack of the colony.
      Returns:
      the created colony instance.
    • deleteColonyByWorld

      public void deleteColonyByWorld(int id, boolean canDestroy, net.minecraft.world.level.Level world)
      Description copied from interface: IColonyManager
      Delete the colony in a world.
      Specified by:
      deleteColonyByWorld in interface IColonyManager
      Parameters:
      id - the id of it.
      canDestroy - if can destroy the buildings.
      world - the world.
    • deleteColonyByDimension

      public void deleteColonyByDimension(int id, boolean canDestroy, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension)
      Description copied from interface: IColonyManager
      Delete the colony by dimension.
      Specified by:
      deleteColonyByDimension in interface IColonyManager
      Parameters:
      id - the id of it.
      canDestroy - if can destroy the buildings.
      dimension - the dimension.
    • removeColonyView

      public void removeColonyView(int id, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension)
      Description copied from interface: IColonyManager
      Removes a colony view
      Specified by:
      removeColonyView in interface IColonyManager
      Parameters:
      id - the id of the colony.
      dimension - the dimension it is in.
    • getColonyByWorld

      @Nullable public @Nullable IColony getColonyByWorld(int id, net.minecraft.world.level.Level world)
      Description copied from interface: IColonyManager
      Get Colony by UUID.
      Specified by:
      getColonyByWorld in interface IColonyManager
      Parameters:
      id - ID of colony.
      world - the world it is in.
      Returns:
      Colony with given ID.
    • getColonyByDimension

      @Nullable public @Nullable IColony getColonyByDimension(int id, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> registryKey)
      Description copied from interface: IColonyManager
      Get Colony by UUID.
      Specified by:
      getColonyByDimension in interface IColonyManager
      Parameters:
      id - ID of colony.
      registryKey - the dimension it is in.
      Returns:
      Colony with given ID.
    • getBuilding

      public IBuilding getBuilding(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Get a AbstractBuilding by a World and coordinates.
      Specified by:
      getBuilding in interface IColonyManager
      Parameters:
      w - World.
      pos - Block position.
      Returns:
      AbstractBuilding at the given location.
    • getColonyByPosFromWorld

      public IColony getColonyByPosFromWorld(@Nullable @Nullable net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Get colony that contains a given coordinate from world.
      Specified by:
      getColonyByPosFromWorld in interface IColonyManager
      Parameters:
      w - World.
      pos - coordinates.
      Returns:
      Colony at the given location.
    • getColonyByPosFromDim

      public IColony getColonyByPosFromDim(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> registryKey, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Get colony that contains a given coordinate from dimension.
      Specified by:
      getColonyByPosFromDim in interface IColonyManager
      Parameters:
      registryKey - the dimension.
      pos - coordinates.
      Returns:
      Colony at the given location.
    • isFarEnoughFromColonies

      public boolean isFarEnoughFromColonies(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Check if a position is too close to another colony to found a new colony.
      Specified by:
      isFarEnoughFromColonies in interface IColonyManager
      Parameters:
      w - World.
      pos - coordinates.
      Returns:
      true if so.
    • getColonies

      @NotNull public @NotNull List<IColony> getColonies(@NotNull @NotNull net.minecraft.world.level.Level w)
      Description copied from interface: IColonyManager
      Get all colonies in this world.
      Specified by:
      getColonies in interface IColonyManager
      Parameters:
      w - World.
      Returns:
      a list of colonies.
    • getAllColonies

      @NotNull public @NotNull List<IColony> getAllColonies()
      Description copied from interface: IColonyManager
      Get all colonies in all worlds.
      Specified by:
      getAllColonies in interface IColonyManager
      Returns:
      a list of colonies.
    • getColoniesAbandonedSince

      @NotNull public @NotNull List<IColony> getColoniesAbandonedSince(int abandonedSince)
      Description copied from interface: IColonyManager
      Get all colonies in all worlds.
      Specified by:
      getColoniesAbandonedSince in interface IColonyManager
      Parameters:
      abandonedSince - time in hours since the last contact.
      Returns:
      a list of colonies.
    • getBuildingView

      public IBuildingView getBuildingView(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension, net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Get a AbstractBuilding by position.
      Specified by:
      getBuildingView in interface IColonyManager
      Parameters:
      dimension - the dimension it is in.
      pos - Block position.
      Returns:
      Returns the view belonging to the building at (x, y, z).
    • getIColonies

      @NotNull public @NotNull List<IColony> getIColonies(@NotNull @NotNull net.minecraft.world.level.Level w)
      Description copied from interface: IColonyManager
      Get all colonies in this world. (Side neutral; on clients it returns the subset of views known to the player.)
      Specified by:
      getIColonies in interface IColonyManager
      Parameters:
      w - World.
      Returns:
      a list of colonies.
    • getIColony

      @Nullable public @Nullable IColony getIColony(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Side neutral method to get colony. On clients it returns the view. On servers it returns the colony itself.
      Specified by:
      getIColony in interface IColonyManager
      Parameters:
      w - World.
      pos - coordinates.
      Returns:
      View of colony or colony itself depending on side.
    • openReactivationWindow

      public void openReactivationWindow(net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Open the new reactivation window.
      Specified by:
      openReactivationWindow in interface IColonyManager
      Parameters:
      pos - the pos to open it at.
    • getColonyViews

      @NotNull public @NotNull List<IColonyView> getColonyViews(@NotNull @NotNull net.minecraft.world.level.Level w)
      Description copied from interface: IColonyManager
      Get all colony views in this world known to the current player.
      Specified by:
      getColonyViews in interface IColonyManager
      Parameters:
      w - World.
      Returns:
      a list of colony views.
    • getColonyView

      public IColonyView getColonyView(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Get Colony that contains a given (x, y, z).
      Specified by:
      getColonyView in interface IColonyManager
      Parameters:
      w - World.
      pos - coordinates.
      Returns:
      returns the view belonging to the colony at x, y, z.
    • getClosestIColony

      @Nullable public @Nullable IColony getClosestIColony(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Side neutral method to get colony. On clients it returns the view. On servers it returns the colony itself. IColonyManager.getClosestColony(Level, BlockPos)
      Specified by:
      getClosestIColony in interface IColonyManager
      Parameters:
      w - World.
      pos - Block position.
      Returns:
      View of colony or colony itself depending on side, closest to coordinates.
    • getClosestColonyView

      @Nullable public @Nullable IColonyView getClosestColonyView(@Nullable @Nullable net.minecraft.world.level.Level w, @Nullable @Nullable net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Specified by:
      getClosestColonyView in interface IColonyManager
      Parameters:
      w - World.
      pos - Block Position.
      Returns:
      View of the closest colony.
    • getClosestColony

      public IColony getClosestColony(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Get closest colony by x,y,z.
      Specified by:
      getClosestColony in interface IColonyManager
      Parameters:
      w - World.
      pos - coordinates.
      Returns:
      Colony closest to coordinates.
    • getIColonyByOwner

      @Nullable public @Nullable IColony getIColonyByOwner(@NotNull @NotNull net.minecraft.world.level.Level w, @NotNull @NotNull net.minecraft.world.entity.player.Player owner)
      Description copied from interface: IColonyManager
      Side neutral method to get colony. On clients it returns the view. On servers it returns the colony itself.

      Returns a colony or view with the given Player as owner.

      Specified by:
      getIColonyByOwner in interface IColonyManager
      Parameters:
      w - World.
      owner - Entity Player.
      Returns:
      IColony belonging to specific player.
    • getIColonyByOwner

      @Nullable public @Nullable IColony getIColonyByOwner(@NotNull @NotNull net.minecraft.world.level.Level w, UUID owner)
      Description copied from interface: IColonyManager
      Side neutral method to get colony. On clients it returns the view. On servers it returns the colony itself.

      Returns a colony or view with given Player as owner.

      Specified by:
      getIColonyByOwner in interface IColonyManager
      Parameters:
      w - World
      owner - UUID of the owner.
      Returns:
      IColony belonging to specific player.
    • getMinimumDistanceBetweenTownHalls

      public int getMinimumDistanceBetweenTownHalls()
      Description copied from interface: IColonyManager
      Returns the minimum distance between two town halls, to not make colonies collide.
      Specified by:
      getMinimumDistanceBetweenTownHalls in interface IColonyManager
      Returns:
      Minimum town hall distance.
    • onServerTick

      public void onServerTick(@NotNull net.minecraftforge.event.TickEvent.ServerTickEvent event)
      Description copied from interface: IColonyManager
      On server tick, tick every Colony. NOTE: Review this for performance.
      Specified by:
      onServerTick in interface IColonyManager
      Parameters:
      event - TickEvent.ServerTickEvent
    • write

      public void write(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound)
      Description copied from interface: IColonyManager
      Write colonies to NBT data for saving.
      Specified by:
      write in interface IColonyManager
      Parameters:
      compound - NBT-Tag.
    • read

      public void read(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound)
      Description copied from interface: IColonyManager
      Read Colonies from saved NBT data.
      Specified by:
      read in interface IColonyManager
      Parameters:
      compound - NBT Tag.
    • onClientTick

      public void onClientTick(@NotNull net.minecraftforge.event.TickEvent.ClientTickEvent event)
      Description copied from interface: IColonyManager
      On Client tick, clears views when player left.
      Specified by:
      onClientTick in interface IColonyManager
      Parameters:
      event - TickEvent.ClientTickEvent.
    • onWorldTick

      public void onWorldTick(@NotNull net.minecraftforge.event.TickEvent.LevelTickEvent event)
      Description copied from interface: IColonyManager
      On world tick, tick every Colony in that world. NOTE: Review this for performance.
      Specified by:
      onWorldTick in interface IColonyManager
    • onWorldLoad

      public void onWorldLoad(@NotNull @NotNull net.minecraft.world.level.Level world)
      Description copied from interface: IColonyManager
      When a world is loaded, Colonies in that world need to grab the reference to the World. Additionally, when loading the first world, load the manager data.
      Specified by:
      onWorldLoad in interface IColonyManager
      Parameters:
      world - World.
    • setCapLoaded

      public void setCapLoaded()
      Description copied from interface: IColonyManager
      Sets the cap for this world to loaded
      Specified by:
      setCapLoaded in interface IColonyManager
    • onWorldUnload

      public void onWorldUnload(@NotNull @NotNull net.minecraft.world.level.Level world)
      Description copied from interface: IColonyManager
      When a world unloads, all colonies in that world are informed. Additionally, when the last world is unloaded, delete all colonies.
      Specified by:
      onWorldUnload in interface IColonyManager
      Parameters:
      world - World.
    • handleColonyViewMessage

      public void handleColonyViewMessage(int colonyId, @NotNull @NotNull net.minecraft.network.FriendlyByteBuf colonyData, @NotNull @NotNull net.minecraft.world.level.Level world, boolean isNewSubscription, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Sends view message to the right view.
      Specified by:
      handleColonyViewMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      colonyData - FriendlyByteBuf with colony data.
      world - the world it is in.
      isNewSubscription - whether this is a new subscription or not.
      dim - the dimension.
    • getColonyView

      public IColonyView getColonyView(int id, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension)
      Description copied from interface: IColonyManager
      Get IColonyView by ID.
      Specified by:
      getColonyView in interface IColonyManager
      Parameters:
      id - ID of colony.
      dimension - the dimension id.
      Returns:
      The IColonyView belonging to the colony.
    • handlePermissionsViewMessage

      public void handlePermissionsViewMessage(int colonyID, @NotNull @NotNull net.minecraft.network.FriendlyByteBuf data, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Specified by:
      handlePermissionsViewMessage in interface IColonyManager
      Parameters:
      colonyID - ID of the colony.
      data - FriendlyByteBuf with colony data.
      dim - the dimension.
    • handleColonyViewCitizensMessage

      public void handleColonyViewCitizensMessage(int colonyId, int citizenId, net.minecraft.network.FriendlyByteBuf buf, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Specified by:
      handleColonyViewCitizensMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      citizenId - ID of the citizen.
      buf - FriendlyByteBuf with colony data.
      dim - the dimension.
    • handleColonyViewWorkOrderMessage

      public void handleColonyViewWorkOrderMessage(int colonyId, net.minecraft.network.FriendlyByteBuf buf, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Specified by:
      handleColonyViewWorkOrderMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      buf - FriendlyByteBuf with colony data.
      dim - the dimension.
    • handleColonyViewRemoveCitizenMessage

      public void handleColonyViewRemoveCitizenMessage(int colonyId, int citizenId, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Specified by:
      handleColonyViewRemoveCitizenMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      citizenId - ID of the citizen.
      dim - the dimension.
    • handleColonyBuildingViewMessage

      public void handleColonyBuildingViewMessage(int colonyId, net.minecraft.core.BlockPos buildingId, @NotNull @NotNull net.minecraft.network.FriendlyByteBuf buf, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Returns result of IColonyView#handleColonyBuildingViewMessage(BlockPos, FriendlyByteBuf) if IColonyManager.getColonyView(int, ResourceKey) gives a not-null result. If IColonyManager.getColonyView(int, ResourceKey) is null, returns null.
      Specified by:
      handleColonyBuildingViewMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      buildingId - ID of the building.
      buf - FriendlyByteBuf with colony data.
      dim - the dimension.
    • handleColonyViewRemoveBuildingMessage

      public void handleColonyViewRemoveBuildingMessage(int colonyId, net.minecraft.core.BlockPos buildingId, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Returns result of IColonyView#handleColonyViewRemoveBuildingMessage(BlockPos) if IColonyManager.getColonyView(int, ResourceKey) gives a not-null result. If IColonyManager.getColonyView(int, ResourceKey) is null, returns null.
      Specified by:
      handleColonyViewRemoveBuildingMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      buildingId - ID of the building.
      dim - the dimension.
    • handleColonyViewRemoveWorkOrderMessage

      public void handleColonyViewRemoveWorkOrderMessage(int colonyId, int workOrderId, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Description copied from interface: IColonyManager
      Specified by:
      handleColonyViewRemoveWorkOrderMessage in interface IColonyManager
      Parameters:
      colonyId - ID of the colony.
      workOrderId - ID of the workOrder.
      dim - the dimension.
    • isSchematicDownloaded

      public boolean isSchematicDownloaded()
      Description copied from interface: IColonyManager
      Whether or not a new schematic have been downloaded.
      Specified by:
      isSchematicDownloaded in interface IColonyManager
      Returns:
      True if a new schematic have been received.
    • setSchematicDownloaded

      public void setSchematicDownloaded(boolean downloaded)
      Description copied from interface: IColonyManager
      Set the schematic downloaded
      Specified by:
      setSchematicDownloaded in interface IColonyManager
      Parameters:
      downloaded - True if a new schematic have been received.
    • isCoordinateInAnyColony

      public boolean isCoordinateInAnyColony(@NotNull @NotNull net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Description copied from interface: IColonyManager
      Check if a given coordinate is inside any other colony.
      Specified by:
      isCoordinateInAnyColony in interface IColonyManager
      Parameters:
      world - the world to check in.
      pos - the position to check.
      Returns:
      true if a colony has been found.
    • getCompatibilityManager

      public ICompatibilityManager getCompatibilityManager()
      Description copied from interface: IColonyManager
      Get an instance of the compatibilityManager.
      Specified by:
      getCompatibilityManager in interface IColonyManager
      Returns:
      the manager.
    • getRecipeManager

      public IRecipeManager getRecipeManager()
      Description copied from interface: IColonyManager
      Getter for the recipeManager.
      Specified by:
      getRecipeManager in interface IColonyManager
      Returns:
      an IRecipeManager.
    • getTopColonyId

      public int getTopColonyId()
      Description copied from interface: IColonyManager
      Get the top colony id of all colonies.
      Specified by:
      getTopColonyId in interface IColonyManager
      Returns:
      the top id.
    • resetColonyViews

      public void resetColonyViews()
      Description copied from interface: IColonyManager
      Reset all colony views on login to new world.
      Specified by:
      resetColonyViews in interface IColonyManager