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);
}
}
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();
}
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());
}
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();
}
}
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;
}
Aggregations