Revered API changes

Because I obviously don't know what I'm doing. Building the jar wasn't working, so reverted for now.
This commit is contained in:
WayofTime 2020-11-15 21:34:18 -05:00
parent 5e5ecfd30a
commit 545b50ac82
5 changed files with 1 additions and 2 deletions

View file

@ -0,0 +1,80 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
/**
* The main interface between a plugin and Blood Magic's internals.
*
* This API is intended for <i>compatibility</i> between other mods and Blood
* Magic. More advanced integration is out of the scope of this API and are
* considered "addons".
*
* To get an instance of this without actually creating an
* {@link IBloodMagicPlugin}, use {@link BloodMagicPlugin.Inject}.
*/
public interface IBloodMagicAPI
{
// /**
// * Retrieves the instance of the blacklist.
// *
// * @return the active {@link IBloodMagicBlacklist} instance
// */
// @Nonnull
// IBloodMagicBlacklist getBlacklist();
/**
* Retrieves the instance of the recipe registrar.
*
* @return the active {@link IBloodMagicRecipeRegistrar} instance
*/
@Nonnull
IBloodMagicRecipeRegistrar getRecipeRegistrar();
/**
* Retrieves the instance of the value manager.
*
* @return the active {@link IBloodMagicValueManager} instance
*/
@Nonnull
IBloodMagicValueManager getValueManager();
/**
* Registers an {@link IBlockState} as a given component for the Blood Altar.
* <p>
* Valid component types:
* <ul>
* <li>GLOWSTONE</li>
* <li>BLOODSTONE</li>
* <li>BEACON</li>
* <li>BLOODRUNE</li>
* <li>CRYSTAL</li>
* <li>NOTAIR</li>
* </ul>
*
* @param state The state to register
* @param componentType The type of Blood Altar component to register as.
*/
void registerAltarComponent(@Nonnull BlockState state, @Nonnull String componentType);
/**
* Removes an {@link IBlockState} from the component mappings
* <p>
* Valid component types:
* <ul>
* <li>GLOWSTONE</li>
* <li>BLOODSTONE</li>
* <li>BEACON</li>
* <li>BLOODRUNE</li>
* <li>CRYSTAL</li>
* <li>NOTAIR</li>
* </ul>
*
* @param state The state to unregister
* @param componentType The type of Blood Altar component to unregister from.
*/
void unregisterAltarComponent(@Nonnull BlockState state, @Nonnull String componentType);
}

View file

@ -0,0 +1,100 @@
package wayoftime.bloodmagic.api;
/**
* Allows recipe addition and removal.
*/
public interface IBloodMagicRecipeRegistrar
{
// /**
// * Adds a new recipe to the Blood Altar.
// *
// * @param input An input {@link Ingredient}.
// * @param output An output {@link ItemStack}.
// * @param minimumTier The minimum Blood Altar tier required for this recipe.
// * @param syphon The amount of Life Essence to syphon from the Blood Altar
// * over the course of the craft.
// * @param consumeRate How quickly the Life Essence is syphoned.
// * @param drainRate How quickly progress is lost if the Blood Altar runs out
// * of Life Essence during the craft.
// */
// void addBloodAltar(@Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier,
// @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate);
//
// /**
// * Removes a Blood Altar recipe based on an input {@link ItemStack}.
// *
// * @param input The input item to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeBloodAltar(@Nonnull ItemStack input);
//
// /**
// * Adds a new recipe to the Alchemy Table.
// *
// * @param output An output {@link ItemStack}.
// * @param syphon The amount of Life Essence to syphon from the Blood Orb's
// * bound network over the course of the craft.
// * @param ticks The amount of ticks it takes to complete the craft.
// * @param minimumTier The minimum Blood Orb tier required for this recipe.
// * @param input An array of {@link Ingredient}s to accept as inputs.
// */
// void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks,
// @Nonnegative int minimumTier, @Nonnull Ingredient... input);
//
// /**
// * Removes an Alchemy Table recipe based on an input {@link ItemStack} array.
// *
// * @param input The input items to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeAlchemyTable(@Nonnull ItemStack... input);
//
// /**
// * Adds a new recipe to the Soul/Tartaric Forge.
// *
// * @param output An output {@link ItemStack}.
// * @param minimumSouls The minimum number of souls that must be contained in the
// * Soul Gem.
// * @param soulDrain The number of souls to drain from the Soul Gem.
// * @param input An array of {@link Ingredient}s to accept as inputs.
// */
// void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain,
// @Nonnull Ingredient... input);
//
// /**
// * Removes a Soul/Tartaric Forge recipe based on an input {@link ItemStack}
// * array.
// *
// * @param input The input items to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeTartaricForge(@Nonnull ItemStack... input);
//
// /**
// * Adds a new recipe to the Alchemy Array.
// *
// * @param input An input {@link Ingredient}. First item put into the
// * Alchemy Array.
// * @param catalyst A catalyst {@link Ingredient}. Second item put into the
// * Alchemy Array.
// * @param output An output {@link ItemStack}.
// * @param circleTexture The texture to render for the Alchemy Array circle.
// */
// void addAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output,
// @Nullable ResourceLocation circleTexture);
//
// /**
// * Removes an Alchemy Array recipe based on an input {@link ItemStack} and it's
// * catalyst {@link ItemStack}.
// *
// * @param input The input item to remove the recipe of.
// * @param catalyst The catalyst item to remove the recipe of.
// * @return Whether or not a recipe was removed.
// */
// boolean removeAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst);
//
// void addSacrificeCraft(@Nonnull ItemStack output, @Nonnegative double healthRequired, @Nonnull Ingredient... input);
//
// boolean removeSacrificeCraft(@Nonnull ItemStack... input);
}

View file

@ -0,0 +1,45 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
import net.minecraft.util.ResourceLocation;
/**
* Allows value modification for various features of Blood Magic such as
* Sacrificial values.
*/
public interface IBloodMagicValueManager
{
/**
* Sets the amount of LP received per health point from sacrificing the given
* entity. By default, this is 25. Setting the value to 0 effectively disables
* sacrificing.
*
* @param entityId The registry name of the entity.
* @param value The amount of LP per health point to receive upon sacrifice.
*/
void setSacrificialValue(@Nonnull ResourceLocation entityId, @Nonnegative int value);
/**
* Sets the Tranquility value of a given {@link IBlockState}.
* <p>
* Valid tranquility types:
* <ul>
* <li>PLANT</li>
* <li>CROP</li>
* <li>TREE</li>
* <li>EARTHEN</li>
* <li>WATER</li>
* <li>FIRE</li>
* <li>LAVA</li>
* </ul>
*
* @param state The {@link IBlockState} to set the value of.
* @param tranquilityType The type of Tranquility this block should provide.
* @param value The amount of tranquility this block should provide.
*/
void setTranquility(@Nonnull BlockState state, @Nonnull String tranquilityType, double value);
}

View file

@ -0,0 +1,129 @@
package wayoftime.bloodmagic.api;
import javax.annotation.Nonnull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;
import wayoftime.bloodmagic.util.Constants;
/**
* Copied liberally from Mekanism. Thanks, pupnewfster!
*
*/
public class SerializerHelper
{
private SerializerHelper()
{
}
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private static void validateKey(@Nonnull JsonObject json, @Nonnull String key)
{
if (!json.has(key))
{
throw new JsonSyntaxException("Missing '" + key + "', expected to find an object");
}
if (!json.get(key).isJsonObject())
{
throw new JsonSyntaxException("Expected '" + key + "' to be an object");
}
}
public static ItemStack getItemStack(@Nonnull JsonObject json, @Nonnull String key)
{
validateKey(json, key);
return ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, key));
}
public static JsonElement serializeItemStack(@Nonnull ItemStack stack)
{
JsonObject json = new JsonObject();
json.addProperty(Constants.JSON.ITEM, stack.getItem().getRegistryName().toString());
if (stack.getCount() > 1)
{
json.addProperty(Constants.JSON.COUNT, stack.getCount());
}
if (stack.hasTag())
{
json.addProperty(Constants.JSON.NBT, stack.getTag().toString());
}
return json;
}
public static FluidStack getFluidStack(@Nonnull JsonObject json, @Nonnull String key)
{
validateKey(json, key);
return deserializeFluid(JSONUtils.getJsonObject(json, key));
}
public static FluidStack deserializeFluid(@Nonnull JsonObject json)
{
if (!json.has(Constants.JSON.AMOUNT))
{
throw new JsonSyntaxException("Expected to receive a amount that is greater than zero");
}
JsonElement count = json.get(Constants.JSON.AMOUNT);
if (!JSONUtils.isNumber(count))
{
throw new JsonSyntaxException("Expected amount to be a number greater than zero.");
}
int amount = count.getAsJsonPrimitive().getAsInt();
if (amount < 1)
{
throw new JsonSyntaxException("Expected amount to be greater than zero.");
}
ResourceLocation resourceLocation = new ResourceLocation(JSONUtils.getString(json, Constants.JSON.FLUID));
Fluid fluid = ForgeRegistries.FLUIDS.getValue(resourceLocation);
if (fluid == null || fluid == Fluids.EMPTY)
{
throw new JsonSyntaxException("Invalid fluid type '" + resourceLocation + "'");
}
CompoundNBT nbt = null;
if (json.has(Constants.JSON.NBT))
{
JsonElement jsonNBT = json.get(Constants.JSON.NBT);
try
{
if (jsonNBT.isJsonObject())
{
nbt = JsonToNBT.getTagFromJson(GSON.toJson(jsonNBT));
} else
{
nbt = JsonToNBT.getTagFromJson(JSONUtils.getString(jsonNBT, Constants.JSON.NBT));
}
} catch (CommandSyntaxException e)
{
throw new JsonSyntaxException("Invalid NBT entry for fluid '" + resourceLocation + "'");
}
}
return new FluidStack(fluid, amount, nbt);
}
public static JsonElement serializeFluidStack(@Nonnull FluidStack stack)
{
JsonObject json = new JsonObject();
json.addProperty(Constants.JSON.FLUID, stack.getFluid().getRegistryName().toString());
json.addProperty(Constants.JSON.AMOUNT, stack.getAmount());
if (stack.hasTag())
{
json.addProperty(Constants.JSON.NBT, stack.getTag().toString());
}
return json;
}
}