Search in sources :

Example 1 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class ColonyManager method deleteColony.

/**
     * Delete a colony and kill all citizens/purge all buildings.
     *
     * @param id the colonies id.
     */
public static void deleteColony(final int id) {
    try {
        final Colony colony = getColony(id);
        Log.getLogger().info("Deleting colony " + id);
        colonies.remove(id);
        coloniesByWorld.get(colony.getDimension()).remove(colony);
        final Set<World> colonyWorlds = new HashSet<>();
        Log.getLogger().info("Removing citizens for " + id);
        for (final CitizenData citizenData : new ArrayList<>(colony.getCitizens().values())) {
            Log.getLogger().info("Kill Citizen " + citizenData.getName());
            final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
            if (entityCitizen != null) {
                final World world = entityCitizen.getEntityWorld();
                citizenData.getCitizenEntity().onDeath(CONSOLE_DAMAGE_SOURCE);
                colonyWorlds.add(world);
            }
        }
        Log.getLogger().info("Removing buildings for " + id);
        for (final AbstractBuilding building : new ArrayList<>(colony.getBuildings().values())) {
            final BlockPos location = building.getLocation();
            Log.getLogger().info("Delete Building at " + location);
            building.destroy();
            for (final World world : colonyWorlds) {
                if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
                    Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
                    world.setBlockToAir(location);
                }
            }
        }
        Log.getLogger().info("Done with " + id);
    } catch (final RuntimeException e) {
        Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 2 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method getRandomBuilding.

/**
     * Gets a random building from his colony.
     *
     * @return a random blockPos.
     */
private BlockPos getRandomBuilding() {
    if (worker.getColony() == null || getOwnBuilding() == null) {
        return worker.getPosition();
    }
    final Collection<AbstractBuilding> buildingList = worker.getColony().getBuildings().values();
    final Object[] buildingArray = buildingList.toArray();
    final int random = worker.getRandom().nextInt(buildingArray.length);
    final AbstractBuilding building = (AbstractBuilding) buildingArray[random];
    if (building instanceof BuildingGuardTower || BlockPosUtil.getDistance2D(building.getLocation(), this.getOwnBuilding().getLocation()) > ((BuildingGuardTower) getOwnBuilding()).getPatrolDistance()) {
        return this.getOwnBuilding().getLocation();
    }
    return building.getLocation();
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 3 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class WorkOrderBuild method onCompleted.

@Override
public void onCompleted(final Colony colony) {
    final BlockPos buildingLocation = getBuildingLocation();
    final AbstractBuilding building = colony.getBuilding(buildingLocation);
    colony.onBuildingUpgradeComplete(building, getUpgradeLevel());
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class WorkOrderBuild method onRemoved.

@Override
public void onRemoved(final Colony colony) {
    super.onRemoved(colony);
    final AbstractBuilding building = colony.getBuilding(getBuildingLocation());
    if (building != null) {
        building.markDirty();
    }
}
Also used : AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 5 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class TileEntityWareHouse method getTask.

/**
     * Get the first task in the taskQueue, or null if its empty.
     * @return the building which needs a delivery.
     */
@Nullable
public AbstractBuilding getTask() {
    final AbstractBuilding task = taskQueue.poll();
    if (task == null) {
        return null;
    }
    taskSet.remove(task);
    return task;
}
Also used : AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)19 BlockPos (net.minecraft.util.math.BlockPos)7 Colony (com.minecolonies.coremod.colony.Colony)5 BuildingGuardTower (com.minecolonies.coremod.colony.buildings.BuildingGuardTower)4 Nullable (org.jetbrains.annotations.Nullable)4 World (net.minecraft.world.World)3 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)2 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 NotNull (org.jetbrains.annotations.NotNull)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingHome (com.minecolonies.coremod.colony.buildings.BuildingHome)1 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.BuildingWareHouse)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1