Search in sources :

Example 1 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class CitizenData method generateName.

/**
 * Generates a random name considering both parent names.
 *
 * @param rand Random object.
 */
public void generateName(@NotNull final Random rand, final String firstParentName, final String secondParentName) {
    String nameA = firstParentName;
    String nameB = secondParentName;
    String citizenName;
    final String firstName;
    final String middleInitial;
    final String lastName;
    if (firstParentName == null || firstParentName.isEmpty()) {
        nameA = generateName(rand, rand.nextBoolean(), colony);
    }
    if (secondParentName == null || secondParentName.isEmpty()) {
        nameB = generateName(rand, rand.nextBoolean(), colony);
    }
    final String[] firstParentNameSplit = nameA.split(" ");
    final String[] secondParentNameSplit = nameB.split(" ");
    int lastNameIndex = 1;
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        lastNameIndex = 0;
    } else if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
        lastNameIndex = 2;
    }
    if (random.nextBoolean()) {
        middleInitial = firstParentNameSplit[lastNameIndex].substring(0, 1);
        lastName = secondParentNameSplit[lastNameIndex];
    } else {
        middleInitial = secondParentNameSplit[lastNameIndex].substring(0, 1);
        lastName = firstParentNameSplit[lastNameIndex];
    }
    if (female) {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
    } else {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
    }
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        // For now, don't include middle names, as their rules (and presence) vary heavily by region.
        citizenName = String.format("%s %s", lastName, firstName);
    } else {
        if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
            citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
        } else {
            citizenName = String.format("%s %s", firstName, lastName);
        }
    }
    // Check whether there's already a citizen with this name
    for (final ICitizenData citizen : this.getColony().getCitizenManager().getCitizens()) {
        if (citizen != null && citizen.getName().equals(citizenName)) {
            // Oops - recurse this function and try again
            generateName(rand, firstParentName, secondParentName);
            return;
        }
    }
    this.name = citizenName;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 2 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class CitizenData method generateName.

/**
 * Generates a random name from a set of names.
 *
 * @param rand Random object.
 * @param female the gender
 * @param colony the colony.
 * @return Name of the citizen.
 */
public static String generateName(@NotNull final Random rand, final boolean female, final IColony colony) {
    String citizenName;
    final String firstName;
    final String middleInitial;
    final String lastName;
    if (female) {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
    } else {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
    }
    middleInitial = String.valueOf(getRandomLetter(rand));
    lastName = getRandomElement(rand, MineColonies.getConfig().getServer().lastNames.get().toArray(new String[0]));
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        // For now, don't include middle names, as their rules (and presence) vary heavily by region.
        citizenName = String.format("%s %s", lastName, firstName);
    } else {
        if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
            citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
        } else {
            citizenName = String.format("%s %s", firstName, lastName);
        }
    }
    // Check whether there's already a citizen with this name
    for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        if (citizen != null && citizen.getName().equals(citizenName)) {
            // Oops - recurse this function and try again
            citizenName = generateName(rand, female, colony);
            break;
        }
    }
    return citizenName;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 3 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuilding method getRequesterDisplayName.

@NotNull
@Override
public IFormattableTextComponent getRequesterDisplayName(@NotNull final IRequestManager manager, @NotNull final IRequest<?> request) {
    final int citizenId = getCitizensByRequest().get(request.getId());
    if (!getCitizensByRequest().containsKey(citizenId)) {
        return new StringTextComponent("<UNKNOWN>");
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
    if (citizenData.getJob() == null) {
        return new StringTextComponent(citizenData.getName());
    }
    final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
    return jobName.append(new StringTextComponent(" " + citizenData.getName()));
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuilding method overruleNextOpenRequestWithStack.

/**
 * Overrule the next open request with a give stack.
 * <p>
 * We squid:s135 which takes care that there are not too many continue statements in a loop since it makes sense here out of performance reasons.
 *
 * @param stack the stack.
 */
@Override
@SuppressWarnings("squid:S135")
public void overruleNextOpenRequestWithStack(@NotNull final ItemStack stack) {
    if (ItemStackUtils.isEmpty(stack)) {
        return;
    }
    final Collection<IRequestResolver<?>> resolvers = getResolvers();
    final List<IToken<?>> playerRequests = colony.getRequestManager().getPlayerResolver().getAllAssignedRequests();
    final List<IToken<?>> retryingRequests = colony.getRequestManager().getRetryingRequestResolver().getAllAssignedRequests();
    for (final IRequestResolver<?> resolver : resolvers) {
        final IStandardRequestManager requestManager = (IStandardRequestManager) colony.getRequestManager();
        final List<IRequest<? extends IDeliverable>> deliverableRequests = requestManager.getRequestHandler().getRequestsMadeByRequester(resolver).stream().filter(iRequest -> iRequest.getRequest() instanceof IDeliverable).map(iRequest -> (IRequest<? extends IDeliverable>) iRequest).collect(Collectors.toList());
        final IRequest<? extends IDeliverable> target = getFirstOverullingRequestFromInputList(deliverableRequests, stack);
        if (target == null || !isRequestStuck(target, playerRequests, retryingRequests)) {
            continue;
        }
        colony.getRequestManager().overruleRequest(target.getId(), stack.copy());
        return;
    }
    final Set<Integer> citizenIdsWithRequests = getOpenRequestsByCitizen().keySet();
    for (final int citizenId : citizenIdsWithRequests) {
        final ICitizenData data = colony.getCitizenManager().getCivilian(citizenId);
        if (data == null) {
            continue;
        }
        final IRequest<? extends IDeliverable> target = getFirstOverullingRequestFromInputList(getOpenRequestsOfType(data.getId(), TypeConstants.DELIVERABLE), stack);
        if (target == null || !isRequestStuck(target, playerRequests, retryingRequests)) {
            continue;
        }
        colony.getRequestManager().overruleRequest(target.getId(), stack.copy());
        return;
    }
}
Also used : ChunkDataHelper(com.minecolonies.coremod.util.ChunkDataHelper) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuildingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.BuildingRequestResolver) ISchematicProvider(com.minecolonies.api.colony.buildings.ISchematicProvider) UNCHECKED(com.minecolonies.api.util.constant.Suppression.UNCHECKED) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AirBlock(net.minecraft.block.AirBlock) ImmutableCollection(com.google.common.collect.ImmutableCollection) CompoundNBT(net.minecraft.nbt.CompoundNBT) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) Block(net.minecraft.block.Block) StringTextComponent(net.minecraft.util.text.StringTextComponent) NORMAL_REQUEST(com.minecolonies.api.util.constant.TranslationConstants.NORMAL_REQUEST) BlockState(net.minecraft.block.BlockState) ASYNC_REQUEST(com.minecolonies.api.util.constant.TranslationConstants.ASYNC_REQUEST) ListNBT(net.minecraft.nbt.ListNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) BoolSetting(com.minecolonies.coremod.colony.buildings.modules.settings.BoolSetting) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) NO_WORK_ORDER(com.minecolonies.api.util.constant.BuildingConstants.NO_WORK_ORDER) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) GENERIC_WILDCARD(com.minecolonies.api.util.constant.Suppression.GENERIC_WILDCARD) com.minecolonies.api.colony.buildings.modules(com.minecolonies.api.colony.buildings.modules) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) Pickup(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Pickup) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) AbstractDeliverymanRequestable.getPlayerActionPriority(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getPlayerActionPriority) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) EntityAIWorkDeliveryman(com.minecolonies.coremod.entity.ai.citizen.deliveryman.EntityAIWorkDeliveryman) TypeToken(com.google.common.reflect.TypeToken) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) MOD_ID(com.minecolonies.api.util.constant.Constants.MOD_ID) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) com.minecolonies.api.util(com.minecolonies.api.util) IRetryingRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.retrying.IRetryingRequestResolver) MinecoloniesTileEntities(com.minecolonies.api.tileentities.MinecoloniesTileEntities) IStandardRequestManager(com.minecolonies.coremod.colony.requestsystem.management.IStandardRequestManager) WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) CONST_DEFAULT_MAX_BUILDING_LEVEL(com.minecolonies.api.util.constant.BuildingConstants.CONST_DEFAULT_MAX_BUILDING_LEVEL) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) RequestBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.RequestBasedInteraction) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) IPlayerRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.player.IPlayerRequestResolver) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) TileEntity(net.minecraft.tileentity.TileEntity) IRequestSystemBuildingDataStore(com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore) PacketBuffer(net.minecraft.network.PacketBuffer) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) ICitizenData(com.minecolonies.api.colony.ICitizenData) IStandardRequestManager(com.minecolonies.coremod.colony.requestsystem.management.IStandardRequestManager) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 5 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuilding method getHandlers.

@Override
public List<IItemHandler> getHandlers() {
    if (this.getAllAssignedCitizen().isEmpty() || colony == null || colony.getWorld() == null) {
        return Collections.emptyList();
    }
    final Set<IItemHandler> handlers = new HashSet<>();
    for (final ICitizenData workerEntity : this.getAllAssignedCitizen()) {
        handlers.add(workerEntity.getInventory());
    }
    final TileEntity entity = colony.getWorld().getBlockEntity(getID());
    if (entity != null) {
        final LazyOptional<IItemHandler> handler = entity.getCapability(ITEM_HANDLER_CAPABILITY, null);
        handler.ifPresent(handlers::add);
    }
    return ImmutableList.copyOf(handlers);
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)175 NotNull (org.jetbrains.annotations.NotNull)47 IColony (com.minecolonies.api.colony.IColony)45 BlockPos (net.minecraft.util.math.BlockPos)45 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)30 ItemStack (net.minecraft.item.ItemStack)28 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)27 PlayerEntity (net.minecraft.entity.player.PlayerEntity)26 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)17 ArrayList (java.util.ArrayList)16 Colony (com.minecolonies.coremod.colony.Colony)15 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12