use of com.minecolonies.coremod.entity.ai.citizen.farmer.Field in project minecolonies by Minecolonies.
the class Colony method addNewField.
/**
* Creates a field from a tile entity and adds it to the colony.
*
* @param tileEntity the scarecrow which contains the inventory.
* @param inventoryPlayer the inventory of the player.
* @param pos Position where the field has been placed.
* @param world the world of the field.
*/
public void addNewField(final ScarecrowTileEntity tileEntity, final InventoryPlayer inventoryPlayer, final BlockPos pos, final World world) {
@NotNull final Field field = new Field(tileEntity, inventoryPlayer, world, pos);
//field.setCustomName(LanguageHandler.format("com.minecolonies.coremod.gui.scarecrow.user", LanguageHandler.format("com.minecolonies.coremod.gui.scarecrow.user.noone")));
addField(field);
field.calculateSize(world, pos);
markFieldsDirty();
}
use of com.minecolonies.coremod.entity.ai.citizen.farmer.Field in project minecolonies by Minecolonies.
the class Colony method cleanUpBuildings.
private void cleanUpBuildings(@NotNull final TickEvent.WorldTickEvent event) {
@Nullable final List<AbstractBuilding> removedBuildings = new ArrayList<>();
//Need this list, we may enter he while we add a building in the real world.
final List<AbstractBuilding> tempBuildings = new ArrayList<>(buildings.values());
for (@NotNull final AbstractBuilding building : tempBuildings) {
final BlockPos loc = building.getLocation();
if (event.world.isBlockLoaded(loc) && !building.isMatchingBlock(event.world.getBlockState(loc).getBlock())) {
// Sanity cleanup
removedBuildings.add(building);
}
}
@NotNull final ArrayList<Field> tempFields = new ArrayList<>(fields.values());
for (@NotNull final Field field : tempFields) {
if (event.world.isBlockLoaded(field.getLocation())) {
final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) event.world.getTileEntity(field.getID());
if (scarecrow == null) {
fields.remove(field.getID());
} else {
field.setInventoryField(scarecrow.getInventoryField());
}
}
}
removedBuildings.forEach(AbstractBuilding::destroy);
}
use of com.minecolonies.coremod.entity.ai.citizen.farmer.Field in project minecolonies by Minecolonies.
the class Colony method getFreeField.
/**
* Returns a field which has not been taken yet.
*
* @param owner name of the owner of the field.
* @return a field if there is one available, else null.
*/
@Nullable
public Field getFreeField(final String owner) {
for (@NotNull final Field field : fields.values()) {
if (!field.isTaken()) {
field.setTaken(true);
field.setOwner(owner);
markFieldsDirty();
return field;
}
}
return null;
}
use of com.minecolonies.coremod.entity.ai.citizen.farmer.Field in project minecolonies by Minecolonies.
the class BuildingFarmer method createJob.
@NotNull
@Override
public AbstractJob createJob(@NotNull final CitizenData citizen) {
if (!farmerFields.isEmpty()) {
for (@NotNull final Field field : farmerFields) {
final Field colonyField = getColony().getField(field.getID());
if (colonyField != null) {
colonyField.setOwner(citizen.getName());
}
field.setOwner(citizen.getName());
}
}
return new JobFarmer(citizen);
}
Aggregations