Class AbstractBuilding

All Implemented Interfaces:
IBuilding, IBuildingContainer, ICommonBuilding, ISchematicProvider, IBuildingModuleContainer, IModuleContainer<IBuildingModule>, IRequester, IRequestResolverProvider, IItemHandlerCapProvider, net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
Direct Known Subclasses:
AbstractBuildingGuards, AbstractBuildingStructureBuilder, BuildingAlchemist, BuildingArchery, BuildingBaker, BuildingBarracks, BuildingBeekeeper, BuildingBlacksmith, BuildingChickenHerder, BuildingCombatAcademy, BuildingComposter, BuildingConcreteMixer, BuildingCook, BuildingCowboy, BuildingCrusher, BuildingDeliveryman, BuildingDyer, BuildingEnchanter, BuildingFarmer, BuildingFisherman, BuildingFletcher, BuildingFlorist, BuildingGlassblower, BuildingGraveyard, BuildingHospital, BuildingKitchen, BuildingLibrary, BuildingLumberjack, BuildingMechanic, BuildingMysticalSite, BuildingNetherWorker, BuildingPlantation, BuildingRabbitHutch, BuildingSawmill, BuildingSchool, BuildingShepherd, BuildingSifter, BuildingSmeltery, BuildingStonemason, BuildingStoneSmeltery, BuildingSwineHerder, BuildingTownHall, BuildingUniversity, BuildingWareHouse, DefaultBuildingInstance, PostBox, Stash

public abstract class AbstractBuilding extends AbstractBuildingContainer
Base building class, has all the foundation for what a building stores and does.

We suppress the warning which warns you about referencing child classes in the parent because that's how we register the instances of the childClasses to their views and blocks.

  • Field Details

  • Constructor Details

    • AbstractBuilding

      protected AbstractBuilding(@NotNull @NotNull IColony colony, net.minecraft.core.BlockPos pos)
      Constructor for a AbstractBuilding.
      Parameters:
      colony - Colony the building belongs to.
      pos - Location of the building (it's Hut Block).
  • Method Details

    • getModules

      @NotNull public @NotNull List<IBuildingModule> getModules()
      Description copied from interface: IModuleContainer
      Get a list containing all modules registered to this container.
      Returns:
      the list of all modules.
    • getClassType

      @NotNull public @NotNull Class<IBuildingModule> getClassType()
      Description copied from interface: IModuleContainer
      Get the class type of the module container.
      Returns:
      the class type.
    • hasModule

      public boolean hasModule(BuildingEntry.ModuleProducer<?,?> producer)
      Description copied from interface: IBuildingModuleContainer
      Check if the object has a particular module.
      Parameters:
      producer - the module producer for the module
      Returns:
      true if so.
    • getModule

      public <M extends IBuildingModule, V extends IBuildingModuleView> M getModule(BuildingEntry.ModuleProducer<M,V> producer)
      Description copied from interface: IBuildingModuleContainer
      Get the first module with a particular class or interface.
      Returns:
      the module or empty if not existent.
    • getModule

      public IBuildingModule getModule(int id)
      Description copied from interface: IBuildingModuleContainer
      Get the first module with a particular class or interface.
      Returns:
      the module or empty if not existent.
    • registerModule

      public void registerModule(@NotNull @NotNull IBuildingModule module)
      Description copied from interface: IBuildingModuleContainer
      Register a specific module to the object.
      Parameters:
      module - the module to register.
    • getCustomName

      @NotNull public @NotNull String getCustomName()
      Getter for the custom name of a building.
      Returns:
      the custom name.
    • getBuildingDisplayName

      @NotNull public @NotNull String getBuildingDisplayName()
      Getter for the custom name of a building. Returns either the custom name (if any) or the translation key.
      Returns:
      the custom name or the schematic name.
    • onWakeUp

      public void onWakeUp()
      Executed when a new day start.
    • onCleanUp

      public void onCleanUp(ICitizenData citizen)
      Executed every time when citizen finish inventory cleanup called after citizen got paused. Use for cleaning a state only.
      Parameters:
      citizen - cleanup for citizen.
    • onRestart

      public void onRestart(ICitizenData citizen)
      Executed when RestartCitizenMessage is called and worker is paused. Use for reseting, onCleanUp is called before this
      Parameters:
      citizen - the citizen assigned to the building.
    • onPlayerEnterBuilding

      public void onPlayerEnterBuilding(net.minecraft.world.entity.player.Player player)
      Description copied from interface: IBuilding
      Called when a player enters the building area
      Parameters:
      player - entering player
    • onPlayerEnterNearby

      public void onPlayerEnterNearby(net.minecraft.world.entity.player.Player player)
      Description copied from interface: IBuilding
      Called when a player comes close to the building.
      Parameters:
      player - entering player
    • onPlacement

      public void onPlacement()
      On setting down the building.
    • isMatchingBlock

      public boolean isMatchingBlock(@NotNull @NotNull net.minecraft.world.level.block.Block block)
      Checks if a block matches the current object.
      Parameters:
      block - Block you want to know whether it matches this class or not.
      Returns:
      True if the block matches this class, otherwise false.
    • deserializeNBT

      public void deserializeNBT(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag compound)
      Specified by:
      deserializeNBT in interface IBuildingContainer
      Specified by:
      deserializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
      Overrides:
      deserializeNBT in class AbstractBuildingContainer
    • serializeNBT

      public net.minecraft.nbt.CompoundTag serializeNBT(net.minecraft.core.HolderLookup.Provider provider)
      Specified by:
      serializeNBT in interface IBuildingContainer
      Specified by:
      serializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
      Overrides:
      serializeNBT in class AbstractBuildingContainer
    • destroy

      public void destroy()
      Destroys the block. Calls onDestroyed().
    • onDestroyed

      public void onDestroyed()
    • requestWorkOrder

      protected void requestWorkOrder(WorkOrderType type, net.minecraft.core.BlockPos builder)
      Adds work orders to the Colony.getWorkManager().
      Parameters:
      type - what to do with the work order
      builder - the assigned builder.
    • canDeconstruct

      public boolean canDeconstruct()
      Check if this particular building can be deconstructed.
      Returns:
      true if so.
    • canBeBuiltByBuilder

      public boolean canBeBuiltByBuilder(int newLevel)
      Method to define if a builder can build this although the builder is not level 1 yet.
      Parameters:
      newLevel - the new level of the building.
      Returns:
      true if so.
    • markDirty

      public final void markDirty()
      Description copied from interface: ISchematicProvider
      Marks the instance and the building dirty.
    • isDirty

      public final boolean isDirty()
      Description copied from interface: ISchematicProvider
      Returns whether the instance is dirty or not.
      Returns:
      true if dirty, false if not.
    • clearDirty

      public final void clearDirty()
      Description copied from interface: ISchematicProvider
      Sets #dirty to false, meaning that the instance is up to date.
    • processOfflineTime

      public void processOfflineTime(long time)
      Description copied from interface: IBuilding
      Process time the colony was offline.
      Parameters:
      time - the time in seconds.
    • isPendingConstruction

      public boolean isPendingConstruction()
      Checks if this building have a work order.
      Returns:
      true if the building is building, upgrading or repairing.
    • removeWorkOrder

      public void removeWorkOrder()
      Remove the work order for the building.

      Remove either the upgrade or repair work order

    • getAllAssignedCitizen

      public Set<ICitizenData> getAllAssignedCitizen()
      Description copied from interface: IBuilding
      Get the set of all assigned citizens in the colony.
      Returns:
      the list
    • getClaimRadius

      public int getClaimRadius(int newLevel)
      Method to calculate the radius to be claimed by this building depending on the level.
      Parameters:
      newLevel - the new level of the building.
      Returns:
      the radius.
    • serializeToView

      public void serializeToView(@NotNull @NotNull net.minecraft.network.RegistryFriendlyByteBuf buf, boolean fullSync)
      Serializes to view.
      Parameters:
      buf - RegistryFriendlyByteBuf to write to.
      fullSync - Whether it's a full sync
    • onColonyTick

      public void onColonyTick(IColony colony)
      Regularly tick this building and check if we got the minimum stock(like once a minute is still fine) - If not: Check if there is a request for this already. -- If not: Create a request. - If so: Check if there is a request for this still. -- If so: cancel it.
      Specified by:
      onColonyTick in interface IBuilding
      Overrides:
      onColonyTick in class AbstractSchematicProvider
    • setCustomBuildingName

      public void setCustomBuildingName(String name)
      Set the custom building name of the building.
      Parameters:
      name - the name to set.
    • canBeGathered

      public boolean canBeGathered()
      Check if the building should be gathered by the dman.
      Returns:
      true if so.
    • requestUpgrade

      public void requestUpgrade(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos builder)
      Requests an upgrade for the current building.
      Parameters:
      player - the requesting player.
      builder - the assigned builder.
    • requestRemoval

      public void requestRemoval(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos builder)
      Description copied from interface: IBuilding
      Requests a removal for the current building.
      Parameters:
      player - the requesting player.
      builder - the assigned builder.
    • pickUp

      public void pickUp(net.minecraft.world.entity.player.Player player)
      Description copied from interface: IBuilding
      Pickup the building including the level and put it in the players inv.
      Parameters:
      player - the player picking it up.
    • requestRepair

      public void requestRepair(net.minecraft.core.BlockPos builder)
      Requests a repair for the current building.
      Parameters:
      builder - the assigned builder.
    • isBuilt

      public boolean isBuilt()
      Check if the building was built already.
      Returns:
      true if so.
    • deconstruct

      public void deconstruct()
      Deconstruct the building on destroyed.
    • getTileEntity

      public AbstractTileEntityColonyBuilding getTileEntity()
      Description copied from interface: IBuildingContainer
      Returns the tile entity that belongs to the colony building.
      Returns:
      AbstractTileEntityColonyBuilding object of the building.
    • onUpgradeComplete

      public void onUpgradeComplete(@Nullable @Nullable com.ldtteam.structurize.blueprints.v1.Blueprint blueprint, int newLevel)
      Description copied from interface: IBuilding
      Called upon completion of an upgrade process. We suppress this warning since this parameter will be used in child classes which override this method.
      Parameters:
      newLevel - The new level.
    • calculatePrestige

      public void calculatePrestige(com.ldtteam.structurize.blueprints.v1.Blueprint blueprint)
      Description copied from interface: IBuilding
      Recalculate prestige for building.
      Parameters:
      blueprint - the blueprint as a basis.
    • calculateCorners

      public void calculateCorners()
      Description copied from interface: IBuilding
      Calculate all building corners from the schematic data.
    • isGuardBuildingNear

      public boolean isGuardBuildingNear()
      Description copied from interface: IBuilding
      Whether this building has a guard building nearby
      Returns:
      true/false
    • resetGuardBuildingNear

      public void resetGuardBuildingNear()
      Description copied from interface: IBuilding
      Requests recalculation of whether this building has a guard building nearby
    • buildingRequiresCertainAmountOfItem

      public int buildingRequiresCertainAmountOfItem(net.minecraft.world.item.ItemStack stack, List<ItemStorage> localAlreadyKept, boolean inventory, JobEntry jobEntry)
      Description copied from interface: IBuilding
      Check if the worker requires a certain amount of that item and the alreadykept list contains it. Always leave one stack behind if the worker requires a certain amount of it. Just to be sure.
      Parameters:
      stack - the stack to check it with.
      localAlreadyKept - already kept items.
      inventory - if it should be in the inventory or in the building.
      jobEntry - the job entry trying to dump.
      Returns:
      the amount which can get dumped or 0 if not.
    • getRequiredItemsAndAmount

      public Map<Predicate<net.minecraft.world.item.ItemStack>,net.minecraft.util.Tuple<Integer,Boolean>> getRequiredItemsAndAmount()
      Override this method if you want to keep an amount of items in inventory. When the inventory is full, everything get's dumped into the building chest. But you can use this method to hold some stacks back.
      Returns:
      a list of objects which should be kept.
    • getPrestige

      public int getPrestige()
      Description copied from interface: ICommonBuilding
      Get the prestige value of the building.
      Returns:
      the prestige value.
    • getMaxBuildingLevel

      public int getMaxBuildingLevel()
      Description copied from interface: ISchematicProvider
      Children must return their max building level.
      Returns:
      Max building level.
    • getHandlers

      public List<net.neoforged.neoforge.items.IItemHandler> getHandlers()
      Description copied from interface: IBuilding
      Get all handlers associated with this building.
      Returns:
      the handlers of the building + citizen.
    • getSetting

      public <T extends ISetting<S>, S> T getSetting(@NotNull @NotNull ISettingKey<T> key)
      Description copied from interface: IBuilding
      Get setting for key. Utility function.
      Type Parameters:
      T - the key type.
      Parameters:
      key - the key.
      Returns:
      the setting.
    • getSettingValueOrDefault

      public <T extends ISetting<S>, S> S getSettingValueOrDefault(@NotNull @NotNull ISettingKey<T> key, @NotNull S def)
      Description copied from interface: IBuilding
      Get setting value for key or some default. Utility function.
      Type Parameters:
      T - the key type.
      Parameters:
      key - the key.
      def - the default.
      Returns:
      the setting.
    • getCraftingModuleForRecipe

      public ICraftingBuildingModule getCraftingModuleForRecipe(IToken<?> token)
      Get the right module for the recipe.
      Parameters:
      token - the recipe trying to be fulfilled.
      Returns:
      the matching module.
    • keepFood

      protected boolean keepFood()
      If the worker should keep some food in the inventory/building.
      Returns:
      true if so.
    • forceTransferStack

      @Nullable public @Nullable net.minecraft.world.item.ItemStack forceTransferStack(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world)
      Try to transfer a stack to one of the inventories of the building and force the transfer.
      Parameters:
      stack - the stack to transfer.
      world - the world to do it in.
      Returns:
      the itemStack which has been replaced or the itemStack which could not be transfered
    • isItemStackInRequest

      public boolean isItemStackInRequest(@Nullable @Nullable net.minecraft.world.item.ItemStack stack)
      Description copied from interface: IBuilding
      Check if a certain ItemStack is in the request of a worker.
      Parameters:
      stack - the stack to chest.
      Returns:
      true if so.
    • writeRequestSystemToNBT

      protected void writeRequestSystemToNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag compound)
    • setupRsDataStore

      protected void setupRsDataStore()
    • getOpenRequestsByRequestableType

      public Map<com.google.common.reflect.TypeToken<?>,Collection<IToken<?>>> getOpenRequestsByRequestableType()
      Description copied from interface: IBuilding
      Get a map of all open requests by type.
      Returns:
      the map.
    • getOpenRequestsByCitizen

      protected Map<Integer,Collection<IToken<?>>> getOpenRequestsByCitizen()
    • createRequest

      public <R extends IRequestable> IToken<?> createRequest(@NotNull @NotNull ICitizenData citizenData, @NotNull R requested, boolean async)
      Create a request for a citizen.
      Type Parameters:
      R - the type of the request.
      Parameters:
      citizenData - the data of the citizen.
      requested - the request to create.
      async - if async or not.
      Returns:
      the Token of the request.
    • createRequest

      public <R extends IRequestable> IToken<?> createRequest(@NotNull R requested, boolean async)
      Create a request for the building.
      Type Parameters:
      R - the type of the request.
      Parameters:
      requested - the request to create.
      async - if async or not.
      Returns:
      the Token of the request.
    • registerBlockPosition

      public void registerBlockPosition(@NotNull @NotNull net.minecraft.world.level.block.state.BlockState blockState, @NotNull @NotNull net.minecraft.core.BlockPos pos, @NotNull @NotNull net.minecraft.world.level.Level world)
      Description copied from interface: IBuildingContainer
      Register a blockState and position. We suppress this warning since this parameter will be used in child classes which override this method.
      Specified by:
      registerBlockPosition in interface IBuildingContainer
      Overrides:
      registerBlockPosition in class AbstractBuildingContainer
      Parameters:
      blockState - to be registered
      pos - of the blockState
      world - world to register it at.
    • hasWorkerOpenRequests

      public boolean hasWorkerOpenRequests(int citizenId)
    • getOpenRequests

      public Collection<IRequest<?>> getOpenRequests(int citizenId)
    • hasWorkerOpenRequestsFiltered

      public boolean hasWorkerOpenRequestsFiltered(int citizenId, @NotNull @NotNull Predicate<IRequest<?>> selectionPredicate)
    • hasOpenSyncRequest

      public boolean hasOpenSyncRequest(@NotNull @NotNull ICitizenData citizen)
      Description copied from interface: IBuilding
      Checks whether the citizen has an open sync request, preventing it from working
      Parameters:
      citizen - citizen data to check
      Returns:
      true if an open non async request exists
    • hasWorkerOpenRequestsOfType

      public <R> boolean hasWorkerOpenRequestsOfType(int citizenId, com.google.common.reflect.TypeToken<R> requestType)
    • getOpenRequestsOfType

      public <R> com.google.common.collect.ImmutableList<IRequest<? extends R>> getOpenRequestsOfType(int citizenId, com.google.common.reflect.TypeToken<R> requestType)
    • createPickupRequest

      public boolean createPickupRequest(int qty, boolean force)
      Description copied from interface: IBuilding
      Creates a pickup request for the building. It will make sure that only one pickup request exists per building, so it's safe to call multiple times. The call will return false if a pickup request already exists, or if the priority is not within the proper range, or if the pickup priority is set to NEVER (0).
      Parameters:
      qty - the qty of items to be picked up.
      force - if the pickup should be forced.
      Returns:
      true if a pickup request could be created, false if not.
    • hasCitizenCompletedRequests

      public boolean hasCitizenCompletedRequests(@NotNull @NotNull ICitizenData data)
    • hasCitizenCompletedRequestsToPickup

      public boolean hasCitizenCompletedRequestsToPickup(@NotNull @NotNull ICitizenData data)
    • getCompletedRequestsOfCitizenOrBuilding

      public Collection<IRequest<?>> getCompletedRequestsOfCitizenOrBuilding(@Nullable @Nullable ICitizenData data)
      Description copied from interface: IBuilding
      Get completed requests for citizen or building (citizen independent, so if data is null)
      Parameters:
      data - the citizen data (or null).
      Returns:
      a collection of request.
    • getCompletedRequestsOfType

      public <R> com.google.common.collect.ImmutableList<IRequest<? extends R>> getCompletedRequestsOfType(@NotNull @NotNull ICitizenData citizenData, com.google.common.reflect.TypeToken<R> requestType)
    • getCompletedRequestsOfTypeFiltered

      public <R> com.google.common.collect.ImmutableList<IRequest<? extends R>> getCompletedRequestsOfTypeFiltered(@NotNull @NotNull ICitizenData citizenData, com.google.common.reflect.TypeToken<R> requestType, Predicate<IRequest<? extends R>> filter)
    • markRequestAsAccepted

      public void markRequestAsAccepted(@NotNull @NotNull ICitizenData data, @NotNull @NotNull IToken<?> token)
    • cancelAllRequestsOfCitizenOrBuilding

      public void cancelAllRequestsOfCitizenOrBuilding(@Nullable @Nullable ICitizenData data)
      Description copied from interface: IBuilding
      Cancel all requests of citizen or building (if citizen data is null)
      Parameters:
      data - the citizen data (or null).
    • overruleNextOpenRequestWithStack

      public void overruleNextOpenRequestWithStack(@NotNull @NotNull net.minecraft.world.item.ItemStack stack)
      Overrule the next open request with a give stack.

      We squid:s135 which takes care that there are not too many continue statements in a loop since it makes sense here out of performance reasons.

      Parameters:
      stack - the stack.
    • getOpenRequestsOfTypeFiltered

      public <R> com.google.common.collect.ImmutableList<IRequest<? extends R>> getOpenRequestsOfTypeFiltered(@NotNull @NotNull ICitizenData citizenData, com.google.common.reflect.TypeToken<R> requestType, Predicate<IRequest<? extends R>> filter)
    • overruleNextOpenRequestOfCitizenWithStack

      public boolean overruleNextOpenRequestOfCitizenWithStack(@NotNull @NotNull ICitizenData citizenData, @NotNull @NotNull net.minecraft.world.item.ItemStack stack)
    • getId

      public IToken<?> getId()
      Description copied from interface: IRequestResolverProvider
      Unique token identifying this provider inside the request management system.
      Returns:
      the token.
    • getResolvers

      public final com.google.common.collect.ImmutableCollection<IRequestResolver<?>> getResolvers()
      Description copied from interface: IRequestResolverProvider
      Method to get the resolvers that this provider provides.
      Returns:
      a list of resolvers.
    • createResolvers

      public com.google.common.collect.ImmutableCollection<IRequestResolver<?>> createResolvers()
    • getRequester

      public IRequester getRequester()
    • getLocation

      @NotNull public @NotNull ILocation getLocation()
      Description copied from interface: IRequester
      Method to get the location of this locatable.
      Returns:
      the location.
    • onRequestedRequestComplete

      public void onRequestedRequestComplete(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Method called by the request system to notify this requester that a request is complete.
      Parameters:
      manager - the request manager.
      request - the request.
    • onRequestedRequestCancelled

      public void onRequestedRequestCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Method called by the request system to notify this requester that a request has been overruled.
      Parameters:
      manager - the request manager.
      request - the request.
    • getRequesterDisplayName

      @NotNull public @NotNull net.minecraft.network.chat.MutableComponent getRequesterDisplayName(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Gets the name of the requester that requested the request given by the token.
      Parameters:
      manager - the request manager.
      request - the request for which the name of the requester is retrieved
      Returns:
      The display name of the requester.
    • getCitizenForRequest

      public Optional<ICitizenData> getCitizenForRequest(@NotNull @NotNull IToken<?> token)
    • reservedStacksExcluding

      public Map<ItemStorage,Integer> reservedStacksExcluding(@NotNull @NotNull IRequest<? extends IDeliverable> excluded)
      Description copied from interface: IBuilding
      Calculate the number of reserved stacks the resolver can't touch.
      Parameters:
      excluded - ignore reservations that would exist for the current request.
      Returns:
      a list of itemstorages.
    • getOpenRequestsOfCitizenOrBuilding

      public List<IRequest<?>> getOpenRequestsOfCitizenOrBuilding(int citizenId, Predicate<IRequest<?>> selectionPredicate)
      Get a list of open requests from the building that are filtered by a predicate for citizen id or building (-1).
      Parameters:
      citizenId - the citizen id to include.
      selectionPredicate - the selection predicate.
      Returns:
      the list.
    • getCompletedRequestsOfCitizenOrBuilding

      public List<IRequest<?>> getCompletedRequestsOfCitizenOrBuilding(@Nullable @Nullable ICitizenData citizenData, Predicate<IRequest<?>> selectionPredicate)
      Get a list of closed requests from the building that are filtered by a predicate for citizen or building (null citizen).
      Parameters:
      citizenData - the citizen to include.
      selectionPredicate - the selection predicate.
      Returns:
      the list.
    • moveToSyncCitizen

      public void moveToSyncCitizen(ICitizenData citizenData, IRequest<?> request)
      Move request from building (-1) to citizen and mark synchronous.
      Parameters:
      citizenData - the citizen to move it to.
      request - the request to move.