Search in sources :

Example 1 with StudyItem

use of com.minecolonies.api.entity.ai.util.StudyItem in project minecolonies by ldtteam.

the class BuildingLibrary method parseFromConfig.

/**
 * Parses Study Items from the Config and adds them on the keepX list
 *
 * @return the list of study items
 */
private List<StudyItem> parseFromConfig() {
    final List<StudyItem> studyItemList = new ArrayList<>();
    for (final String entry : MineColonies.getConfig().getServer().configListStudyItems.get()) {
        try {
            final String[] entries = entry.split(";");
            if (entries.length < 3) {
                Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
                continue;
            }
            final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(entries[0]));
            final int skillChance = Integer.parseInt(entries[1]);
            final int breakChance = Integer.parseInt(entries[2]);
            if (item == null || skillChance < 100 || skillChance > 1000 || breakChance > 100 || breakChance < 0) {
                Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
                continue;
            }
            studyItemList.add(new StudyItem(item, skillChance, breakChance));
            // Keep a certain part of the items in the Chest
            keepX.put(itemStack -> itemStack.getItem() == item, new Tuple<>(breakChance < 5 ? 5 : breakChance, true));
        } catch (NumberFormatException | ClassCastException e) {
            Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry + " Exception:" + e.getMessage());
        }
    }
    return studyItemList;
}
Also used : Item(net.minecraft.item.Item) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem)

Example 2 with StudyItem

use of com.minecolonies.api.entity.ai.util.StudyItem in project minecolonies by Minecolonies.

the class EntityAIStudy method study.

/**
 * The AI task for the student to study. For this he should walk between the different bookcase hit them once and then stand around for a while.
 *
 * @return the next IAIState.
 */
private IAIState study() {
    final ICitizenData data = worker.getCitizenData();
    if (studyPos == null) {
        studyPos = building.getRandomBookShelf();
    }
    if (walkToBlock(studyPos)) {
        setDelay(WALK_DELAY);
        return getState();
    }
    // Search for Items to use to study
    final List<StudyItem> currentItems = new ArrayList<>();
    for (final StudyItem curItem : building.getStudyItems()) {
        final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, itemStack -> !ItemStackUtils.isEmpty(itemStack) && itemStack.getItem() == curItem.getItem());
        if (slot != -1) {
            curItem.setSlot(slot);
            currentItems.add(curItem);
        }
    }
    // Create a new Request for items
    if (currentItems.isEmpty()) {
        // Default levelup
        data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE, data);
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        for (final StudyItem studyItem : building.getStudyItems()) {
            final int bSlot = InventoryUtils.findFirstSlotInProviderWith(building, studyItem.getItem());
            if (bSlot > -1) {
                if (walkToBuilding()) {
                    setDelay(WALK_DELAY);
                    return getState();
                }
                takeItemStackFromProvider(building, bSlot);
            } else {
                checkIfRequestForItemExistOrCreateAsync(new ItemStack(studyItem.getItem(), studyItem.getBreakPct() / 10 > 0 ? studyItem.getBreakPct() / 10 : 1));
            }
        }
    } else // Use random item
    {
        final StudyItem chosenItem = currentItems.get(world.random.nextInt(currentItems.size()));
        worker.setItemInHand(Hand.MAIN_HAND, new ItemStack(chosenItem.getItem(), 1));
        data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE * (100D / chosenItem.getSkillIncreasePct()), data);
        // Break item rand
        if (world.random.nextInt(100) <= chosenItem.getBreakPct()) {
            data.getInventory().extractItem(chosenItem.getSlot(), 1, false);
        }
    }
    worker.decreaseSaturationForAction();
    studyPos = null;
    setDelay(STUDY_DELAY);
    return getState();
}
Also used : ArrayList(java.util.ArrayList) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemStack(net.minecraft.item.ItemStack) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem)

Example 3 with StudyItem

use of com.minecolonies.api.entity.ai.util.StudyItem in project minecolonies by Minecolonies.

the class BuildingLibrary method parseFromConfig.

/**
 * Parses Study Items from the Config and adds them on the keepX list
 *
 * @return the list of study items
 */
private List<StudyItem> parseFromConfig() {
    final List<StudyItem> studyItemList = new ArrayList<>();
    for (final String entry : MineColonies.getConfig().getServer().configListStudyItems.get()) {
        try {
            final String[] entries = entry.split(";");
            if (entries.length < 3) {
                Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
                continue;
            }
            final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(entries[0]));
            final int skillChance = Integer.parseInt(entries[1]);
            final int breakChance = Integer.parseInt(entries[2]);
            if (item == null || skillChance < 100 || skillChance > 1000 || breakChance > 100 || breakChance < 0) {
                Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
                continue;
            }
            studyItemList.add(new StudyItem(item, skillChance, breakChance));
            // Keep a certain part of the items in the Chest
            keepX.put(itemStack -> itemStack.getItem() == item, new Tuple<>(breakChance < 5 ? 5 : breakChance, true));
        } catch (NumberFormatException | ClassCastException e) {
            Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry + " Exception:" + e.getMessage());
        }
    }
    return studyItemList;
}
Also used : Item(net.minecraft.item.Item) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem)

Example 4 with StudyItem

use of com.minecolonies.api.entity.ai.util.StudyItem in project minecolonies by ldtteam.

the class EntityAIStudy method study.

/**
 * The AI task for the student to study. For this he should walk between the different bookcase hit them once and then stand around for a while.
 *
 * @return the next IAIState.
 */
private IAIState study() {
    final ICitizenData data = worker.getCitizenData();
    if (studyPos == null) {
        studyPos = getOwnBuilding().getRandomBookShelf();
    }
    if (walkToBlock(studyPos)) {
        setDelay(WALK_DELAY);
        return getState();
    }
    // Search for Items to use to study
    final List<StudyItem> currentItems = new ArrayList<>();
    for (final StudyItem curItem : getOwnBuilding().getStudyItems()) {
        final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, itemStack -> !ItemStackUtils.isEmpty(itemStack) && itemStack.getItem() == curItem.getItem());
        if (slot != -1) {
            curItem.setSlot(slot);
            currentItems.add(curItem);
        }
    }
    // Create a new Request for items
    if (currentItems.isEmpty()) {
        // Default levelup
        data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE, data);
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        for (final StudyItem studyItem : getOwnBuilding().getStudyItems()) {
            final int bSlot = InventoryUtils.findFirstSlotInProviderWith(getOwnBuilding(), studyItem.getItem());
            if (bSlot > -1) {
                if (walkToBuilding()) {
                    setDelay(WALK_DELAY);
                    return getState();
                }
                takeItemStackFromProvider(getOwnBuilding(), bSlot);
            } else {
                checkIfRequestForItemExistOrCreateAsynch(new ItemStack(studyItem.getItem(), studyItem.getBreakPct() / 10 > 0 ? studyItem.getBreakPct() / 10 : 1));
            }
        }
    } else // Use random item
    {
        final StudyItem chosenItem = currentItems.get(world.random.nextInt(currentItems.size()));
        worker.setItemInHand(Hand.MAIN_HAND, new ItemStack(chosenItem.getItem(), 1));
        data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE * (100D / chosenItem.getSkillIncreasePct()), data);
        // Break item rand
        if (world.random.nextInt(100) <= chosenItem.getBreakPct()) {
            data.getInventory().extractItem(chosenItem.getSlot(), 1, false);
        }
    }
    worker.decreaseSaturationForAction();
    studyPos = null;
    setDelay(STUDY_DELAY);
    return getState();
}
Also used : ArrayList(java.util.ArrayList) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemStack(net.minecraft.item.ItemStack) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem)

Aggregations

StudyItem (com.minecolonies.api.entity.ai.util.StudyItem)4 ArrayList (java.util.ArrayList)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2