use of com.minecolonies.coremod.colony.buildings.BuildingFarmer in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method cycle.
/**
* The main work cycle of the Famer.
* This checks each block, harvests, tills, and plants.
*/
private AIState cycle() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
return AIState.PREPARING;
}
@Nullable final Field field = buildingFarmer.getCurrentField();
if (workingOffset != null) {
final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
// Still moving to the block
if (walkToBlock(position.up())) {
return AIState.FARMER_WORK;
}
// harvest the block if able to.
if (harvestIfAble(position)) {
setDelay(getLevelDelay());
}
}
if (!handleOffsetHarvest(field)) {
resetVariables();
shouldDumpInventory = true;
field.setNeedsWork(false);
return AIState.IDLE;
}
return AIState.FARMER_WORK;
}
use of com.minecolonies.coremod.colony.buildings.BuildingFarmer in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method lookAtField.
/**
* Farmer looks at field to see if it's harvestable.
* Checks to see if there are any harvestable crops,
* if so go to FARMER_WORK, if not, set needs work to false and go to IDLE.
*/
private AIState lookAtField() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
return AIState.PREPARING;
}
@Nullable final Field field = buildingFarmer.getCurrentField();
setDelay(LOOK_WAIT);
if (handleOffsetHarvest(field)) {
return AIState.FARMER_WORK;
} else {
if (containsPlants(field)) {
field.setNeedsWork(false);
return AIState.PREPARING;
} else {
field.setInitialized(false);
return AIState.PREPARING;
}
}
}
use of com.minecolonies.coremod.colony.buildings.BuildingFarmer in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method prepareForFarming.
/**
* Prepares the farmer for farming.
* Also requests the tools and checks if the farmer has sufficient fields.
*
* @return the next AIState
*/
@NotNull
private AIState prepareForFarming() {
@Nullable final BuildingFarmer building = getOwnBuilding();
if (building == null || building.getBuildingLevel() < 1) {
return AIState.PREPARING;
}
building.syncWithColony(world);
if (building.getFarmerFields().size() < getOwnBuilding().getBuildingLevel() && !building.assignManually()) {
searchAndAddFields();
}
if (building.hasNoFields()) {
chatSpamFilter.talkWithoutSpam("entity.farmer.noFreeFields");
return AIState.PREPARING;
}
//If the farmer has no currentField and there is no field which needs work, check fields.
if (building.getCurrentField() == null && building.getFieldToWorkOn() == null) {
building.resetFields();
return AIState.IDLE;
}
@Nullable final Field currentField = building.getCurrentField();
if (currentField.needsWork()) {
if (currentField.isInitialized()) {
walkToBlock(currentField.getLocation());
return AIState.FARMER_OBSERVE;
} else if (canGoPlanting(currentField, building) && !checkForHoe()) {
return walkToBlock(currentField.getLocation()) ? AIState.PREPARING : AIState.FARMER_INITIALIZE;
} else if (containsPlants(currentField) && !walkToBuilding() && !canGoPlanting(currentField, building)) {
currentField.setInitialized(true);
currentField.setNeedsWork(false);
}
} else {
getOwnBuilding().setCurrentField(null);
}
return AIState.PREPARING;
}
use of com.minecolonies.coremod.colony.buildings.BuildingFarmer in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method initialize.
/**
* This (re)initializes a field.
* Checks the block above to see if it is a plant, if so, breaks it. Then tills.
*/
private AIState initialize() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
return AIState.PREPARING;
}
@Nullable final Field field = buildingFarmer.getCurrentField();
if (workingOffset != null) {
final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
// Still moving to the block
if (walkToBlock(position.up())) {
return AIState.FARMER_INITIALIZE;
}
// Check to see if the block is a plant, and if it is, break it.
final IBlockState blockState = world.getBlockState(position.up());
if (blockState.getBlock() instanceof IGrowable && (!(blockState.getBlock() instanceof BlockCrops) || ((BlockCrops) blockState.getBlock()).getItem(world, position.up(), blockState) != field.getSeed())) {
mineBlock(position.up());
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
// hoe the block if able to.
if (hoeIfAble(position, field)) {
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
if (shouldPlant(position, field) && !plantCrop(field.getSeed(), position)) {
resetVariables();
return AIState.PREPARING;
}
}
if (!handleOffset(field)) {
resetVariables();
shouldDumpInventory = true;
field.setInitialized(true);
field.setNeedsWork(false);
return AIState.IDLE;
}
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
Aggregations