use of com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState in project minecolonies by ldtteam.
the class EntityAIWorkFarmer method workAtField.
/**
* This (re)initializes a field. Checks the block above to see if it is a plant, if so, breaks it. Then tills.
*
* @return the next state to go into.
*/
private IAIState workAtField() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
final FarmerFieldModule module = buildingFarmer.getFirstModuleOccurance(FarmerFieldModule.class);
if (checkForToolOrWeapon(ToolType.HOE) || module.getCurrentField() == null) {
return PREPARING;
}
worker.getCitizenData().setVisibleStatus(FARMING_ICON);
@Nullable final BlockPos field = module.getCurrentField();
final TileEntity entity = world.getBlockEntity(field);
if (entity instanceof ScarecrowTileEntity) {
final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) entity;
if (workingOffset != null) {
if (scarecrow.getOwnerId() != worker.getCivilianID()) {
module.freeField(module.getCurrentField());
module.setCurrentField(null);
return getState();
}
final BlockPos position = field.below().south(workingOffset.getZ()).east(workingOffset.getX());
// Still moving to the block
if (walkToBlock(position.above())) {
return getState();
}
switch((AIWorkerState) getState()) {
case FARMER_HOE:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.hoeing"));
if (!hoeIfAble(position, scarecrow)) {
return getState();
}
break;
case FARMER_PLANT:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.planting"));
if (!tryToPlant(scarecrow, position)) {
return PREPARING;
}
break;
case FARMER_HARVEST:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.harvesting"));
if (!harvestIfAble(position)) {
return getState();
}
break;
default:
return PREPARING;
}
prevPos = position;
setDelay(getLevelDelay());
}
workingOffset = nextValidCell(scarecrow);
if (workingOffset == null) {
shouldDumpInventory = true;
scarecrow.nextState();
prevPos = null;
return IDLE;
}
} else {
return IDLE;
}
return getState();
}
use of com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method workAtField.
/**
* This (re)initializes a field. Checks the block above to see if it is a plant, if so, breaks it. Then tills.
*
* @return the next state to go into.
*/
private IAIState workAtField() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
final FarmerFieldModule module = buildingFarmer.getFirstModuleOccurance(FarmerFieldModule.class);
if (checkForToolOrWeapon(ToolType.HOE) || module.getCurrentField() == null) {
return PREPARING;
}
worker.getCitizenData().setVisibleStatus(FARMING_ICON);
@Nullable final BlockPos field = module.getCurrentField();
final TileEntity entity = world.getBlockEntity(field);
if (entity instanceof ScarecrowTileEntity) {
final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) entity;
if (workingOffset != null) {
if (scarecrow.getOwnerId() != worker.getCivilianID()) {
module.freeField(module.getCurrentField());
module.setCurrentField(null);
return getState();
}
final BlockPos position = field.below().south(workingOffset.getZ()).east(workingOffset.getX());
// Still moving to the block
if (walkToBlock(position.above())) {
return getState();
}
switch((AIWorkerState) getState()) {
case FARMER_HOE:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.hoeing"));
if (!hoeIfAble(position, scarecrow)) {
return getState();
}
break;
case FARMER_PLANT:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.planting"));
if (!tryToPlant(scarecrow, position)) {
return PREPARING;
}
break;
case FARMER_HARVEST:
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.harvesting"));
if (!harvestIfAble(position)) {
return getState();
}
break;
default:
return PREPARING;
}
prevPos = position;
setDelay(getLevelDelay());
}
workingOffset = nextValidCell(scarecrow);
if (workingOffset == null) {
shouldDumpInventory = true;
scarecrow.nextState();
prevPos = null;
return IDLE;
}
} else {
return IDLE;
}
return getState();
}
Aggregations