Search in sources :

Example 1 with CraftingType

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

the class ModCraftingTypesInitializer method init.

public static void init(final RegistryEvent.Register<CraftingType> event) {
    final IForgeRegistry<CraftingType> reg = event.getRegistry();
    ModCraftingTypes.SMALL_CRAFTING = new RecipeCraftingType<>(ModCraftingTypes.SMALL_CRAFTING_ID, IRecipeType.CRAFTING, r -> r.canCraftInDimensions(2, 2));
    reg.register(ModCraftingTypes.SMALL_CRAFTING);
    ModCraftingTypes.LARGE_CRAFTING = new RecipeCraftingType<>(ModCraftingTypes.LARGE_CRAFTING_ID, IRecipeType.CRAFTING, r -> r.canCraftInDimensions(3, 3) && !r.canCraftInDimensions(2, 2));
    reg.register(ModCraftingTypes.LARGE_CRAFTING);
    ModCraftingTypes.SMELTING = new RecipeCraftingType<>(ModCraftingTypes.SMELTING_ID, IRecipeType.SMELTING, null);
    reg.register(ModCraftingTypes.SMELTING);
    ModCraftingTypes.BREWING = new BrewingCraftingType();
    reg.register(ModCraftingTypes.BREWING);
}
Also used : RecipeCraftingType(com.minecolonies.api.crafting.RecipeCraftingType) BrewingCraftingType(com.minecolonies.coremod.recipes.BrewingCraftingType) RegistryEvent(net.minecraftforge.event.RegistryEvent) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) ModCraftingTypes(com.minecolonies.api.crafting.ModCraftingTypes) IRecipeType(net.minecraft.item.crafting.IRecipeType) RecipeCraftingType(com.minecolonies.api.crafting.RecipeCraftingType) BrewingCraftingType(com.minecolonies.coremod.recipes.BrewingCraftingType) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) BrewingCraftingType(com.minecolonies.coremod.recipes.BrewingCraftingType)

Example 2 with CraftingType

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

the class CommonMinecoloniesAPIImpl method onRegistryNewRegistry.

public void onRegistryNewRegistry(final RegistryEvent.NewRegistry event) {
    buildingRegistry = new RegistryBuilder<BuildingEntry>().setName(new ResourceLocation(Constants.MOD_ID, "buildings")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setType(BuildingEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    jobRegistry = new RegistryBuilder<JobEntry>().setName(new ResourceLocation(Constants.MOD_ID, "jobs")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setType(JobEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    guardTypeRegistry = new RegistryBuilder<GuardType>().setName(new ResourceLocation(Constants.MOD_ID, "guardtypes")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setDefaultKey(ModGuardTypes.KNIGHT_ID).setType(GuardType.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    interactionHandlerRegistry = new RegistryBuilder<InteractionResponseHandlerEntry>().setName(new ResourceLocation(Constants.MOD_ID, "interactionresponsehandlers")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setType(InteractionResponseHandlerEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    colonyEventRegistry = new RegistryBuilder<ColonyEventTypeRegistryEntry>().setName(new ResourceLocation(Constants.MOD_ID, "colonyeventtypes")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setType(ColonyEventTypeRegistryEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    colonyEventDescriptionRegistry = new RegistryBuilder<ColonyEventDescriptionTypeRegistryEntry>().setName(new ResourceLocation(Constants.MOD_ID, "colonyeventdesctypes")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "null")).disableSaving().allowModification().setType(ColonyEventDescriptionTypeRegistryEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    craftingTypeRegistry = new RegistryBuilder<CraftingType>().setName(new ResourceLocation(Constants.MOD_ID, "craftingtypes")).disableSaving().allowModification().setType(CraftingType.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    recipeTypeEntryRegistry = new RegistryBuilder<RecipeTypeEntry>().setName(new ResourceLocation(Constants.MOD_ID, "recipetypeentries")).setDefaultKey(new ResourceLocation(Constants.MOD_ID, "classic")).disableSaving().allowModification().setType(RecipeTypeEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    researchRequirementRegistry = new RegistryBuilder<ResearchRequirementEntry>().setName(new ResourceLocation(Constants.MOD_ID, "researchrequirementtypes")).setDefaultKey(RESEARCH_RESEARCH_REQ_ID).disableSaving().allowModification().setType(ResearchRequirementEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
    researchEffectRegistry = new RegistryBuilder<ResearchEffectEntry>().setName(new ResourceLocation(Constants.MOD_ID, "researcheffecttypes")).setDefaultKey(GLOBAL_EFFECT_ID).disableSaving().allowModification().setType(ResearchEffectEntry.class).setIDRange(0, Integer.MAX_VALUE - 1).create();
}
Also used : RecipeTypeEntry(com.minecolonies.api.crafting.registry.RecipeTypeEntry) GuardType(com.minecolonies.api.colony.guardtype.GuardType) ColonyEventTypeRegistryEntry(com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ColonyEventDescriptionTypeRegistryEntry(com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) ResearchEffectEntry(com.minecolonies.api.research.effects.registry.ResearchEffectEntry) InteractionResponseHandlerEntry(com.minecolonies.api.colony.interactionhandling.registry.InteractionResponseHandlerEntry) BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) ResourceLocation(net.minecraft.util.ResourceLocation) RegistryBuilder(net.minecraftforge.registries.RegistryBuilder) ResearchRequirementEntry(com.minecolonies.api.research.registry.ResearchRequirementEntry)

Example 3 with CraftingType

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

the class CraftingModuleView method deserialize.

@Override
public void deserialize(@NotNull PacketBuffer buf) {
    if (buf.readBoolean()) {
        this.jobEntry = buf.readRegistryIdSafe(JobEntry.class);
    } else {
        this.jobEntry = null;
    }
    recipeTypeSet.clear();
    final int size = buf.readVarInt();
    for (int i = 0; i < size; ++i) {
        final CraftingType type = buf.readRegistryIdUnsafe(MinecoloniesAPIProxy.getInstance().getCraftingTypeRegistry());
        if (type != null) {
            recipeTypeSet.add(type);
        }
    }
    recipes.clear();
    disabledRecipes.clear();
    final int recipesSize = buf.readInt();
    for (int i = 0; i < recipesSize; i++) {
        final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt());
        if (storage != null) {
            recipes.add(storage);
        }
    }
    final int disabledRecipeSize = buf.readInt();
    for (int i = 0; i < disabledRecipeSize; i++) {
        final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt());
        if (storage != null) {
            disabledRecipes.add(storage);
        }
    }
    this.maxRecipes = buf.readInt();
    this.id = buf.readUtf(32767);
    this.isVisible = buf.readBoolean();
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage)

Example 4 with CraftingType

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

the class RecipeAnalyzer method findRecipes.

/**
 * Find all recipes for a given crafter.
 *
 * @param vanilla vanilla recipes map.
 * @param crafting crafting module.
 * @return list of recipes
 */
@NotNull
public static List<IGenericRecipe> findRecipes(@NotNull final Map<CraftingType, List<IGenericRecipe>> vanilla, @NotNull final ICraftingBuildingModule crafting) {
    final List<IGenericRecipe> recipes = new ArrayList<>();
    // all vanilla teachable recipes
    for (final Map.Entry<CraftingType, List<IGenericRecipe>> entry : vanilla.entrySet()) {
        if (crafting.canLearn(entry.getKey())) {
            for (final IGenericRecipe recipe : entry.getValue()) {
                final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, crafting.getIngredientValidator());
                if (crafting.isRecipeCompatible(safeRecipe)) {
                    recipes.add(safeRecipe);
                }
            }
        }
    }
    // custom MineColonies additional recipes
    for (final CustomRecipe customRecipe : CustomRecipeManager.getInstance().getRecipes(crafting.getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = customRecipe.getRecipeStorage();
        if (!recipeStorage.getAlternateOutputs().isEmpty()) {
            // this is a multi-output recipe; assume it replaces a bunch of vanilla
            // recipes we already added above
            recipes.removeIf(r -> ItemStackUtils.compareItemStacksIgnoreStackSize(recipeStorage.getPrimaryOutput(), r.getPrimaryOutput()));
            recipes.removeIf(r -> recipeStorage.getAlternateOutputs().stream().anyMatch(s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, r.getPrimaryOutput())));
        }
        recipes.add(GenericRecipeUtils.create(customRecipe, recipeStorage));
    }
    // and even more recipes that can't be taught, but are just inherent in the worker AI
    recipes.addAll(crafting.getAdditionalRecipesForDisplayPurposesOnly());
    return recipes;
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) World(net.minecraft.world.World) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) ArrayList(java.util.ArrayList) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) RecipeManager(net.minecraft.item.crafting.RecipeManager) Map(java.util.Map) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) NotNull(org.jetbrains.annotations.NotNull) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) ArrayList(java.util.ArrayList) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CraftingType

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

the class RecipeAnalyzer method buildVanillaRecipesMap.

/**
 * Build a map of all potentially learnable vanilla recipes, converted to {@link IGenericRecipe}.
 *
 * @param recipeManager the vanilla recipe manager
 * @return the recipe map
 */
public static Map<CraftingType, List<IGenericRecipe>> buildVanillaRecipesMap(@NotNull final RecipeManager recipeManager, @Nullable final World world) {
    final ImmutableMap.Builder<CraftingType, List<IGenericRecipe>> builder = ImmutableMap.builder();
    for (final CraftingType type : MinecoloniesAPIProxy.getInstance().getCraftingTypeRegistry().getValues()) {
        final List<IGenericRecipe> recipes = type.findRecipes(recipeManager, world);
        builder.put(type, recipes);
    }
    return builder.build();
}
Also used : CraftingType(com.minecolonies.api.crafting.registry.CraftingType) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe)

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