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);
}
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();
}
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();
}
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;
}
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();
}
Aggregations