Search in sources :

Example 1 with BuildingWareHouse

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

the class AbstractWarehouseRequestResolver method canResolveRequest.

@Override
public boolean canResolveRequest(@NotNull final IRequestManager manager, final IRequest<? extends IDeliverable> requestToCheck) {
    if (requestToCheck.getRequester() instanceof BuildingBasedRequester) {
        final BuildingBasedRequester requester = ((BuildingBasedRequester) requestToCheck.getRequester());
        final Optional<IRequester> building = requester.getBuilding(manager, requestToCheck.getRequester().getId());
        if (building.isPresent() && building.get() instanceof BuildingWareHouse) {
            return false;
        }
    }
    if (!manager.getColony().getWorld().isClientSide) {
        if (!isRequestChainValid(manager, requestToCheck)) {
            return false;
        }
        final Colony colony = (Colony) manager.getColony();
        try {
            return internalCanResolve(getWareHousesInColony(colony, requestToCheck.getRequester().getLocation().getInDimensionLocation()), requestToCheck);
        } catch (Exception e) {
            Log.getLogger().error(e);
        }
    }
    return false;
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) Colony(com.minecolonies.coremod.colony.Colony) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 2 with BuildingWareHouse

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

the class BuildingManager 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();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 3 with BuildingWareHouse

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse in project minecolonies by ldtteam.

the class BuildingManager 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();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 4 with BuildingWareHouse

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse in project minecolonies by ldtteam.

the class AbstractWarehouseRequestResolver method getWareHousesInColony.

/**
 * Use to get the ordered list of all warehouses.
 * @param colony the colony in question.
 * @return the ordered list.
 */
protected static List<TileEntityWareHouse> getWareHousesInColony(final Colony colony, final BlockPos requesterPosition) {
    final List<TileEntityWareHouse> wareHouses = new ArrayList<>();
    for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
        if (building instanceof BuildingWareHouse && building.getTileEntity() != null) {
            wareHouses.add((TileEntityWareHouse) building.getTileEntity());
        }
    }
    wareHouses.sort((w1, w2) -> {
        final double dist1 = w1.getPosition().distSqr(requesterPosition);
        final double dist2 = w2.getPosition().distSqr(requesterPosition);
        return Double.compare(dist1, dist2);
    });
    return wareHouses;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) TileEntityWareHouse(com.minecolonies.coremod.tileentities.TileEntityWareHouse) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 5 with BuildingWareHouse

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

the class StationRequestResolver method canResolveForBuilding.

@Override
public boolean canResolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IDeliverable> request, @NotNull final AbstractBuilding building) {
    if (building instanceof BuildingWareHouse || building.getCitizenForRequest(request.getId()).isPresent() || building.hasModule(WorkerBuildingModule.class) || !building.hasModule(AbstractAssignedCitizenModule.class)) {
        return false;
    }
    boolean foundMatch = false;
    for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
        for (final ICitizenData citizen : module.getAssignedCitizen()) {
            if (citizen.getWorkBuilding() != null && citizen.getWorkBuilding().getCitizenForRequest(request.getId()).isPresent()) {
                foundMatch = true;
                break;
            }
        }
    }
    if (!foundMatch) {
        return false;
    }
    final Predicate<ItemStack> pred = itemStack -> {
        if (ItemStackUtils.isEmpty(itemStack) || !request.getRequest().matches(itemStack)) {
            return false;
        }
        if (!request.hasParent()) {
            return true;
        }
        final IRequest<?> requestParent = manager.getRequestForToken(request.getParent());
        return !requestParent.getRequestOfType(IDeliverable.class).map(d -> d.matches(itemStack)).orElse(false);
    };
    return InventoryUtils.getCountFromBuilding(building, pred) > 0;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) java.util(java.util) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) Predicate(java.util.function.Predicate) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) ItemStack(net.minecraft.item.ItemStack) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Aggregations

BuildingWareHouse (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)8 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 NotNull (org.jetbrains.annotations.NotNull)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)2 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 Colony (com.minecolonies.coremod.colony.Colony)2 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 BuildingMysticalSite (com.minecolonies.coremod.colony.buildings.BuildingMysticalSite)2 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)2 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)2 BuildingTownHall (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall)2 BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)2