use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RaidManager method getRandomBuilding.
@Override
@NotNull
public BlockPos getRandomBuilding() {
buildingPosUsage++;
if (buildingPosUsage > 3 || lastBuilding == null) {
buildingPosUsage = 0;
final Collection<IBuilding> buildingList = colony.getBuildingManager().getBuildings().values();
final Object[] buildingArray = buildingList.toArray();
if (buildingArray.length != 0) {
final int rand = colony.getWorld().random.nextInt(buildingArray.length);
final IBuilding building = (IBuilding) buildingArray[rand];
lastBuilding = building.getPosition();
} else {
lastBuilding = colony.getCenter();
}
}
return lastBuilding;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RegisteredStructureManager method removeBuilding.
@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
if (buildings.containsKey(building.getID())) {
final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
for (final IBuilding tbuilding : buildings.values()) {
if (tbuilding != building) {
builder.put(tbuilding.getID(), tbuilding);
}
}
buildings = builder.build();
for (final ServerPlayerEntity player : subscribers) {
Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
}
Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
}
if (building instanceof BuildingTownHall) {
townHall = null;
} else if (building instanceof BuildingWareHouse) {
wareHouses.remove(building);
} else if (building instanceof BuildingMysticalSite) {
mysticalSites.remove(building);
}
// Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
citizen.onRemoveBuilding(building);
building.cancelAllRequestsOfCitizen(citizen);
}
colony.getRequestManager().onProviderRemovedFromColony(building);
colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
colony.getCitizenManager().calculateMaxCitizens();
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RegisteredStructureManager method getBestBuilding.
@Override
public BlockPos getBestBuilding(final BlockPos citizen, final Class<? extends IBuilding> clazz) {
double distance = Double.MAX_VALUE;
BlockPos goodCook = null;
for (final IBuilding building : buildings.values()) {
if (clazz.isInstance(building) && building.getBuildingLevel() > 0) {
final double localDistance = building.getPosition().distSqr(citizen);
if (localDistance < distance) {
distance = localDistance;
goodCook = building.getPosition();
}
}
}
return goodCook;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RegisteredStructureManager method sendFieldPackets.
/**
* Sends packages to update the fields.
*
* @param closeSubscribers the current event subscribers.
* @param newSubscribers the new event subscribers.
*/
private void sendFieldPackets(final Set<ServerPlayerEntity> closeSubscribers, final Set<ServerPlayerEntity> newSubscribers) {
if (isFieldsDirty || !newSubscribers.isEmpty()) {
final Set<ServerPlayerEntity> players = new HashSet<>();
if (isFieldsDirty) {
players.addAll(closeSubscribers);
}
players.addAll(newSubscribers);
for (final IBuilding building : buildings.values()) {
if (building instanceof BuildingFarmer) {
players.forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewBuildingViewMessage(building), player));
}
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RegisteredStructureManager method cleanUpBuildings.
@Override
public void cleanUpBuildings(@NotNull final IColony colony) {
@Nullable final List<IBuilding> removedBuildings = new ArrayList<>();
// Need this list, we may enter here while we add a building in the real world.
final List<IBuilding> tempBuildings = new ArrayList<>(buildings.values());
for (@NotNull final IBuilding building : tempBuildings) {
final BlockPos loc = building.getPosition();
if (WorldUtil.isBlockLoaded(colony.getWorld(), loc) && !building.isMatchingBlock(colony.getWorld().getBlockState(loc).getBlock())) {
// Sanity cleanup
removedBuildings.add(building);
}
}
@NotNull final ArrayList<BlockPos> tempFields = new ArrayList<>(fields);
for (@NotNull final BlockPos pos : tempFields) {
if (WorldUtil.isBlockLoaded(colony.getWorld(), pos)) {
if (!(colony.getWorld().getBlockEntity(pos) instanceof ScarecrowTileEntity)) {
removeField(pos);
}
}
}
for (@NotNull final BlockPos pos : leisureSites) {
if (WorldUtil.isBlockLoaded(colony.getWorld(), pos)) {
if (!(colony.getWorld().getBlockEntity(pos) instanceof TileEntityDecorationController)) {
removeLeisureSite(pos);
}
}
}
if (!removedBuildings.isEmpty() && removedBuildings.size() >= buildings.values().size()) {
Log.getLogger().warn("Colony:" + colony.getID() + " is removing all buildings at once. Did you just load a backup? If not there is a chance that colony data got corrupted and you want to restore a backup.");
}
removedBuildings.forEach(IBuilding::destroy);
}
Aggregations