External mod API
This commit is contained in:
parent
be459bed73
commit
5cdcc72531
6 changed files with 97 additions and 26 deletions
|
@ -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) {
|
||||
|
|
28
src/main/java/ru/betterend/api/BetterEndPlugin.java
Normal file
28
src/main/java/ru/betterend/api/BetterEndPlugin.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<Inventory> {
|
||||
|
||||
|
@ -118,8 +119,8 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
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<Inventory> {
|
|||
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<Inventory> {
|
|||
private String group;
|
||||
private float experience;
|
||||
private int smeltTime;
|
||||
private boolean alright = true;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
|
@ -146,11 +152,17 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
}
|
||||
|
||||
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<Inventory> {
|
|||
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<Inventory> {
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Inventory> {
|
||||
|
||||
|
@ -127,7 +128,11 @@ public class AnvilSmithingRecipe implements Recipe<Inventory> {
|
|||
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<Inventory> {
|
|||
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<Inventory> {
|
|||
}
|
||||
|
||||
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<Inventory> {
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue