Class AbstractEntityAIBasic<J extends AbstractJob<?,J>,B extends AbstractBuilding>
- Type Parameters:
J- The job this ai has to fulfil
- All Implemented Interfaces:
ITickingStateAI
- Direct Known Subclasses:
AbstractEntityAISkill
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal BThe building of the citizen.protected @Nullable net.minecraft.core.BlockPosThe block the ai is currently working at or wants to work.What he currently might be needing.protected static final intThe returned slot if a slot hasn't been found.protected static final intThe standard delay after each terminated action.protected static final intThe standard delay after each terminated action.protected static final intDelay for walking.protected net.minecraft.core.BlockPosThe current position the worker should walk to.intWorking pos index.Fields inherited from class com.minecolonies.core.entity.ai.workers.AbstractAISkeleton
job, worker, world -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEntityAIBasic(J job) Sets up some important skeleton stuff for every ai. -
Method Summary
Modifier and TypeMethodDescriptionState to go to after dumping.What to do after picking up a request.protected voidcancelAsynchRequestForArmor(EquipmentTypeEntry armorType) Cancel all requests for a certain armor type for a certain citizen.booleanIf the worker currently has work to do or could also just wander around.booleancheckAndTransferFromHut(@Nullable net.minecraft.world.item.ItemStack is) Check all racks in the workers hut for a required item.booleancheckForToolOrWeapon(@NotNull EquipmentTypeEntry toolType) Ensures that we have a appropriate tool available.protected booleancheckForToolOrWeapon(@NotNull EquipmentTypeEntry toolType, int minimalLevel) protected voidcheckForToolOrWeaponAsync(@NotNull EquipmentTypeEntry toolType, int minLevel, int maxLevel) Ensures that we have a appropriate tool available.protected booleanCheck ifbooleancheckIfRequestForItemExistOrCreate(@NotNull IDeliverable deliverable) Check if a request exists for a given deliverable.booleancheckIfRequestForItemExistOrCreate(@NotNull Collection<net.minecraft.world.item.ItemStack> stacks) Check if any of the stacks is in the inventory.booleancheckIfRequestForItemExistOrCreate(@NotNull net.minecraft.world.item.ItemStack stack) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForItemExistOrCreate(@NotNull net.minecraft.world.item.ItemStack... stacks) Requests a list of itemstacks.booleancheckIfRequestForItemExistOrCreate(@NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForItemExistOrCreate(@NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount, boolean matchNBT, boolean async) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForItemExistOrCreateAsync(@NotNull Collection<net.minecraft.world.item.ItemStack> stacks) Check if any of the stacks is in the inventory.booleancheckIfRequestForItemExistOrCreateAsync(@NotNull net.minecraft.world.item.ItemStack stack) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForItemExistOrCreateAsync(@NotNull net.minecraft.world.item.ItemStack... stacks) Requests a list of itemstacks.booleancheckIfRequestForItemExistOrCreateAsync(@NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForItemExistOrCreateAsync(@NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount, boolean matchNBT) Check if a stack has been requested already or is in the inventory.booleancheckIfRequestForTagExistOrCreateAsync(@NotNull net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag, int count) Check if a tag has been requested already or is in the inventory.protected intCalculates after how many actions the ai should dump it's inventory.protected IBuildingGet the building to dump the inventory into.protected static intgetEffectiveSkillLevel(int rawSkillLevel) Apply a early bonus curve to a skill level note: This adjusts the range from 0-99 to be 1-100intThe current exception timerCan be overridden in implementations to return the exact building type the worker expects.protected net.neoforged.neoforge.common.util.FakePlayerObtains a fake player class which can be used inside the AI logic to utilize in requests that require a player instance when none is available.protected @NotNull InventoryCitizenCalculate the citizens inventory.protected static intgetInvertedEffectiveSkillLevel(int rawSkillLevel) Returns the inverted skill level, to use in chance based calcsprotected WorkerBuildingModuleUtility method to get a given module for this AI.protected intgetMostEfficientTool(@NotNull net.minecraft.world.level.block.state.BlockState target, net.minecraft.core.BlockPos pos) Calculates the most efficient tool to use on that block.protected intGet the primary skill of this worker.protected intGet the secondary skill of this worker.The state to transform to after picking up things.intgetTotalRequiredAmount(net.minecraft.world.item.ItemStack deliveredItemStack) Get the total amount required for an itemStack.net.minecraft.core.BlockPosgetWorkingPosition(int distance, net.minecraft.core.BlockPos targetPos, int offset) Calculates the working position.net.minecraft.core.BlockPosgetWorkingPosition(net.minecraft.core.BlockPos targetPosition) Calculates the working position.protected final booleanhasNotDelayed(int time) Will delay one time and pass through the second time.booleanholdEfficientTool(@NotNull net.minecraft.world.level.block.state.BlockState target, net.minecraft.core.BlockPos pos) Check and ensure that we hold the most efficient tool for the job.final voidTell the ai that you have done one more action.protected final voidincrementActionsDone(int numberOfActions) Tell the ai that you have done numberOfActions more actions.final voidTell the ai that you have done one more action.protected booleanCheck if we need to dump the worker inventory.booleanChecks whether automatic pickups after dumps are allowed.protected @NotNull List<ItemStorage> Can be overridden by implementations to specify items useful for the worker.protected voidprotected final voidReset the done actions of the AI.booleanretrieveToolInHut(EquipmentTypeEntry toolType, int minimalLevel) Check all chests in the workers hut for a required tool.booleanretrieveToolInTileEntity(net.minecraft.world.level.block.entity.BlockEntity entity, EquipmentTypeEntry toolType, int minLevel, int maxLevel) Finds the first @see ItemStack the type ofis.final voidsetDelay(int timeout) Set a delay in ticks.voidtakeItemStackFromProvider(@NotNull IItemHandlerCapProvider provider, int slotIndex) Takes whatever is in that slot of the worker chest and puts it in his inventory.protected voidCan be overridden in implementations.protected @NotNull IAIStateIf the worker has open requests their results will be queried until they all are completed Also waits for DELAY_RECHECK.protected final booleanWalk the worker to it's work building.protected final booleanwalkToBuilding(IBuilding building) Walk the worker to the given building.protected final booleanwalkToSafePos(net.minecraft.core.BlockPos pos) Walk the worker to the safe positionprotected final booleanWalk the worker to a tagged workpos in building, or the building pos if non existent.protected final booleanwalkToUnSafePos(net.minecraft.core.BlockPos pos) Walk the worker to the unsafe positionprotected final booleanwalkToUnSafePos(net.minecraft.core.BlockPos pos, int distance) Walk the worker to the unsafe positionprotected final booleanwalkToWorkPos(net.minecraft.core.BlockPos pos) Walk the worker to the given building.protected final booleanwalkWithProxy(@NotNull net.minecraft.core.BlockPos stand) Sets the block the AI is currently walking to.protected final booleanwalkWithProxy(@NotNull net.minecraft.core.BlockPos stand, int range) Sets the block the AI is currently walking to.protected booleanHas to be overridden by classes to specify when to dump inventory.Methods inherited from class com.minecolonies.core.entity.ai.workers.AbstractAISkeleton
canBeInterrupted, getState, getStateAI, getTickRate, onRemoval, registerGroupTarget, registerTarget, registerTargets, resetAI, setCurrentDelay, tick
-
Field Details
-
NO_TOOL
protected static final int NO_TOOLThe returned slot if a slot hasn't been found.- See Also:
-
STANDARD_DELAY
protected static final int STANDARD_DELAYThe standard delay after each terminated action.- See Also:
-
REQUEST_DELAY
protected static final int REQUEST_DELAYThe standard delay after each terminated action.- See Also:
-
currentWorkingLocation
@Nullable protected @Nullable net.minecraft.core.BlockPos currentWorkingLocationThe block the ai is currently working at or wants to work. -
WALK_DELAY
protected static final int WALK_DELAYDelay for walking.- See Also:
-
needsCurrently
What he currently might be needing. -
walkTo
protected net.minecraft.core.BlockPos walkToThe current position the worker should walk to. -
building
The building of the citizen. -
workPosIndex
public int workPosIndexWorking pos index. Initialized with -1, not saved.
-
-
Constructor Details
-
AbstractEntityAIBasic
Sets up some important skeleton stuff for every ai.- Parameters:
job- the job class
-
-
Method Details
-
checkIfNeedsItem
protected boolean checkIfNeedsItem()Check if- Returns:
-
getStateAfterPickUp
The state to transform to after picking up things.- Returns:
- the next state to go to.
-
getExpectedBuildingClass
Can be overridden in implementations to return the exact building type the worker expects.- Returns:
- the building type associated with this AI's worker.
-
onException
- Overrides:
onExceptionin classAbstractAISkeleton<J extends AbstractJob<?,J>>
-
setDelay
public final void setDelay(int timeout) Set a delay in ticks.- Parameters:
timeout- the delay to wait after this tick.
-
inventoryNeedsDump
protected boolean inventoryNeedsDump()Check if we need to dump the worker inventory.This will also ask the implementing ai if we need to dump on custom reasons. {see wantInventoryDumped}
- Returns:
- true if we need to dump the inventory.
-
getActionsDoneUntilDumping
protected int getActionsDoneUntilDumping()Calculates after how many actions the ai should dump it's inventory.Override this to change the value.
- Returns:
- the number of actions done before item dump.
-
wantInventoryDumped
protected boolean wantInventoryDumped()Has to be overridden by classes to specify when to dump inventory. Always dump on inventory full.- Returns:
- true if inventory needs to be dumped now
-
updateRenderMetaData
protected void updateRenderMetaData()Can be overridden in implementations.Here the AI can check if the chestBelt has to be re rendered and do it.
-
waitForRequests
If the worker has open requests their results will be queried until they all are completed Also waits for DELAY_RECHECK.- Returns:
- NEEDS_ITEM
-
getPrimarySkillLevel
protected int getPrimarySkillLevel()Get the primary skill of this worker.- Returns:
- the primary skill.
-
getSecondarySkillLevel
protected int getSecondarySkillLevel()Get the secondary skill of this worker.- Returns:
- the secondary skill.
-
getModuleForJob
Utility method to get a given module for this AI.- Returns:
- the right module.
-
getEffectiveSkillLevel
protected static int getEffectiveSkillLevel(int rawSkillLevel) Apply a early bonus curve to a skill level note: This adjusts the range from 0-99 to be 1-100- Parameters:
rawSkillLevel- to apply the curve to- Returns:
- effective skill level to use in linear bonus functions
-
getInvertedEffectiveSkillLevel
protected static int getInvertedEffectiveSkillLevel(int rawSkillLevel) Returns the inverted skill level, to use in chance based calcs- Parameters:
rawSkillLevel-- Returns:
-
isAfterDumpPickupAllowed
public boolean isAfterDumpPickupAllowed()Checks whether automatic pickups after dumps are allowed. Usually we want this, but if the worker is currently crafting/building, he will handle deliveries/afterdumps in their resolvers, so we can disable automatic pickups in that time. Note that this is just a efficiency-thing. It doesn't hurt when the dman does a pickup during crafting, it's just a wasted run. Therefore, this flag is only considered for *automatic* pickups after dump. It is *ignored* for player-triggered forcePickups, and when the inventory is full.- Returns:
- true if after-dump pickups are allowed currently.
-
afterRequestPickUp
What to do after picking up a request.- Returns:
- the next state to go to.
-
getTotalRequiredAmount
public int getTotalRequiredAmount(net.minecraft.world.item.ItemStack deliveredItemStack) Get the total amount required for an itemStack. Workers have to override this if they have more information.- Parameters:
deliveredItemStack- the required stack.- Returns:
- on default the size of the stack.
-
walkToBuilding
protected final boolean walkToBuilding()Walk the worker to it's work building.- Returns:
- true on arrival
-
walkToTaggedWorkPos
protected final boolean walkToTaggedWorkPos()Walk the worker to a tagged workpos in building, or the building pos if non existent.- Returns:
- true while walking
-
walkToWorkPos
protected final boolean walkToWorkPos(net.minecraft.core.BlockPos pos) Walk the worker to the given building.- Returns:
- true while walking
-
walkToBuilding
Walk the worker to the given building.- Returns:
- true while walking
-
walkToSafePos
protected final boolean walkToSafePos(net.minecraft.core.BlockPos pos) Walk the worker to the safe position- Returns:
- false while walking
-
walkToUnSafePos
protected final boolean walkToUnSafePos(net.minecraft.core.BlockPos pos) Walk the worker to the unsafe position- Returns:
- false while walking
-
walkToUnSafePos
protected final boolean walkToUnSafePos(net.minecraft.core.BlockPos pos, int distance) Walk the worker to the unsafe position- Returns:
- false while walking
-
checkAndTransferFromHut
public boolean checkAndTransferFromHut(@Nullable @Nullable net.minecraft.world.item.ItemStack is) Check all racks in the workers hut for a required item. Transfer to worker if found.- Parameters:
is- the type of item requested (amount is ignored)- Returns:
- true if a stack of that type was found and transferred.
-
walkWithProxy
protected final boolean walkWithProxy(@NotNull @NotNull net.minecraft.core.BlockPos stand) Sets the block the AI is currently walking to.- Parameters:
stand- where to walk to- Returns:
- true while walking to the block
-
walkWithProxy
protected final boolean walkWithProxy(@NotNull @NotNull net.minecraft.core.BlockPos stand, int range) Sets the block the AI is currently walking to.- Parameters:
stand- where to walk torange- how close we need to be- Returns:
- true while walking to the block
-
retrieveToolInTileEntity
public boolean retrieveToolInTileEntity(net.minecraft.world.level.block.entity.BlockEntity entity, EquipmentTypeEntry toolType, int minLevel, int maxLevel) Finds the first @see ItemStack the type ofis. It will be taken from the chest and placed in the worker inventory. Make sure that the worker stands next the chest to not break immersion. Also make sure to have inventory space for the stack.- Parameters:
entity- the tileEntity chest or building.toolType- the type of tool.minLevel- the min tool level.maxLevel- the max tool level.- Returns:
- true if found the tool.
-
takeItemStackFromProvider
public void takeItemStackFromProvider(@NotNull @NotNull IItemHandlerCapProvider provider, int slotIndex) Takes whatever is in that slot of the worker chest and puts it in his inventory. If the inventory is full, only the fitting part will be moved. Beware this method shouldn't be private, because the generic access won't work within a lambda won't work else.- Parameters:
provider- The provider to take from.slotIndex- The slot to take.
-
checkForToolOrWeapon
Ensures that we have a appropriate tool available. Will setneedsToolaccordingly.- Parameters:
toolType- type of tool we check for.- Returns:
- false if we have the tool
-
checkForToolOrWeapon
protected boolean checkForToolOrWeapon(@NotNull @NotNull EquipmentTypeEntry toolType, int minimalLevel) -
checkForToolOrWeaponAsync
protected void checkForToolOrWeaponAsync(@NotNull @NotNull EquipmentTypeEntry toolType, int minLevel, int maxLevel) Ensures that we have a appropriate tool available. ASync call on the tool.- Parameters:
toolType- Tool type that is requestedminLevel- min. level of the toolmaxLevel- min. level of the tool
-
cancelAsynchRequestForArmor
Cancel all requests for a certain armor type for a certain citizen.- Parameters:
armorType- the armor type.
-
retrieveToolInHut
Check all chests in the workers hut for a required tool.- Parameters:
toolType- the type of tool requested (amount is ignored)minimalLevel- the minimal level the tool should have.- Returns:
- true if a stack of that type was found
-
getBuildingToDump
Get the building to dump the inventory into.- Returns:
- its own building by default.
-
afterDump
State to go to after dumping.- Returns:
- the next state.
-
itemsNiceToHave
Can be overridden by implementations to specify items useful for the worker. When the worker inventory is full, he will try to keep these items. ItemStack amounts are ignored, the first stack found will be taken.- Returns:
- a list with items nice to have for the worker
-
getInventory
Calculate the citizens inventory.- Returns:
- A InventoryCitizen matching this ai's citizen.
-
holdEfficientTool
public boolean holdEfficientTool(@NotNull @NotNull net.minecraft.world.level.block.state.BlockState target, net.minecraft.core.BlockPos pos) Check and ensure that we hold the most efficient tool for the job.If we have no tool for the job, we will request on, return immediately.
- Parameters:
target- the BlockState to minepos- the pos to mine- Returns:
- true if we have a tool for the job
-
getMostEfficientTool
protected int getMostEfficientTool(@NotNull @NotNull net.minecraft.world.level.block.state.BlockState target, net.minecraft.core.BlockPos pos) Calculates the most efficient tool to use on that block.- Parameters:
target- the BlockState to minepos- the pos it is at.- Returns:
- the slot with the best tool
-
hasNotDelayed
protected final boolean hasNotDelayed(int time) Will delay one time and pass through the second time. Use for convenience instead of SetDelay- Parameters:
time- the time to wait- Returns:
- true if you should wait
-
incrementActionsDoneAndDecSaturation
public final void incrementActionsDoneAndDecSaturation()Tell the ai that you have done one more action.if the actions exceed a certain number, the ai will dump it's inventory. this also triggers the AI to get hungry.
For example:
After x blocks, bring everything back.
-
incrementActionsDone
public final void incrementActionsDone()Tell the ai that you have done one more action.if the actions exceed a certain number, the ai will dump it's inventory.
For example:
After x blocks, bring everything back.
- See Also:
-
resetActionsDone
protected final void resetActionsDone()Reset the done actions of the AI.- See Also:
-
incrementActionsDone
protected final void incrementActionsDone(int numberOfActions) Tell the ai that you have done numberOfActions more actions.if the actions exceed a certain number, the ai will dump it's inventory.
For example:
After x blocks, bring everything back.
- Parameters:
numberOfActions- number of actions to be added at once.- See Also:
-
getWorkingPosition
public net.minecraft.core.BlockPos getWorkingPosition(net.minecraft.core.BlockPos targetPosition) Calculates the working position.Takes the position where the worker would like to work on and return the most appropriate position for it.
- Parameters:
targetPosition- the position to work at.- Returns:
- BlockPos most appropiate position to work from.
-
getWorkingPosition
public net.minecraft.core.BlockPos getWorkingPosition(int distance, net.minecraft.core.BlockPos targetPos, int offset) 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.
- Parameters:
distance- the extra distance to apply away from the building.targetPos- the target position which needs to be worked.offset- an additional offset- Returns:
- BlockPos position to work from.
-
checkIfRequestForItemExistOrCreate
public boolean checkIfRequestForItemExistOrCreate(@NotNull @NotNull net.minecraft.world.item.ItemStack... stacks) Requests a list of itemstacks.- Parameters:
stacks- the stacks.- Returns:
- true if they're in the inventory.
-
checkIfRequestForItemExistOrCreate
public boolean checkIfRequestForItemExistOrCreate(@NotNull @NotNull Collection<net.minecraft.world.item.ItemStack> stacks) Check if any of the stacks is in the inventory.- Parameters:
stacks- the list of stacks.- Returns:
- true if so.
-
checkIfRequestForItemExistOrCreate
public boolean checkIfRequestForItemExistOrCreate(@NotNull @NotNull net.minecraft.world.item.ItemStack stack) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreate
public boolean checkIfRequestForItemExistOrCreate(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.count- count to request.minCount- the min count to fulfill.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreateAsync
public boolean checkIfRequestForItemExistOrCreateAsync(@NotNull @NotNull net.minecraft.world.item.ItemStack... stacks) Requests a list of itemstacks.- Parameters:
stacks- the stacks.- Returns:
- true if they're in the inventory.
-
checkIfRequestForItemExistOrCreateAsync
public boolean checkIfRequestForItemExistOrCreateAsync(@NotNull @NotNull Collection<net.minecraft.world.item.ItemStack> stacks) Check if any of the stacks is in the inventory.- Parameters:
stacks- the list of stacks.- Returns:
- true if so.
-
checkIfRequestForItemExistOrCreateAsync
public boolean checkIfRequestForItemExistOrCreateAsync(@NotNull @NotNull net.minecraft.world.item.ItemStack stack) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreateAsync
public boolean checkIfRequestForItemExistOrCreateAsync(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.count- the count.minCount- the min count.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreateAsync
public boolean checkIfRequestForItemExistOrCreateAsync(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount, boolean matchNBT) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.count- the total count.minCount- the minimum count.matchNBT- if nbt has to be matched.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreate
public boolean checkIfRequestForItemExistOrCreate(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, int count, int minCount, boolean matchNBT, boolean async) Check if a stack has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
stack- the requested stack.count- the total count.minCount- the minimum count.matchNBT- if nbt has to be matched.async- if should be an async request.- Returns:
- true if in the inventory, else false.
-
checkIfRequestForItemExistOrCreate
Check if a request exists for a given deliverable.- Parameters:
deliverable- the deliverable to check of request.- Returns:
- true if available or transfered.
-
checkIfRequestForTagExistOrCreateAsync
public boolean checkIfRequestForTagExistOrCreateAsync(@NotNull @NotNull net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag, int count) Check if a tag has been requested already or is in the inventory. If not in the inventory and not requested already, create request- Parameters:
tag- the requested tag.- Returns:
- true if in the inventory, else false.
-
getExceptionTimer
public int getExceptionTimer()The current exception timer- Returns:
- the timer.
-
getFakePlayer
protected net.neoforged.neoforge.common.util.FakePlayer getFakePlayer()Obtains a fake player class which can be used inside the AI logic to utilize in requests that require a player instance when none is available.- Returns:
- a fake player.
-
canGoIdle
public boolean canGoIdle()If the worker currently has work to do or could also just wander around.- Returns:
- true if can go idle.
-