Search in sources :

Example 1 with Field

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();
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Field

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);
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) BlockPos(net.minecraft.util.math.BlockPos) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Field

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;
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Field

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);
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) JobFarmer(com.minecolonies.coremod.colony.jobs.JobFarmer) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Field (com.minecolonies.coremod.entity.ai.citizen.farmer.Field)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)2 JobFarmer (com.minecolonies.coremod.colony.jobs.JobFarmer)1 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1