Search in sources :

Example 1 with ScarecrowTileEntity

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

the class GuiHandler method getServerGuiElement.

@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    final BlockPos pos = new BlockPos(x, y, z);
    final ScarecrowTileEntity tileEntity = (ScarecrowTileEntity) world.getTileEntity(pos);
    return new Field(tileEntity, player.inventory, world, pos);
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) BlockPos(net.minecraft.util.math.BlockPos) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity)

Example 2 with ScarecrowTileEntity

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

the class GuiHandler method getClientGuiElement.

@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    final BlockPos pos = new BlockPos(x, y, z);
    final ScarecrowTileEntity tileEntity = (ScarecrowTileEntity) world.getTileEntity(pos);
    return new GuiField(player.inventory, tileEntity, world, pos);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity)

Example 3 with ScarecrowTileEntity

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

the class BuildingFarmer method syncWithColony.

/**
     * Synchronize field list with colony.
     *
     * @param world the world the building is in.
     */
public void syncWithColony(@NotNull final World world) {
    if (!farmerFields.isEmpty()) {
        @NotNull final ArrayList<Field> tempFields = new ArrayList<>(farmerFields);
        for (@NotNull final Field field : tempFields) {
            final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) world.getTileEntity(field.getID());
            if (scarecrow == null) {
                farmerFields.remove(field);
                if (currentField != null && currentField.getID() == field.getID()) {
                    currentField = null;
                }
            } else {
                scarecrow.setName(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_SCARECROW_USER, getWorker().getName()));
                getColony().getWorld().notifyBlockUpdate(scarecrow.getPos(), getColony().getWorld().getBlockState(scarecrow.getPos()), getColony().getWorld().getBlockState(scarecrow.getPos()), BLOCK_UPDATE_FLAG);
                field.setInventoryField(scarecrow.getInventoryField());
                if (currentField != null && currentField.getID() == field.getID()) {
                    currentField.setInventoryField(scarecrow.getInventoryField());
                }
            }
        }
    }
}
Also used : Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ScarecrowTileEntity

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

the class BlockHutField method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
    //Only work on server side.
    if (worldIn.isRemote) {
        return;
    }
    if (placer instanceof EntityPlayer) {
        @Nullable final Colony colony = ColonyManager.getColony(worldIn, pos);
        if (colony != null) {
            @NotNull final InventoryField inventoryField = new InventoryField();
            final ScarecrowTileEntity scareCrow = (ScarecrowTileEntity) worldIn.getTileEntity(pos);
            final EntityPlayer player = (EntityPlayer) placer;
            if (scareCrow != null) {
                scareCrow.setInventoryField(inventoryField);
                colony.addNewField(scareCrow, player.inventory, pos, worldIn);
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) InventoryField(com.minecolonies.coremod.inventory.InventoryField) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ScarecrowTileEntity

use of com.minecolonies.coremod.tileentities.ScarecrowTileEntity 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)

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