Search in sources :

Example 16 with ICraftingBuildingModule

use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.

the class CraftingTagAuditor method doRecipeAudit.

private static void doRecipeAudit(@NotNull final BufferedWriter writer, @NotNull final MinecraftServer server, @NotNull final CustomRecipeManager customRecipeManager) throws IOException {
    final Map<CraftingType, List<IGenericRecipe>> vanillaRecipesMap = RecipeAnalyzer.buildVanillaRecipesMap(server.getRecipeManager(), server.overworld());
    final List<ICraftingBuildingModule> crafters = getCraftingModules().stream().sorted(Comparator.comparing(m -> m instanceof SimpleCraftingModule).reversed()).collect(// sort the simple modules first (2x2 crafting, personal only)
    Collectors.toList());
    final Map<ItemStorage, Map<ICraftingBuildingModule, List<IGenericRecipe>>> craftingMap = new HashMap<>();
    // initially map every vanilla craftable
    for (final List<IGenericRecipe> recipeList : vanillaRecipesMap.values()) {
        for (final IGenericRecipe recipe : recipeList) {
            add(customRecipeManager, craftingMap, null, recipe);
        }
    }
    writeItemHeaders(writer);
    writer.write(",player");
    for (final ICraftingBuildingModule crafter : crafters) {
        writer.write(',');
        writer.write(crafter.getCustomRecipeKey());
        final List<IGenericRecipe> recipes = RecipeAnalyzer.findRecipes(vanillaRecipesMap, crafter);
        for (final IGenericRecipe recipe : recipes) {
            add(customRecipeManager, craftingMap, crafter, recipe);
        }
    }
    writer.newLine();
    for (final ItemStack item : getAllItems()) {
        writeItemData(writer, item);
        final Map<ICraftingBuildingModule, List<IGenericRecipe>> crafterMap = craftingMap.getOrDefault(new ItemStorage(item, true, false), Collections.emptyMap());
        writeCrafterValue(writer, crafterMap, null);
        for (final ICraftingBuildingModule crafter : crafters) {
            writeCrafterValue(writer, crafterMap, crafter);
        }
        writer.newLine();
    }
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) java.util(java.util) SimpleCraftingModule(com.minecolonies.coremod.colony.buildings.modules.SimpleCraftingModule) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) Supplier(java.util.function.Supplier) ItemStack(net.minecraft.item.ItemStack) MinecraftServer(net.minecraft.server.MinecraftServer) IMinecoloniesAPI(com.minecolonies.api.IMinecoloniesAPI) FolderName(net.minecraft.world.storage.FolderName) MOD_ID(com.minecolonies.api.util.constant.Constants.MOD_ID) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) Log(com.minecolonies.api.util.Log) LootTableAnalyzer(com.minecolonies.coremod.colony.crafting.LootTableAnalyzer) Path(java.nio.file.Path) ICompatibilityManager(com.minecolonies.api.compatibility.ICompatibilityManager) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IColonyManager(com.minecolonies.api.colony.IColonyManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RecipeAnalyzer(com.minecolonies.coremod.colony.crafting.RecipeAnalyzer) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) IBuildingModule(com.minecolonies.api.colony.buildings.modules.IBuildingModule) SimpleCraftingModule(com.minecolonies.coremod.colony.buildings.modules.SimpleCraftingModule) ItemStorage(com.minecolonies.api.crafting.ItemStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ICraftingBuildingModule

use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.

the class JEIPlugin method registerCategories.

@Override
public void registerCategories(@NotNull final IRecipeCategoryRegistration registration) {
    final IJeiHelpers jeiHelpers = registration.getJeiHelpers();
    final IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
    final IModIdHelper modIdHelper = jeiHelpers.getModIdHelper();
    registration.addRecipeCategories(new CompostRecipeCategory(guiHelper));
    registration.addRecipeCategories(new FishermanRecipeCategory(guiHelper));
    categories.clear();
    for (final BuildingEntry building : IMinecoloniesAPI.getInstance().getBuildingRegistry()) {
        for (final Supplier<IBuildingModule> producer : building.getModuleProducers()) {
            final IBuildingModule module = producer.get();
            if (module instanceof ICraftingBuildingModule) {
                final ICraftingBuildingModule crafting = (ICraftingBuildingModule) module;
                final IJob<?> job = crafting.getCraftingJob();
                if (job != null) {
                    registerCategory(registration, new GenericRecipeCategory(building, job, crafting, guiHelper, modIdHelper));
                }
            }
            if (module instanceof AnimalHerdingModule) {
                final AnimalHerdingModule herding = (AnimalHerdingModule) module;
                registerCategory(registration, new HerderRecipeCategory(building, herding.getHerdingJob(), herding, guiHelper));
            }
        }
    }
}
Also used : IGuiHelper(mezz.jei.api.helpers.IGuiHelper) IBuildingModule(com.minecolonies.api.colony.buildings.modules.IBuildingModule) AnimalHerdingModule(com.minecolonies.coremod.colony.buildings.modules.AnimalHerdingModule) IModIdHelper(mezz.jei.api.helpers.IModIdHelper) IJeiHelpers(mezz.jei.api.helpers.IJeiHelpers) BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)

Example 18 with ICraftingBuildingModule

use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.

the class AbstractCraftingProductionResolver method attemptResolveForBuildingAndStack.

@Nullable
protected List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull final IRequestManager manager, @NotNull final AbstractBuilding building, final ItemStack stack, final int count, final int minCount, final IToken<?> recipeId) {
    final ICraftingBuildingModule module = building.getCraftingModuleForRecipe(recipeId);
    if (module == null) {
        return null;
    }
    if (!canBuildingCraftStack(manager, building, stack)) {
        return null;
    }
    final IRecipeStorage fullfillableCrafting = module.getFirstFulfillableRecipe(itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack), count, true);
    if (fullfillableCrafting != null) {
        return ImmutableList.of();
    }
    final IRecipeStorage craftableCrafting = module.getFirstRecipe(stack);
    if (craftableCrafting == null) {
        return null;
    }
    return createRequestsForRecipe(manager, building, count, minCount, craftableCrafting);
}
Also used : IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with ICraftingBuildingModule

use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by ldtteam.

the class EntityAIWorkNether method decide.

@Override
protected IAIState decide() {
    if (job.isInNether()) {
        if (!worker.isInvisible()) {
            goToVault();
        }
        return NETHER_AWAY;
    }
    if (worker.isInvisible()) {
        returnFromVault();
    }
    IAIState crafterState = super.decide();
    if (crafterState != IDLE && crafterState != START_WORKING) {
        return crafterState;
    }
    // Get Armor if available.
    // This is async, so we could go to the nether without it.
    checkAndRequestArmor();
    // Check for materials needed to go to the Nether:
    IRecipeStorage rs = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class).getFirstRecipe(ItemStack::isEmpty);
    if (rs != null) {
        for (ItemStorage item : rs.getInput()) {
            checkAndRequestMaterials(item.getItemStack(), item.getAmount());
        }
    }
    // Make sure we have a stash of some food
    checkAndRequestFood(16);
    // Get other adventuring supplies. These are required.
    // Done this way to get all the requests in parallel
    boolean haveAxe = checkForToolOrWeapon(ToolType.AXE);
    boolean havePick = checkForToolOrWeapon(ToolType.PICKAXE);
    boolean haveShovel = checkForToolOrWeapon(ToolType.SHOVEL);
    boolean haveSword = checkForToolOrWeapon(ToolType.SWORD);
    boolean haveLighter = checkForToolOrWeapon(ToolType.FLINT_N_STEEL);
    if (haveAxe || havePick || haveShovel || haveSword || haveLighter) {
        worker.getCitizenData().setIdleAtJob(true);
        return IDLE;
    }
    if (currentRecipeStorage == null) {
        final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class);
        currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
        if (getOwnBuilding().isReadyForTrip()) {
            worker.getCitizenData().setIdleAtJob(true);
        }
        final BlockPos portal = getOwnBuilding().getPortalLocation();
        if (portal != null && currentRecipeStorage == null && getOwnBuilding().shallClosePortalOnReturn()) {
            final BlockState block = world.getBlockState(portal);
            if (block.is(Blocks.NETHER_PORTAL)) {
                return NETHER_CLOSEPORTAL;
            }
        }
        return getState();
    } else {
        if (!getOwnBuilding().isReadyForTrip()) {
            worker.getCitizenData().setIdleAtJob(false);
            return IDLE;
        }
        if (walkTo != null || walkToBuilding()) {
            return getState();
        }
        if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
            return INVENTORY_FULL;
        }
        IAIState checkResult = checkForItems(currentRecipeStorage);
        if (checkResult == GET_RECIPE) {
            currentRecipeStorage = null;
            worker.getCitizenData().setIdleAtJob(true);
            return IDLE;
        }
        if (checkResult != CRAFT) {
            return checkResult;
        }
    }
    return NETHER_LEAVE;
}
Also used : BuildingNetherWorker(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingNetherWorker) BlockState(net.minecraft.block.BlockState) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) BlockPos(net.minecraft.util.math.BlockPos) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 20 with ICraftingBuildingModule

use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by ldtteam.

the class AbstractCraftingProductionResolver method attemptResolveForBuildingAndStack.

@Nullable
protected List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull final IRequestManager manager, @NotNull final AbstractBuilding building, final ItemStack stack, final int count, final int minCount, final IToken<?> recipeId) {
    final ICraftingBuildingModule module = building.getCraftingModuleForRecipe(recipeId);
    if (module == null) {
        return null;
    }
    if (!canBuildingCraftStack(manager, building, stack)) {
        return null;
    }
    final IRecipeStorage fullfillableCrafting = module.getFirstFulfillableRecipe(itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack), count, true);
    if (fullfillableCrafting != null) {
        return ImmutableList.of();
    }
    final IRecipeStorage craftableCrafting = module.getFirstRecipe(stack);
    if (craftableCrafting == null) {
        return null;
    }
    return createRequestsForRecipe(manager, building, count, minCount, craftableCrafting);
}
Also used : IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ICraftingBuildingModule (com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)21 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)11 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)8 ItemStorage (com.minecolonies.api.crafting.ItemStorage)7 NotNull (org.jetbrains.annotations.NotNull)6 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)5 ItemStack (net.minecraft.item.ItemStack)5 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 InventoryUtils (com.minecolonies.api.util.InventoryUtils)4 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)4 Hand (net.minecraft.util.Hand)4 IBuildingModule (com.minecolonies.api.colony.buildings.modules.IBuildingModule)3 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)3 Nullable (org.jetbrains.annotations.Nullable)3 ImmutableList (com.google.common.collect.ImmutableList)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)2 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)2