Creating a usable API (#1713)

* Initial stab at API structuring

* Throwing all the things into the API*
Eliminated all internal imports
Also added some helpful comments
*except for the ritual stuff

* Reducing the API
Threw back the altar/incense/unnecessary items to main
Added in a functional API instance

* API cleanup
Removing all the unnecessities
Smushed and vaporized some redundant recipe stuffs

* Made API dummy instances
Refactor packaging
This commit is contained in:
Arcaratus 2020-11-23 21:03:19 -05:00 committed by GitHub
parent 952b6aeeb0
commit 574d6a8e74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
144 changed files with 558 additions and 990 deletions

View file

@ -1,6 +1,7 @@
package wayoftime.bloodmagic.impl;
import java.util.List;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
@ -8,9 +9,15 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import wayoftime.bloodmagic.altar.ComponentType;
import wayoftime.bloodmagic.api.IBloodMagicAPI;
import wayoftime.bloodmagic.api.compat.EnumDemonWillType;
import wayoftime.bloodmagic.incense.EnumTranquilityType;
import wayoftime.bloodmagic.incense.IncenseTranquilityRegistry;
import wayoftime.bloodmagic.incense.TranquilityStack;
import wayoftime.bloodmagic.util.BMLog;
import wayoftime.bloodmagic.will.PlayerDemonWillHandler;
public class BloodMagicAPI implements IBloodMagicAPI
{
@ -36,9 +43,8 @@ public class BloodMagicAPI implements IBloodMagicAPI
// {
// return blacklist;
// }
//
@Nonnull
@Override
public BloodMagicRecipeRegistrar getRecipeRegistrar()
{
return recipeRegistrar;
@ -55,15 +61,7 @@ public class BloodMagicAPI implements IBloodMagicAPI
@Override
public void registerAltarComponent(@Nonnull BlockState state, @Nonnull String componentType)
{
ComponentType component = null;
for (ComponentType type : ComponentType.VALUES)
{
if (type.name().equalsIgnoreCase(componentType))
{
component = type;
break;
}
}
ComponentType component = ComponentType.getType(componentType);
if (component != null)
{
@ -76,15 +74,7 @@ public class BloodMagicAPI implements IBloodMagicAPI
@Override
public void unregisterAltarComponent(@Nonnull BlockState state, @Nonnull String componentType)
{
ComponentType component = null;
for (ComponentType type : ComponentType.VALUES)
{
if (type.name().equalsIgnoreCase(componentType))
{
component = type;
break;
}
}
ComponentType component = ComponentType.getType(componentType);
if (component != null)
{
@ -94,6 +84,27 @@ public class BloodMagicAPI implements IBloodMagicAPI
BMLog.API.warn("Invalid Altar component type: {}.", componentType);
}
@Override
public void registerTranquilityHandler(@Nonnull Predicate<BlockState> blockState, @Nonnull String tranquilityType, double value)
{
EnumTranquilityType type = EnumTranquilityType.getType(tranquilityType);
if (type != null)
{
IncenseTranquilityRegistry.registerTranquilityHandler((world, pos, block, state) -> blockState.test(state) ? new TranquilityStack(type, value) : null);
}
else
{
BMLog.API.warn("Invalid Tranquility type: {}.", tranquilityType);
}
}
@Override
public double getTotalDemonWill(String willType, PlayerEntity player)
{
return PlayerDemonWillHandler.getTotalDemonWill(EnumDemonWillType.getType(willType), player);
}
@Nonnull
public List<BlockState> getComponentStates(ComponentType component)
{

View file

@ -1,11 +1,16 @@
package wayoftime.bloodmagic.impl;
import net.minecraft.block.Blocks;
import net.minecraft.block.FireBlock;
import net.minecraft.block.GrassBlock;
import net.minecraft.block.LeavesBlock;
import net.minecraft.tags.BlockTags;
import wayoftime.bloodmagic.altar.ComponentType;
import wayoftime.bloodmagic.api.IBloodMagicAPI;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.incense.EnumTranquilityType;
import wayoftime.bloodmagic.incense.TranquilityStack;
import wayoftime.bloodmagic.incense.IncenseTranquilityRegistry;
public class BloodMagicCorePlugin
{
@ -28,6 +33,13 @@ public class BloodMagicCorePlugin
api.getValueManager().setTranquility(Blocks.NETHER_WART, new TranquilityStack(EnumTranquilityType.CROP, 1.0D));
api.getValueManager().setTranquility(Blocks.BEETROOTS, new TranquilityStack(EnumTranquilityType.CROP, 1.0D));
apiInterface.registerTranquilityHandler(state -> state.getBlock() instanceof LeavesBlock, EnumTranquilityType.PLANT.name(), 1.0D);
apiInterface.registerTranquilityHandler(state -> state.getBlock() instanceof FireBlock, EnumTranquilityType.FIRE.name(), 1.0D);
apiInterface.registerTranquilityHandler(state -> state.getBlock() instanceof GrassBlock, EnumTranquilityType.EARTHEN.name(), 0.5D);
apiInterface.registerTranquilityHandler(state -> BlockTags.LOGS.contains(state.getBlock()), EnumTranquilityType.TREE.name(), 1.0D);
IncenseTranquilityRegistry.registerTranquilityHandler((world, pos, block, state) -> BloodMagicAPI.INSTANCE.getValueManager().getTranquility().get(state));
apiInterface.registerAltarComponent(Blocks.GLOWSTONE.getDefaultState(), ComponentType.GLOWSTONE.name());
apiInterface.registerAltarComponent(Blocks.SEA_LANTERN.getDefaultState(), ComponentType.GLOWSTONE.name());
apiInterface.registerAltarComponent(BloodMagicBlocks.BLOODSTONE.get().getDefaultState(), ComponentType.BLOODSTONE.name());

View file

@ -16,228 +16,15 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import wayoftime.bloodmagic.api.IBloodMagicRecipeRegistrar;
import wayoftime.bloodmagic.api.recipe.RecipeARC;
import wayoftime.bloodmagic.api.recipe.RecipeAlchemyArray;
import wayoftime.bloodmagic.api.recipe.RecipeAlchemyTable;
import wayoftime.bloodmagic.api.recipe.RecipeBloodAltar;
import wayoftime.bloodmagic.api.recipe.RecipeTartaricForge;
import wayoftime.bloodmagic.recipe.RecipeARC;
import wayoftime.bloodmagic.recipe.RecipeAlchemyArray;
import wayoftime.bloodmagic.recipe.RecipeAlchemyTable;
import wayoftime.bloodmagic.recipe.RecipeBloodAltar;
import wayoftime.bloodmagic.recipe.RecipeTartaricForge;
import wayoftime.bloodmagic.common.recipe.BloodMagicRecipeType;
public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar
public class BloodMagicRecipeRegistrar
{
// private final Set<RecipeBloodAltar> altarRecipes;
// private final Set<RecipeAlchemyTable> alchemyRecipes;
// private final Set<RecipeTartaricForge> tartaricForgeRecipes;
// private final Set<RecipeAlchemyArray> alchemyArrayRecipes;
// private final Set<RecipeSacrificeCraft> sacrificeCraftRecipes;
public BloodMagicRecipeRegistrar()
{
// this.altarRecipes = Sets.newHashSet();
// this.alchemyRecipes = Sets.newHashSet();
// this.tartaricForgeRecipes = Sets.newHashSet();
// this.alchemyArrayRecipes = Sets.newHashSet();
// this.sacrificeCraftRecipes = Sets.newHashSet();
}
// @Override
// public void addBloodAltar(@Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier,
// @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(minimumTier >= 0, "minimumTier cannot be negative.");
// Preconditions.checkArgument(syphon >= 0, "syphon cannot be negative.");
// Preconditions.checkArgument(consumeRate >= 0, "consumeRate cannot be negative.");
// Preconditions.checkArgument(drainRate >= 0, "drainRate cannot be negative.");
//
// // TODO: Got to adda ResourceLocation argument.
// altarRecipes.add(new IRecipeBloodAltar(null, input, output, minimumTier, syphon, consumeRate, drainRate));
// }
//
// @Override
// public boolean removeBloodAltar(@Nonnull ItemStack input)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// return altarRecipes.remove(getBloodAltar(input));
// }
// @Override
// public void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks,
// @Nonnegative int minimumTier, @Nonnull Ingredient... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(syphon >= 0, "syphon cannot be negative.");
// Preconditions.checkArgument(ticks >= 0, "ticks cannot be negative.");
// Preconditions.checkArgument(minimumTier >= 0, "minimumTier cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// NonNullList<Ingredient> inputs = NonNullList.from(Ingredient.EMPTY, input);
// alchemyRecipes.add(new RecipeAlchemyTable(inputs, output, syphon, ticks, minimumTier));
// }
//
// public void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks,
// @Nonnegative int minimumTier, @Nonnull Object... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(syphon >= 0, "syphon cannot be negative.");
// Preconditions.checkArgument(ticks >= 0, "ticks cannot be negative.");
// Preconditions.checkArgument(minimumTier >= 0, "minimumTier cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// List<Ingredient> ingredients = Lists.newArrayList();
// for (Object object : input)
// {
// if (object instanceof ItemStack && ((ItemStack) object).getItem() instanceof IBloodOrb)
// {
// ingredients.add(new IngredientBloodOrb(((IBloodOrb) ((ItemStack) object).getItem()).getOrb((ItemStack) object)));
// continue;
// }
//
// ingredients.add(CraftingHelper.getIngredient(object));
// }
//
// addAlchemyTable(output, syphon, ticks, minimumTier, ingredients.toArray(new Ingredient[0]));
// }
//
// public void addAlchemyTable(RecipeAlchemyTable recipe)
// {
// alchemyRecipes.add(recipe);
// }
//
// @Override
// public boolean removeAlchemyTable(@Nonnull ItemStack... input)
// {
// Preconditions.checkNotNull(input, "inputs cannot be null.");
//
// for (ItemStack stack : input) Preconditions.checkNotNull(stack, "input cannot be null.");
//
// return alchemyRecipes.remove(getAlchemyTable(Lists.newArrayList(input)));
// }
//
// @Override
// public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls,
// @Nonnegative double soulDrain, @Nonnull Ingredient... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
// Preconditions.checkArgument(soulDrain >= 0, "soulDrain cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// NonNullList<Ingredient> inputs = NonNullList.from(Ingredient.EMPTY, input);
// tartaricForgeRecipes.add(new RecipeTartaricForge(inputs, output, minimumSouls, soulDrain));
// }
//
// @Override
// public boolean removeTartaricForge(@Nonnull ItemStack... input)
// {
// Preconditions.checkNotNull(input, "inputs cannot be null.");
//
// for (ItemStack stack : input) Preconditions.checkNotNull(stack, "input cannot be null.");
//
// return tartaricForgeRecipes.remove(getTartaricForge(Lists.newArrayList(input)));
// }
//
// public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls,
// @Nonnegative double soulDrain, @Nonnull Object... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
// Preconditions.checkArgument(soulDrain >= 0, "soulDrain cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// List<Ingredient> ingredients = Lists.newArrayList();
// for (Object object : input)
// {
// if (object instanceof ItemStack && ((ItemStack) object).getItem() instanceof IBloodOrb)
// {
// ingredients.add(new IngredientBloodOrb(((IBloodOrb) ((ItemStack) object).getItem()).getOrb((ItemStack) object)));
// continue;
// }
//
// ingredients.add(CraftingHelper.getIngredient(object));
// }
//
// addTartaricForge(output, minimumSouls, soulDrain, ingredients.toArray(new Ingredient[0]));
// }
//
// @Override
// public void addAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output,
// @Nullable ResourceLocation circleTexture)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
// Preconditions.checkNotNull(output, "output cannot be null.");
//
// alchemyArrayRecipes.add(new RecipeAlchemyArray(input, catalyst, output, circleTexture));
// }
//
// @Override
// public boolean removeAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
//
// return alchemyArrayRecipes.remove(getAlchemyArray(input, catalyst));
// }
//
// public void addAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst, @Nonnull ItemStack output,
// @Nullable ResourceLocation circleTexture)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
// Preconditions.checkNotNull(output, "output cannot be null.");
//
// addAlchemyArray(Ingredient.fromStacks(input), Ingredient.fromStacks(catalyst), output, circleTexture);
// }
//
// public void addSacrificeCraft(@Nonnull ItemStack output, @Nonnegative double healthRequired,
// @Nonnull Object... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(healthRequired >= 0, "healthRequired cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// List<Ingredient> ingredients = Lists.newArrayList();
// for (Object object : input)
// {
// if (object instanceof ItemStack && ((ItemStack) object).getItem() instanceof IBloodOrb)
// {
// ingredients.add(new IngredientBloodOrb(((IBloodOrb) ((ItemStack) object).getItem()).getOrb((ItemStack) object)));
// continue;
// }
//
// ingredients.add(CraftingHelper.getIngredient(object));
// }
//
// addSacrificeCraft(output, healthRequired, ingredients.toArray(new Ingredient[0]));
// }
//
// @Override
// public boolean removeSacrificeCraft(@Nonnull ItemStack... input)
// {
// Preconditions.checkNotNull(input, "inputs cannot be null.");
//
// for (ItemStack stack : input) Preconditions.checkNotNull(stack, "input cannot be null.");
//
// return sacrificeCraftRecipes.remove(getSacrificeCraft(Lists.newArrayList(input)));
// }
//
// @Override
// public void addSacrificeCraft(@Nonnull ItemStack output, @Nonnegative double healthRequired,
// @Nonnull Ingredient... input)
// {
// Preconditions.checkNotNull(output, "output cannot be null.");
// Preconditions.checkArgument(healthRequired >= 0, "healthRequired cannot be negative.");
// Preconditions.checkNotNull(input, "input cannot be null.");
//
// NonNullList<Ingredient> inputs = NonNullList.from(Ingredient.EMPTY, input);
// sacrificeCraftRecipes.add(new RecipeSacrificeCraft(inputs, output, healthRequired));
// }
@Nullable
public RecipeBloodAltar getBloodAltar(World world, @Nonnull ItemStack input)
{
@ -287,44 +74,6 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar
return null;
}
// @Nullable
// public RecipeAlchemyTable getAlchemyTable(@Nonnull List<ItemStack> input)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// if (input.isEmpty())
// return null;
//
// mainLoop: for (RecipeAlchemyTable recipe : alchemyRecipes)
// {
// if (recipe.getInput().size() != input.size())
// continue;
//
// List<Ingredient> recipeInput = new ArrayList<>(recipe.getInput());
//
// for (int i = 0; i < input.size(); i++)
// {
// boolean matched = false;
// for (int j = 0; j < recipeInput.size(); j++)
// {
// Ingredient ingredient = recipeInput.get(j);
// if (ingredient.apply(input.get(i)))
// {
// matched = true;
// recipeInput.remove(j);
// break;
// }
// }
//
// if (!matched)
// continue mainLoop;
// }
//
// return recipe;
// }
//
// return null;
// }
//
@Nullable
public RecipeAlchemyTable getAlchemyTable(World world, @Nonnull List<ItemStack> input)
{
@ -403,45 +152,6 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar
return null;
}
//
// @Nullable
// public RecipeSacrificeCraft getSacrificeCraft(@Nonnull List<ItemStack> input)
// {
// Preconditions.checkNotNull(input, "input cannot be null.");
// if (input.isEmpty())
// return null;
//
// mainLoop: for (RecipeSacrificeCraft recipe : sacrificeCraftRecipes)
// {
// if (recipe.getInput().size() != input.size())
// continue;
//
// List<Ingredient> recipeInput = new ArrayList<>(recipe.getInput());
//
// for (int i = 0; i < input.size(); i++)
// {
// boolean matched = false;
// for (int j = 0; j < recipeInput.size(); j++)
// {
// Ingredient ingredient = recipeInput.get(j);
// if (ingredient.apply(input.get(i)))
// {
// matched = true;
// recipeInput.remove(j);
// break;
// }
// }
//
// if (!matched)
// continue mainLoop;
// }
//
// return recipe;
// }
//
// return null;
// }
//
/**
*
* @param world
@ -516,19 +226,4 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar
return copyRecipes;
}
// public Set<RecipeAlchemyTable> getAlchemyRecipes()
// {
// return ImmutableSet.copyOf(alchemyRecipes);
// }
//
// public Set<RecipeTartaricForge> getTartaricForgeRecipes()
// {
// return ImmutableSet.copyOf(tartaricForgeRecipes);
// }
//
// public Set<RecipeAlchemyArray> getAlchemyArrayRecipes()
// {
// return ImmutableSet.copyOf(alchemyArrayRecipes);
// }
}