Class AbstractEntityAIStructure<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>

Type Parameters:
J - the job type this AI has to do.
All Implemented Interfaces:
ITickingStateAI
Direct Known Subclasses:
AbstractEntityAIStructureWithWorkOrder

public abstract class AbstractEntityAIStructure<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder> extends AbstractEntityAIInteract<J,B>
This base ai class is used by ai's who need to build entire structures. These structures have to be supplied as schematics files.

Once an ai starts building a structure, control over it is only given back once that is done.

If the ai resets, the structure is gone, so just restart building and no progress will be reset.

  • Field Details

    • BUILD_BLOCK_DELAY

      protected static final int BUILD_BLOCK_DELAY
      Building block delay
      See Also:
    • structurePlacer

      protected Tuple<com.ldtteam.structurize.placement.StructurePlacer,BuildingStructureHandler<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>> structurePlacer
      The current structure task to be build.
    • limitReached

      protected boolean limitReached
      If the structure state is currently reached limit rather than block placement.
    • loadingBlueprint

      protected boolean loadingBlueprint
      We're waiting for the blueprint to finish loading.
    • DONT_TOUCH_PREDICATE

      protected net.neoforged.neoforge.common.util.TriPredicate<com.ldtteam.structurize.util.BlueprintPositionInfo,net.minecraft.core.BlockPos,com.ldtteam.structurize.placement.structure.IStructureHandler> DONT_TOUCH_PREDICATE
      Predicate defining things we don't want the builders to ever touch.
    • workFrom

      protected net.minecraft.core.BlockPos workFrom
      Position where the Builders constructs from.
    • prevBlockPosition

      protected net.minecraft.core.BlockPos prevBlockPosition
      Previous Position where the Builders constructed from.
    • blockToMine

      protected net.minecraft.core.BlockPos blockToMine
      Block to mine.
    • gotoPos

      protected net.minecraft.core.BlockPos gotoPos
      Block to go to when building
  • Constructor Details

    • AbstractEntityAIStructure

      protected AbstractEntityAIStructure(@NotNull J job)
      Creates this ai base class and set's up important things.

      Always use this constructor!

      Parameters:
      job - the job class of the ai using this base class.
  • Method Details

    • startWorkingAtOwnBuilding

      protected IAIState startWorkingAtOwnBuilding()
      Start working at own building. Override for worker specific implementations.
      Returns:
      next state.
    • pickUpMaterial

      public IAIState pickUpMaterial()
      State to pick up material before going back to work.
      Returns:
      the next state to go to.
    • completeBuild

      protected IAIState completeBuild()
      Completition logic.
      Returns:
      the final state after completition.
    • startBuilding

      @NotNull protected @NotNull IAIState startBuilding()
      Start building this StructureIterator.

      Will determine where to start.

      Returns:
      the new State to start in.
    • afterStructureLoading

      public IAIState afterStructureLoading()
      The next state after structure loading.
      Returns:
      the next state.
    • walkToConstructionSite

      public abstract boolean walkToConstructionSite(net.minecraft.core.BlockPos currentBlock)
      Walk to the current construction site.

      Calculates and caches the position where to walk to.

      Parameters:
      currentBlock - the current block it is working on.
      Returns:
      true while walking to the site.
    • isDecoItem

      protected static boolean isDecoItem(net.minecraft.world.level.block.Block block)
      Checks for blocks that need to be treated as deco
    • structureStep

      protected IAIState structureStep()
      The Structure step to execute the actual placement actions etc.
      Returns:
      the next step to go to.
    • getPosToWorkAt

      protected net.minecraft.core.BlockPos getPosToWorkAt()
      Get the position the citizen needs to walk to in order to build
      Returns:
      the position to go to
    • goToNextStage

      protected boolean goToNextStage(com.ldtteam.structurize.placement.StructurePhasePlacementResult result)
      This method is called when a stage is finished, and it is needed to go to the next stage
      Returns:
      whether it succeeded, i.e. there was a next stage to go to.
    • skipBuilding

      protected boolean skipBuilding(com.ldtteam.structurize.util.BlueprintPositionInfo info, net.minecraft.core.BlockPos pos, com.ldtteam.structurize.placement.structure.IStructureHandler handler)
      Checks wich blocks are skipped on building
      Parameters:
      info -
      pos -
      handler -
      Returns:
    • skipClearing

      protected boolean skipClearing(com.ldtteam.structurize.util.BlueprintPositionInfo info, net.minecraft.core.BlockPos pos, com.ldtteam.structurize.placement.structure.IStructureHandler handler)
      Checks which blocks are skipped on clearing
      Parameters:
      info -
      pos -
      handler -
      Returns:
    • getPlaceSpeedLevel

      public abstract int getPlaceSpeedLevel()
      Get the level that affects the place speed.
      Returns:
      the level.
    • getStateAfterPickUp

      public IAIState getStateAfterPickUp()
      Description copied from class: AbstractEntityAIBasic
      The state to transform to after picking up things.
      Overrides:
      getStateAfterPickUp in class AbstractEntityAIBasic<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>
      Returns:
      the next state to go to.
    • afterRequestPickUp

      public IAIState afterRequestPickUp()
      Description copied from class: AbstractEntityAIBasic
      What to do after picking up a request.
      Overrides:
      afterRequestPickUp in class AbstractEntityAIBasic<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>
      Returns:
      the next state to go to.
    • afterDump

      public IAIState afterDump()
      Description copied from class: AbstractEntityAIBasic
      State to go to after dumping.
      Overrides:
      afterDump in class AbstractEntityAIBasic<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>
      Returns:
      the next state.
    • doMining

      public IAIState doMining()
      Separate step for mining.
      Returns:
      the next state to go to.
    • loadStructure

      public void loadStructure(@NotNull @NotNull IBuilderWorkOrder workOrder, net.minecraft.core.BlockPos position, boolean removal)
      Loads the structure given the name, rotation and position.
      Parameters:
      workOrder - the work order.
      position - the position to set it.
      removal - if removal step.
    • setStructurePlacer

      public void setStructurePlacer(BuildingStructureHandler<J,B> structure)
      Set the structure placer.
      Parameters:
      structure - the placer.
    • hasListOfResInInvOrRequest

      public static <J extends AbstractJobStructure<?, J>, B extends AbstractBuildingStructureBuilder> AbstractEntityAIStructure.ItemCheckResult hasListOfResInInvOrRequest(@NotNull @NotNull AbstractEntityAIStructure<J,B> placer, List<net.minecraft.world.item.ItemStack> itemList, boolean force)
      Check the placers inventory for the items in the itemList and remove it of the list if found.
      Parameters:
      placer - the placer.
      itemList - the list to check.
      force - if force insertion.
      Returns:
      true if need to request.
    • loadRequirements

      public IAIState loadRequirements()
      Load all requirements of the structure.
      Returns:
      the next state to go to.
    • requestMaterials

      public boolean requestMaterials()
      Iterates through all the required resources and stores them in the building.
      Returns:
      true if finished.
    • registerBlockAsNeeded

      public void registerBlockAsNeeded(net.minecraft.world.item.ItemStack stack)
      Register the block as needed at the building if possible.
      Parameters:
      stack - the stack.
    • storeProgressPos

      public void storeProgressPos(net.minecraft.core.BlockPos blockPos, BuildingProgressStage stage)
      Store the progressPos in the building if possible for the worker.
      Parameters:
      blockPos - the progressResult.
      stage - the current stage.
    • getWorkingPosition

      public net.minecraft.core.BlockPos getWorkingPosition(net.minecraft.core.BlockPos targetPosition)
      Calculates the working position.

      Takes a min distance from width and length.

      Then finds the floor level at that distance and then check if it does contain two air levels.

      Overrides:
      getWorkingPosition in class AbstractEntityAIBasic<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>
      Parameters:
      targetPosition - the position to work at.
      Returns:
      BlockPos position to work from.
    • isBlockFree

      public static boolean isBlockFree(@Nullable @Nullable net.minecraft.world.level.block.state.BlockState block)
      Defines blocks that can be built for free.
      Parameters:
      block - The block to check if it is free.
      Returns:
      true or false.
    • isAlreadyCleared

      protected boolean isAlreadyCleared()
      Let childs overwrite this if necessary.
      Returns:
      true if so.
    • getCurrentBuildingPosition

      @Nullable public @Nullable net.minecraft.core.BlockPos getCurrentBuildingPosition()
      Get the current block being placed/removed. May be null if nothing is loaded yet.
      Returns:
      the current building position, or null.
    • getCurrentWorkingPosition

      protected net.minecraft.core.BlockPos getCurrentWorkingPosition()
      Get the current working position for the worker. If workFrom is null calculate a new one.
      Returns:
      the current working position.
    • isThereAStructureToBuild

      protected boolean isThereAStructureToBuild()
      Check if there is a StructureIterator to be build.
      Returns:
      true if we should start building.
    • reduceNeededResources

      public void reduceNeededResources(net.minecraft.world.item.ItemStack stack)
      Reduces the needed resources by 1.
      Parameters:
      stack - the stack which has been used now.
    • checkForExtraBuildingActions

      public void checkForExtraBuildingActions()
      Check for extra building options to do with each block.
    • handleSpecificCancelActions

      public void handleSpecificCancelActions()
      Specific actions to handle a cancellation of a structure.
    • getTotalAmount

      @Nullable public @Nullable net.minecraft.world.item.ItemStack getTotalAmount(@Nullable @Nullable net.minecraft.world.item.ItemStack stack)
      Check how much of a certain stuck is actually required.
      Parameters:
      stack - the stack to check.
      Returns:
      the new stack with the correct amount.
    • resetCurrentStructure

      public void resetCurrentStructure()
      Set the currentStructure to null.
    • getWorker

      public AbstractEntityCitizen getWorker()
      Get the worker of the AI.
      Returns:
      the EntityCitizen object.
    • getProgressPos

      public abstract Tuple<net.minecraft.core.BlockPos,BuildingProgressStage> getProgressPos()
      Get the current structure progress,
      Returns:
      the progress with the current stage.
    • shallReplaceSolidSubstitutionBlock

      public abstract boolean shallReplaceSolidSubstitutionBlock(net.minecraft.world.level.block.Block worldBlock, net.minecraft.world.level.block.state.BlockState worldMetadata)
      Check if a solid substitution block should be overwritten in a specific case.
      Parameters:
      worldBlock - the worldblock.
      worldMetadata - the world metadata.
      Returns:
      true if should be overwritten.
    • getSolidSubstitution

      public net.minecraft.world.level.block.state.BlockState getSolidSubstitution(net.minecraft.core.BlockPos ignored, Function<net.minecraft.core.BlockPos,@Nullable net.minecraft.world.level.block.state.BlockState> virtualBlocks)
      Searches a handy block to substitute a non-solid space which should be guaranteed solid.
      Parameters:
      ignored - the location the block should be at.
      virtualBlocks - blueprint blocks, fnc may return null if virtual block is not available (then use level instead for getting surrounding block states), pos argument is using world coords
      Returns:
      the Block.
    • executeSpecificCompleteActions

      protected abstract void executeSpecificCompleteActions()
      Execute specific actions on loading a structure.
    • checkIfCanceled

      protected abstract boolean checkIfCanceled()
      Check if the structure tusk has been canceled.
      Returns:
      true if reset to idle.