Search in sources :

Example 6 with CraftingType

use of com.minecolonies.api.crafting.registry.CraftingType in project minecolonies by Minecolonies.

the class AbstractCraftingBuildingModule method serializeToView.

@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
    if (jobEntry != null) {
        buf.writeBoolean(true);
        buf.writeRegistryId(jobEntry);
    } else {
        buf.writeBoolean(false);
    }
    final Set<CraftingType> craftingTypes = this.getSupportedCraftingTypes();
    buf.writeVarInt(craftingTypes.size());
    for (final CraftingType type : craftingTypes) {
        buf.writeRegistryIdUnsafe(MinecoloniesAPIProxy.getInstance().getCraftingTypeRegistry(), type);
    }
    final List<IRecipeStorage> storages = new ArrayList<>();
    final List<IRecipeStorage> disabledStorages = new ArrayList<>();
    final Map<ResourceLocation, CustomRecipe> crafterRecipes = CustomRecipeManager.getInstance().getAllRecipes().getOrDefault(getCustomRecipeKey(), Collections.emptyMap());
    for (final IToken<?> token : new ArrayList<>(recipes)) {
        final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token);
        if (storage == null || (storage.getRecipeSource() != null && !crafterRecipes.containsKey(storage.getRecipeSource())) || (!isRecipeCompatibleWithCraftingModule(token) && !isPreTaughtRecipe(storage, crafterRecipes))) {
            removeRecipe(token);
        } else {
            storages.add(storage);
            if (disabledRecipes.contains(token)) {
                disabledStorages.add(storage);
            }
        }
    }
    buf.writeInt(storages.size());
    for (final IRecipeStorage storage : storages) {
        buf.writeNbt(StandardFactoryController.getInstance().serialize(storage));
    }
    buf.writeInt(disabledStorages.size());
    for (final IRecipeStorage storage : disabledStorages) {
        buf.writeNbt(StandardFactoryController.getInstance().serialize(storage));
    }
    buf.writeInt(getMaxRecipes());
    buf.writeUtf(getId());
    buf.writeBoolean(isVisible());
}
Also used : CraftingType(com.minecolonies.api.crafting.registry.CraftingType) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 7 with CraftingType

use of com.minecolonies.api.crafting.registry.CraftingType 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)

Aggregations

CraftingType (com.minecolonies.api.crafting.registry.CraftingType)7 IGenericRecipe (com.minecolonies.api.crafting.IGenericRecipe)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ICraftingBuildingModule (com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)2 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 IMinecoloniesAPI (com.minecolonies.api.IMinecoloniesAPI)1 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)1 IColonyManager (com.minecolonies.api.colony.IColonyManager)1 IBuildingModule (com.minecolonies.api.colony.buildings.modules.IBuildingModule)1 ColonyEventDescriptionTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry)1 ColonyEventTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry)1 GuardType (com.minecolonies.api.colony.guardtype.GuardType)1 InteractionResponseHandlerEntry (com.minecolonies.api.colony.interactionhandling.registry.InteractionResponseHandlerEntry)1