Class AbstractEntityAIStructure<J extends AbstractJobStructure<?,J>,B extends AbstractBuildingStructureBuilder>
java.lang.Object
com.minecolonies.core.entity.ai.workers.AbstractAISkeleton<J>
com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic<J,B>
com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill<J,B>
com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract<J,B>
com.minecolonies.core.entity.ai.workers.AbstractEntityAIStructure<J,B>
- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDifferent item check result possibilities. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected net.minecraft.core.BlockPosBlock to mine.protected static final intBuilding block delayprotected net.neoforged.neoforge.common.util.TriPredicate<com.ldtteam.structurize.util.BlueprintPositionInfo, net.minecraft.core.BlockPos, com.ldtteam.structurize.placement.structure.IStructureHandler> Predicate defining things we don't want the builders to ever touch.protected net.minecraft.core.BlockPosBlock to go to when buildingprotected booleanIf the structure state is currently reached limit rather than block placement.protected booleanWe're waiting for the blueprint to finish loading.protected net.minecraft.core.BlockPosPrevious Position where the Builders constructed from.protected Tuple<com.ldtteam.structurize.placement.StructurePlacer, BuildingStructureHandler<J, B>> The current structure task to be build.protected net.minecraft.core.BlockPosPosition where the Builders constructs from.Fields inherited from class com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract
BLOCK_MINING_DELAY, RANGE_HORIZONTAL_PICKUP, RANGE_VERTICAL_PICKUP, RENDER_META_WORKING, XP_PER_BLOCKFields inherited from class com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic
building, currentWorkingLocation, needsCurrently, NO_TOOL, REQUEST_DELAY, STANDARD_DELAY, WALK_DELAY, walkTo, workPosIndexFields inherited from class com.minecolonies.core.entity.ai.workers.AbstractAISkeleton
job, worker, world -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates this ai base class and set's up important things. -
Method Summary
Modifier and TypeMethodDescriptionState to go to after dumping.What to do after picking up a request.The next state after structure loading.voidCheck for extra building options to do with each block.protected abstract booleanCheck if the structure tusk has been canceled.protected IAIStateCompletition logic.doMining()Separate step for mining.protected abstract voidExecute specific actions on loading a structure.@Nullable net.minecraft.core.BlockPosGet the current block being placed/removed.protected net.minecraft.core.BlockPosGet the current working position for the worker.abstract intGet the level that affects the place speed.protected net.minecraft.core.BlockPosGet the position the citizen needs to walk to in order to buildabstract Tuple<net.minecraft.core.BlockPos, BuildingProgressStage> Get the current structure progress,net.minecraft.world.level.block.state.BlockStategetSolidSubstitution(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.The state to transform to after picking up things.@Nullable net.minecraft.world.item.ItemStackgetTotalAmount(@Nullable net.minecraft.world.item.ItemStack stack) Check how much of a certain stuck is actually required.Get the worker of the AI.net.minecraft.core.BlockPosgetWorkingPosition(net.minecraft.core.BlockPos targetPosition) Calculates the working position.protected booleangoToNextStage(com.ldtteam.structurize.placement.StructurePhasePlacementResult result) This method is called when a stage is finished, and it is needed to go to the next stagevoidSpecific actions to handle a cancellation of a structure.static <J extends AbstractJobStructure<?,J>, B extends AbstractBuildingStructureBuilder>
AbstractEntityAIStructure.ItemCheckResulthasListOfResInInvOrRequest(@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.protected booleanLet childs overwrite this if necessary.static booleanisBlockFree(@Nullable net.minecraft.world.level.block.state.BlockState block) Defines blocks that can be built for free.protected static booleanisDecoItem(net.minecraft.world.level.block.Block block) Checks for blocks that need to be treated as decoprotected booleanCheck if there is a StructureIterator to be build.Load all requirements of the structure.voidloadStructure(@NotNull IBuilderWorkOrder workOrder, net.minecraft.core.BlockPos position, boolean removal) Loads the structure given the name, rotation and position.State to pick up material before going back to work.voidreduceNeededResources(net.minecraft.world.item.ItemStack stack) Reduces the needed resources by 1.voidregisterBlockAsNeeded(net.minecraft.world.item.ItemStack stack) Register the block as needed at the building if possible.booleanIterates through all the required resources and stores them in the building.voidSet the currentStructure to null.voidsetStructurePlacer(BuildingStructureHandler<J, B> structure) Set the structure placer.abstract booleanshallReplaceSolidSubstitutionBlock(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.protected booleanskipBuilding(com.ldtteam.structurize.util.BlueprintPositionInfo info, net.minecraft.core.BlockPos pos, com.ldtteam.structurize.placement.structure.IStructureHandler handler) Checks wich blocks are skipped on buildingprotected booleanskipClearing(com.ldtteam.structurize.util.BlueprintPositionInfo info, net.minecraft.core.BlockPos pos, com.ldtteam.structurize.placement.structure.IStructureHandler handler) Checks which blocks are skipped on clearingprotected @NotNull IAIStateStart building this StructureIterator.protected IAIStateStart working at own building.voidstoreProgressPos(net.minecraft.core.BlockPos blockPos, BuildingProgressStage stage) Store the progressPos in the building if possible for the worker.protected IAIStateThe Structure step to execute the actual placement actions etc.abstract booleanwalkToConstructionSite(net.minecraft.core.BlockPos currentBlock) Walk to the current construction site.Methods inherited from class com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract
fillItemsList, gatherItems, getBlockMiningTime, getBreakSpeedLevel, getItemsForPickUp, increaseBlockDrops, isItemWorthPickingUp, mineBlock, mineBlock, mineBlock, onBlockDropReception, resetGatheringItems, searchForItems, shouldSilkTouchBlock, triggerMinedBlockMethods inherited from class com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic
cancelAsynchRequestForArmor, canGoIdle, checkAndTransferFromHut, checkForToolOrWeapon, checkForToolOrWeapon, checkForToolOrWeaponAsync, checkIfNeedsItem, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreate, checkIfRequestForItemExistOrCreateAsync, checkIfRequestForItemExistOrCreateAsync, checkIfRequestForItemExistOrCreateAsync, checkIfRequestForItemExistOrCreateAsync, checkIfRequestForItemExistOrCreateAsync, checkIfRequestForTagExistOrCreateAsync, getActionsDoneUntilDumping, getBuildingToDump, getEffectiveSkillLevel, getExceptionTimer, getExpectedBuildingClass, getFakePlayer, getInventory, getInvertedEffectiveSkillLevel, getModuleForJob, getMostEfficientTool, getPrimarySkillLevel, getSecondarySkillLevel, getTotalRequiredAmount, getWorkingPosition, hasNotDelayed, holdEfficientTool, incrementActionsDone, incrementActionsDone, incrementActionsDoneAndDecSaturation, inventoryNeedsDump, isAfterDumpPickupAllowed, itemsNiceToHave, onException, resetActionsDone, retrieveToolInHut, retrieveToolInTileEntity, setDelay, takeItemStackFromProvider, updateRenderMetaData, waitForRequests, walkToBuilding, walkToBuilding, walkToSafePos, walkToTaggedWorkPos, walkToUnSafePos, walkToUnSafePos, walkToWorkPos, walkWithProxy, walkWithProxy, wantInventoryDumpedMethods inherited from class com.minecolonies.core.entity.ai.workers.AbstractAISkeleton
canBeInterrupted, getState, getStateAI, getTickRate, onRemoval, registerGroupTarget, registerTarget, registerTargets, resetAI, setCurrentDelay, tick
-
Field Details
-
BUILD_BLOCK_DELAY
protected static final int BUILD_BLOCK_DELAYBuilding block delay- See Also:
-
structurePlacer
protected Tuple<com.ldtteam.structurize.placement.StructurePlacer,BuildingStructureHandler<J extends AbstractJobStructure<?, structurePlacerJ>, B extends AbstractBuildingStructureBuilder>> The current structure task to be build. -
limitReached
protected boolean limitReachedIf the structure state is currently reached limit rather than block placement. -
loadingBlueprint
protected boolean loadingBlueprintWe'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, DONT_TOUCH_PREDICATEcom.ldtteam.structurize.placement.structure.IStructureHandler> Predicate defining things we don't want the builders to ever touch. -
workFrom
protected net.minecraft.core.BlockPos workFromPosition where the Builders constructs from. -
prevBlockPosition
protected net.minecraft.core.BlockPos prevBlockPositionPrevious Position where the Builders constructed from. -
blockToMine
protected net.minecraft.core.BlockPos blockToMineBlock to mine. -
gotoPos
protected net.minecraft.core.BlockPos gotoPosBlock to go to when building
-
-
Constructor Details
-
AbstractEntityAIStructure
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
Start working at own building. Override for worker specific implementations.- Returns:
- next state.
-
pickUpMaterial
State to pick up material before going back to work.- Returns:
- the next state to go to.
-
completeBuild
Completition logic.- Returns:
- the final state after completition.
-
startBuilding
Start building this StructureIterator.Will determine where to start.
- Returns:
- the new State to start in.
-
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
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
Description copied from class:AbstractEntityAIBasicThe state to transform to after picking up things.- Overrides:
getStateAfterPickUpin classAbstractEntityAIBasic<J extends AbstractJobStructure<?,J>, B extends AbstractBuildingStructureBuilder> - Returns:
- the next state to go to.
-
afterRequestPickUp
Description copied from class:AbstractEntityAIBasicWhat to do after picking up a request.- Overrides:
afterRequestPickUpin classAbstractEntityAIBasic<J extends AbstractJobStructure<?,J>, B extends AbstractBuildingStructureBuilder> - Returns:
- the next state to go to.
-
afterDump
Description copied from class:AbstractEntityAIBasicState to go to after dumping.- Overrides:
afterDumpin classAbstractEntityAIBasic<J extends AbstractJobStructure<?,J>, B extends AbstractBuildingStructureBuilder> - Returns:
- the next state.
-
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
Set the structure placer.- Parameters:
structure- the placer.
-
hasListOfResInInvOrRequest
public static <J extends AbstractJobStructure<?,J>, AbstractEntityAIStructure.ItemCheckResult hasListOfResInInvOrRequestB extends AbstractBuildingStructureBuilder> (@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
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
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:
getWorkingPositionin classAbstractEntityAIBasic<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
Get the worker of the AI.- Returns:
- the EntityCitizen object.
-
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.
-