Search in sources :

Example 6 with ScarecrowTileEntity

use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.

the class BuildingFarmer method freeField.

/**
     * Method called to free a field.
     *
     * @param position id of the field.
     */
public void freeField(final BlockPos position) {
    //Get the field with matching id, if none found return null.
    final Field tempField = farmerFields.stream().filter(field -> field.getID().equals(position)).findFirst().orElse(null);
    if (tempField != null) {
        farmerFields.remove(tempField);
        final Field field = getColony().getField(position);
        field.setTaken(false);
        field.setOwner("");
        final ScarecrowTileEntity scarecrowTileEntity = (ScarecrowTileEntity) getColony().getWorld().getTileEntity(field.getID());
        getColony().getWorld().notifyBlockUpdate(scarecrowTileEntity.getPos(), getColony().getWorld().getBlockState(scarecrowTileEntity.getPos()), getColony().getWorld().getBlockState(scarecrowTileEntity.getPos()), BLOCK_UPDATE_FLAG);
        scarecrowTileEntity.setName(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER, LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER_NOONE)));
    }
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity)

Example 7 with ScarecrowTileEntity

use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity in project minecolonies by Minecolonies.

the class BuildingFarmer method onDestroyed.

@Override
public void onDestroyed() {
    super.onDestroyed();
    for (@NotNull final Field field : farmerFields) {
        final Field tempField = getColony().getField(field.getID());
        if (tempField != null) {
            tempField.setTaken(false);
            tempField.setOwner("");
            if (getColony().getWorld() != null) {
                final ScarecrowTileEntity scarecrowTileEntity = (ScarecrowTileEntity) getColony().getWorld().getTileEntity(field.getID());
                getColony().getWorld().notifyBlockUpdate(scarecrowTileEntity.getPos(), getColony().getWorld().getBlockState(scarecrowTileEntity.getPos()), getColony().getWorld().getBlockState(scarecrowTileEntity.getPos()), BLOCK_UPDATE_FLAG);
                scarecrowTileEntity.setName(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER, LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER_NOONE)));
            }
        }
    }
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)7 Field (com.minecolonies.coremod.entity.ai.citizen.farmer.Field)5 NotNull (org.jetbrains.annotations.NotNull)4 BlockPos (net.minecraft.util.math.BlockPos)3 Nullable (org.jetbrains.annotations.Nullable)2 Colony (com.minecolonies.coremod.colony.Colony)1 InventoryField (com.minecolonies.coremod.inventory.InventoryField)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1