diff --git a/src/main/java/ru/betterend/BetterEnd.java b/src/main/java/ru/betterend/BetterEnd.java index 93ae34e0..d1f4b4e6 100644 --- a/src/main/java/ru/betterend/BetterEnd.java +++ b/src/main/java/ru/betterend/BetterEnd.java @@ -1,7 +1,9 @@ package ru.betterend; import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Identifier; +import ru.betterend.api.BetterEndPlugin; import ru.betterend.config.MainConfig; import ru.betterend.effects.EndEnchantments; import ru.betterend.effects.EndPotions; @@ -48,6 +50,9 @@ public class BetterEnd implements ModInitializer { AlloyingRecipes.register(); SmithingRecipes.register(); StructureRegistry.register(); + + FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class) + .forEach(BetterEndPlugin::register); } public static Identifier makeID(String path) { diff --git a/src/main/java/ru/betterend/api/BetterEndPlugin.java b/src/main/java/ru/betterend/api/BetterEndPlugin.java new file mode 100644 index 00000000..62ecd60d --- /dev/null +++ b/src/main/java/ru/betterend/api/BetterEndPlugin.java @@ -0,0 +1,28 @@ +package ru.betterend.api; + +public interface BetterEndPlugin { + /** + * Alloying recipes registration. + * See AlloyingRecipe.Builder for details. + */ + default void registerAlloyingRecipes() {} + + /** + * Smithing recipes registration. + * See AnvilSmithingRecipe.Builder for details. + */ + default void registerSmithingRecipes() {} + + /** + * Additional biomes registration. + * See BiomeRegistry.registerBiome for details. + */ + default void registerEndBiomes() {} + + + public static void register(BetterEndPlugin plugin) { + plugin.registerAlloyingRecipes(); + plugin.registerSmithingRecipes(); + plugin.registerEndBiomes(); + } +} diff --git a/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java b/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java index f2b2e6f6..4eb50bdd 100644 --- a/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java @@ -23,6 +23,7 @@ import net.minecraft.world.World; import ru.betterend.BetterEnd; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.registry.BlockRegistry; +import ru.betterend.util.RecipeHelper; public class AlloyingRecipe implements Recipe { @@ -118,8 +119,8 @@ public class AlloyingRecipe implements Recipe { public static class Builder { private final static Builder INSTANCE = new Builder(); - public static Builder create(String id) { - INSTANCE.id = BetterEnd.makeID(id); + public static Builder create(Identifier id) { + INSTANCE.id = id; INSTANCE.group = String.format("%s_%s", GROUP, id); INSTANCE.primaryInput = null; INSTANCE.secondaryInput = null; @@ -130,6 +131,10 @@ public class AlloyingRecipe implements Recipe { return INSTANCE; } + public static Builder create(String id) { + return create(BetterEnd.makeID(id)); + } + private Identifier id; private Ingredient primaryInput; private Ingredient secondaryInput; @@ -137,6 +142,7 @@ public class AlloyingRecipe implements Recipe { private String group; private float experience; private int smeltTime; + private boolean alright = true; private Builder() {} @@ -146,11 +152,17 @@ public class AlloyingRecipe implements Recipe { } public Builder setPrimaryInput(ItemConvertible... inputs) { + for (ItemConvertible item : inputs) { + this.alright &= RecipeHelper.exists(item); + } this.primaryInput = Ingredient.ofItems(inputs); return this; } public Builder setSecondaryInput(ItemConvertible... inputs) { + for (ItemConvertible item : inputs) { + this.alright &= RecipeHelper.exists(item); + } this.secondaryInput = Ingredient.ofItems(inputs); return this; } @@ -177,13 +189,8 @@ public class AlloyingRecipe implements Recipe { return this; } - public Builder setInput(Ingredient primaryInput, Ingredient secondaryInput) { - this.primaryInput = primaryInput; - this.secondaryInput = secondaryInput; - return this; - } - public Builder setOutput(ItemConvertible output, int amount) { + this.alright &= RecipeHelper.exists(output); this.output = new ItemStack(output, amount); return this; } @@ -200,13 +207,26 @@ public class AlloyingRecipe implements Recipe { public void build() { if (primaryInput == null) { - throw new IllegalArgumentException("Primary input can't be null!"); - } else if(secondaryInput == null) { - throw new IllegalArgumentException("Secondary input can't be null!"); - } else if(output == null) { - throw new IllegalArgumentException("Output can't be null!"); + BetterEnd.LOGGER.warning("Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!", id); + return; } - EndRecipeManager.addRecipe(AlloyingRecipe.TYPE, new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime)); + if(secondaryInput == null) { + BetterEnd.LOGGER.warning("Secondary input for Alloying can't be 'null', recipe {} will be ignored!", id); + return; + } + if(output == null) { + BetterEnd.LOGGER.warning("Output for Alloying can't be 'null', recipe {} will be ignored!", id); + return; + } + if (EndRecipeManager.getRecipe(TYPE, id) != null) { + BetterEnd.LOGGER.warning("Can't add Alloying recipe! Id {} already exists!", id); + return; + } + if (!alright) { + BetterEnd.LOGGER.debug("Can't add Alloying recipe {}! Ingeredient or output not exists.", id); + return; + } + EndRecipeManager.addRecipe(TYPE, new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime)); } } diff --git a/src/main/java/ru/betterend/recipe/builders/AnvilSmithingRecipe.java b/src/main/java/ru/betterend/recipe/builders/AnvilSmithingRecipe.java index f49b77a6..6f18ba57 100644 --- a/src/main/java/ru/betterend/recipe/builders/AnvilSmithingRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/AnvilSmithingRecipe.java @@ -24,6 +24,7 @@ import net.minecraft.world.World; import ru.betterend.BetterEnd; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.registry.ItemTagRegistry; +import ru.betterend.util.RecipeHelper; public class AnvilSmithingRecipe implements Recipe { @@ -127,7 +128,11 @@ public class AnvilSmithingRecipe implements Recipe { private final static Builder INSTANCE = new Builder(); public static Builder create(String id) { - INSTANCE.id = BetterEnd.makeID(id); + return create(BetterEnd.makeID(id)); + } + + public static Builder create(Identifier id) { + INSTANCE.id = id; INSTANCE.input = null; INSTANCE.output = null; INSTANCE.level = 1; @@ -141,11 +146,15 @@ public class AnvilSmithingRecipe implements Recipe { private ItemStack output; private int level = 1; private int damage = 1; + private boolean alright = true; private Builder() {} - public Builder setInput(ItemConvertible... inputItem) { - this.setInput(Ingredient.ofItems(inputItem)); + public Builder setInput(ItemConvertible... inputItems) { + for (ItemConvertible item : inputItems) { + this.alright &= RecipeHelper.exists(item); + } + this.setInput(Ingredient.ofItems(inputItems)); return this; } @@ -160,6 +169,7 @@ public class AnvilSmithingRecipe implements Recipe { } public Builder setOutput(ItemConvertible output, int amount) { + this.alright &= RecipeHelper.exists(output); this.output = new ItemStack(output, amount); return this; } @@ -176,11 +186,21 @@ public class AnvilSmithingRecipe implements Recipe { public void build() { if (input == null) { - throw new IllegalArgumentException("Input can't be null!"); - } else if(output == null) { - throw new IllegalArgumentException("Output can't be null!"); + BetterEnd.LOGGER.warning("Input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); + return; + } + if(output == null) { + BetterEnd.LOGGER.warning("Output for Smithing recipe can't be 'null', recipe {} will be ignored!", id); + return; + } + if (EndRecipeManager.getRecipe(TYPE, id) != null) { + BetterEnd.LOGGER.warning("Can't add Smithing recipe! Id {} already exists!", id); + return; + } + if (!alright) { + BetterEnd.LOGGER.debug("Can't add Smithing recipe {}! Ingeredient or output not exists.", id); + return; } - EndRecipeManager.addRecipe(TYPE, new AnvilSmithingRecipe(id, input, output, level, damage)); } } diff --git a/src/main/java/ru/betterend/recipe/builders/RecipeBuilder.java b/src/main/java/ru/betterend/recipe/builders/RecipeBuilder.java index d65c2d50..20886780 100644 --- a/src/main/java/ru/betterend/recipe/builders/RecipeBuilder.java +++ b/src/main/java/ru/betterend/recipe/builders/RecipeBuilder.java @@ -111,9 +111,8 @@ public class RecipeBuilder { CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials); EndRecipeManager.addRecipe(type, recipe); - } - else { - BetterEnd.LOGGER.debug("recipe {} couldn't be added", name); + } else { + BetterEnd.LOGGER.debug("Recipe {} couldn't be added", name); } } } diff --git a/src/main/java/ru/betterend/util/RecipeHelper.java b/src/main/java/ru/betterend/util/RecipeHelper.java index b6f9094b..36696623 100644 --- a/src/main/java/ru/betterend/util/RecipeHelper.java +++ b/src/main/java/ru/betterend/util/RecipeHelper.java @@ -8,8 +8,7 @@ public class RecipeHelper { public static boolean exists(ItemConvertible item) { if (item instanceof Block) { return Registry.BLOCK.getId((Block) item) != Registry.BLOCK.getDefaultId(); - } - else { + } else { return Registry.ITEM.getId(item.asItem()) != Registry.ITEM.getDefaultId(); } }