Attempt to fix 1.16.3 branch's issues on the repository
Added the original 'wayoftime' folder back, so see if that fixed the multiple folder issue.
This commit is contained in:
parent
6b4145a67c
commit
9fa68e86ae
224 changed files with 24047 additions and 0 deletions
80
src/main/java/wayoftime/bloodmagic/api/IBloodMagicAPI.java
Normal file
80
src/main/java/wayoftime/bloodmagic/api/IBloodMagicAPI.java
Normal 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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
129
src/main/java/wayoftime/bloodmagic/api/SerializerHelper.java
Normal file
129
src/main/java/wayoftime/bloodmagic/api/SerializerHelper.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package wayoftime.bloodmagic.api.event;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
public class BloodMagicCraftedEvent extends Event
|
||||
{
|
||||
|
||||
private final boolean modifiable;
|
||||
private final ItemStack[] inputs;
|
||||
private ItemStack output;
|
||||
|
||||
public BloodMagicCraftedEvent(ItemStack output, ItemStack[] inputs, boolean modifiable)
|
||||
{
|
||||
this.modifiable = modifiable;
|
||||
this.inputs = inputs;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public boolean isModifiable()
|
||||
{
|
||||
return modifiable;
|
||||
}
|
||||
|
||||
public ItemStack[] getInputs()
|
||||
{
|
||||
return inputs;
|
||||
}
|
||||
|
||||
public ItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(ItemStack output)
|
||||
{
|
||||
if (isModifiable())
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired whenever a craft is completed in a Blood Altar.
|
||||
*
|
||||
* It is not cancelable, however you can modify the output stack.
|
||||
*/
|
||||
public static class Altar extends BloodMagicCraftedEvent
|
||||
{
|
||||
|
||||
public Altar(ItemStack output, ItemStack input)
|
||||
{
|
||||
super(output, new ItemStack[]
|
||||
{ input }, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired whenever a craft is completed in a Soul Forge.
|
||||
*
|
||||
* It is not cancelable, however you can modify the output stack.
|
||||
*/
|
||||
public static class SoulForge extends BloodMagicCraftedEvent
|
||||
{
|
||||
|
||||
public SoulForge(ItemStack output, ItemStack[] inputs)
|
||||
{
|
||||
super(output, inputs, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired whenever a craft is completed in an Alchemy Table.
|
||||
*
|
||||
* It is not cancelable, however you can modify the output stack.
|
||||
*/
|
||||
public static class AlchemyTable extends BloodMagicCraftedEvent
|
||||
{
|
||||
|
||||
public AlchemyTable(ItemStack output, ItemStack[] inputs)
|
||||
{
|
||||
super(output, inputs, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,385 @@
|
|||
package wayoftime.bloodmagic.api.event.recipes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.TagCollectionManager;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import wayoftime.bloodmagic.api.SerializerHelper;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
||||
/**
|
||||
* Created by Thiakil on 12/07/2019.
|
||||
*/
|
||||
public abstract class FluidStackIngredient implements InputIngredient<FluidStack>
|
||||
{
|
||||
|
||||
public static FluidStackIngredient from(@Nonnull Fluid instance, int amount)
|
||||
{
|
||||
return from(new FluidStack(instance, amount));
|
||||
}
|
||||
|
||||
public static FluidStackIngredient from(@Nonnull FluidStack instance)
|
||||
{
|
||||
return new Single(instance);
|
||||
}
|
||||
|
||||
public static FluidStackIngredient from(@Nonnull ITag<Fluid> fluidTag, int minAmount)
|
||||
{
|
||||
return new Tagged(fluidTag, minAmount);
|
||||
}
|
||||
|
||||
public static FluidStackIngredient read(PacketBuffer buffer)
|
||||
{
|
||||
// TODO: Allow supporting serialization of different types than just the ones we
|
||||
// implement?
|
||||
IngredientType type = buffer.readEnumValue(IngredientType.class);
|
||||
if (type == IngredientType.SINGLE)
|
||||
{
|
||||
return Single.read(buffer);
|
||||
} else if (type == IngredientType.TAGGED)
|
||||
{
|
||||
return Tagged.read(buffer);
|
||||
}
|
||||
return Multi.read(buffer);
|
||||
}
|
||||
|
||||
public static FluidStackIngredient deserialize(@Nullable JsonElement json)
|
||||
{
|
||||
if (json == null || json.isJsonNull())
|
||||
{
|
||||
throw new JsonSyntaxException("Ingredient cannot be null");
|
||||
}
|
||||
if (json.isJsonArray())
|
||||
{
|
||||
JsonArray jsonArray = json.getAsJsonArray();
|
||||
int size = jsonArray.size();
|
||||
if (size == 0)
|
||||
{
|
||||
throw new JsonSyntaxException("Ingredient array cannot be empty, at least one ingredient must be defined");
|
||||
} else if (size > 1)
|
||||
{
|
||||
FluidStackIngredient[] ingredients = new FluidStackIngredient[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
// Read all the ingredients
|
||||
ingredients[i] = deserialize(jsonArray.get(i));
|
||||
}
|
||||
return createMulti(ingredients);
|
||||
}
|
||||
// If we only have a single element, just set our json as that so that we don't
|
||||
// have to use Multi for efficiency reasons
|
||||
json = jsonArray.get(0);
|
||||
}
|
||||
if (!json.isJsonObject())
|
||||
{
|
||||
throw new JsonSyntaxException("Expected fluid to be object or array of objects");
|
||||
}
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
if (jsonObject.has(Constants.JSON.FLUID) && jsonObject.has(Constants.JSON.TAG))
|
||||
{
|
||||
throw new JsonParseException("An ingredient entry is either a tag or an fluid, not both");
|
||||
} else if (jsonObject.has(Constants.JSON.FLUID))
|
||||
{
|
||||
return from(SerializerHelper.deserializeFluid(jsonObject));
|
||||
} else if (jsonObject.has(Constants.JSON.TAG))
|
||||
{
|
||||
if (!jsonObject.has(Constants.JSON.AMOUNT))
|
||||
{
|
||||
throw new JsonSyntaxException("Expected to receive a amount that is greater than zero");
|
||||
}
|
||||
JsonElement count = jsonObject.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(jsonObject, Constants.JSON.TAG));
|
||||
ITag<Fluid> tag = TagCollectionManager.getManager().getFluidTags().get(resourceLocation);
|
||||
if (tag == null)
|
||||
{
|
||||
throw new JsonSyntaxException("Unknown fluid tag '" + resourceLocation + "'");
|
||||
}
|
||||
return from(tag, amount);
|
||||
}
|
||||
throw new JsonSyntaxException("Expected to receive a resource location representing either a tag or a fluid.");
|
||||
}
|
||||
|
||||
public static FluidStackIngredient createMulti(FluidStackIngredient... ingredients)
|
||||
{
|
||||
if (ingredients.length == 0)
|
||||
{
|
||||
// TODO: Throw error
|
||||
} else if (ingredients.length == 1)
|
||||
{
|
||||
return ingredients[0];
|
||||
}
|
||||
List<FluidStackIngredient> cleanedIngredients = new ArrayList<>();
|
||||
for (FluidStackIngredient ingredient : ingredients)
|
||||
{
|
||||
if (ingredient instanceof Multi)
|
||||
{
|
||||
// Don't worry about if our inner ingredients are multi as well, as if this is
|
||||
// the only external method for
|
||||
// creating a multi ingredient, then we are certified they won't be of a higher
|
||||
// depth
|
||||
cleanedIngredients.addAll(Arrays.asList(((Multi) ingredient).ingredients));
|
||||
} else
|
||||
{
|
||||
cleanedIngredients.add(ingredient);
|
||||
}
|
||||
}
|
||||
// There should be more than a single fluid or we would have split out earlier
|
||||
return new Multi(cleanedIngredients.toArray(new FluidStackIngredient[0]));
|
||||
}
|
||||
|
||||
public static class Single extends FluidStackIngredient
|
||||
{
|
||||
|
||||
@Nonnull
|
||||
private final FluidStack fluidInstance;
|
||||
|
||||
public Single(@Nonnull FluidStack fluidInstance)
|
||||
{
|
||||
this.fluidInstance = Objects.requireNonNull(fluidInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
return testType(fluidStack) && fluidStack.getAmount() >= fluidInstance.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testType(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
return Objects.requireNonNull(fluidStack).isFluidEqual(fluidInstance);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getMatchingInstance(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
return test(fluidStack) ? fluidInstance : FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<FluidStack> getRepresentations()
|
||||
{
|
||||
return Collections.singletonList(fluidInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
buffer.writeEnumValue(IngredientType.SINGLE);
|
||||
fluidInstance.writeToPacket(buffer);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public JsonElement serialize()
|
||||
{
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty(Constants.JSON.AMOUNT, fluidInstance.getAmount());
|
||||
json.addProperty(Constants.JSON.FLUID, fluidInstance.getFluid().getRegistryName().toString());
|
||||
if (fluidInstance.hasTag())
|
||||
{
|
||||
json.addProperty(Constants.JSON.NBT, fluidInstance.getTag().toString());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Single read(PacketBuffer buffer)
|
||||
{
|
||||
return new Single(FluidStack.readFromPacket(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Tagged extends FluidStackIngredient
|
||||
{
|
||||
|
||||
@Nonnull
|
||||
private final ITag<Fluid> tag;
|
||||
private final int amount;
|
||||
|
||||
public Tagged(@Nonnull ITag<Fluid> tag, int amount)
|
||||
{
|
||||
this.tag = tag;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
return testType(fluidStack) && fluidStack.getAmount() >= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testType(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
return Objects.requireNonNull(fluidStack).getFluid().isIn(tag);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getMatchingInstance(@Nonnull FluidStack fluidStack)
|
||||
{
|
||||
if (test(fluidStack))
|
||||
{
|
||||
// Our fluid is in the tag so we make a new stack with the given amount
|
||||
return new FluidStack(fluidStack, amount);
|
||||
}
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<FluidStack> getRepresentations()
|
||||
{
|
||||
// TODO: Can this be cached some how
|
||||
List<FluidStack> representations = new ArrayList<>();
|
||||
for (Fluid fluid : TagResolverHelper.getRepresentations(tag))
|
||||
{
|
||||
representations.add(new FluidStack(fluid, amount));
|
||||
}
|
||||
return representations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
buffer.writeEnumValue(IngredientType.TAGGED);
|
||||
buffer.writeResourceLocation(TagCollectionManager.getManager().getFluidTags().getValidatedIdFromTag(tag));
|
||||
buffer.writeVarInt(amount);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public JsonElement serialize()
|
||||
{
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty(Constants.JSON.AMOUNT, amount);
|
||||
json.addProperty(Constants.JSON.TAG, TagCollectionManager.getManager().getFluidTags().getValidatedIdFromTag(tag).toString());
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Tagged read(PacketBuffer buffer)
|
||||
{
|
||||
return new Tagged(FluidTags.makeWrapperTag(buffer.readResourceLocation().toString()), buffer.readVarInt());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Multi extends FluidStackIngredient
|
||||
{
|
||||
|
||||
private final FluidStackIngredient[] ingredients;
|
||||
|
||||
protected Multi(@Nonnull FluidStackIngredient... ingredients)
|
||||
{
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@Nonnull FluidStack stack)
|
||||
{
|
||||
return Arrays.stream(ingredients).anyMatch(ingredient -> ingredient.test(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testType(@Nonnull FluidStack stack)
|
||||
{
|
||||
return Arrays.stream(ingredients).anyMatch(ingredient -> ingredient.testType(stack));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getMatchingInstance(@Nonnull FluidStack stack)
|
||||
{
|
||||
for (FluidStackIngredient ingredient : ingredients)
|
||||
{
|
||||
FluidStack matchingInstance = ingredient.getMatchingInstance(stack);
|
||||
if (!matchingInstance.isEmpty())
|
||||
{
|
||||
return matchingInstance;
|
||||
}
|
||||
}
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<FluidStack> getRepresentations()
|
||||
{
|
||||
List<FluidStack> representations = new ArrayList<>();
|
||||
for (FluidStackIngredient ingredient : ingredients)
|
||||
{
|
||||
representations.addAll(ingredient.getRepresentations());
|
||||
}
|
||||
return representations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
buffer.writeEnumValue(IngredientType.MULTI);
|
||||
buffer.writeVarInt(ingredients.length);
|
||||
for (FluidStackIngredient ingredient : ingredients)
|
||||
{
|
||||
ingredient.write(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public JsonElement serialize()
|
||||
{
|
||||
JsonArray json = new JsonArray();
|
||||
for (FluidStackIngredient ingredient : ingredients)
|
||||
{
|
||||
json.add(ingredient.serialize());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static FluidStackIngredient read(PacketBuffer buffer)
|
||||
{
|
||||
FluidStackIngredient[] ingredients = new FluidStackIngredient[buffer.readVarInt()];
|
||||
for (int i = 0; i < ingredients.length; i++)
|
||||
{
|
||||
ingredients[i] = FluidStackIngredient.read(buffer);
|
||||
}
|
||||
return createMulti(ingredients);
|
||||
}
|
||||
}
|
||||
|
||||
private enum IngredientType
|
||||
{
|
||||
SINGLE,
|
||||
TAGGED,
|
||||
MULTI
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package wayoftime.bloodmagic.api.event.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public interface InputIngredient<TYPE> extends Predicate<TYPE>
|
||||
{
|
||||
|
||||
/**
|
||||
* Evaluates this predicate on the given argument, ignoring any size data.
|
||||
*
|
||||
* @param type the input argument
|
||||
*
|
||||
* @return {@code true} if the input argument matches the predicate, otherwise
|
||||
* {@code false}
|
||||
*/
|
||||
boolean testType(@Nonnull TYPE type);
|
||||
|
||||
TYPE getMatchingInstance(TYPE type);
|
||||
|
||||
/**
|
||||
* Primarily for JEI, a list of valid instances of the type
|
||||
*
|
||||
* @return List (empty means no valid registrations found and recipe is to be
|
||||
* hidden)
|
||||
*
|
||||
* @apiNote Do not modify any of the values returned by the representations
|
||||
*/
|
||||
@Nonnull
|
||||
List<TYPE> getRepresentations();
|
||||
|
||||
/**
|
||||
* Writes this ingredient to a PacketBuffer.
|
||||
*
|
||||
* @param buffer The buffer to write to.
|
||||
*/
|
||||
void write(PacketBuffer buffer);
|
||||
|
||||
/**
|
||||
* Serializes this ingredient to a JsonElement
|
||||
*
|
||||
* @return JsonElement representation of this ingredient.
|
||||
*/
|
||||
@Nonnull
|
||||
JsonElement serialize();
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package wayoftime.bloodmagic.api.event.recipes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tags.ITag;
|
||||
|
||||
/**
|
||||
* Copied from Mekanism, including the author's rant about tags.
|
||||
*/
|
||||
public class TagResolverHelper
|
||||
{
|
||||
|
||||
public static <TYPE> List<TYPE> getRepresentations(ITag<TYPE> tag)
|
||||
{
|
||||
try
|
||||
{
|
||||
return tag.getAllElements();
|
||||
} catch (IllegalStateException e)
|
||||
{
|
||||
// Why do tags have to be such an annoyance in 1.16
|
||||
// This is needed so that we can ensure we give JEI an empty list of
|
||||
// representations
|
||||
// instead of crashing on the first run, as recipes get "initialized" before
|
||||
// tags are
|
||||
// done initializing, and we don't want to spam the log with errors. JEI and
|
||||
// things
|
||||
// still work fine regardless of this
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
101
src/main/java/wayoftime/bloodmagic/api/impl/BloodMagicAPI.java
Normal file
101
src/main/java/wayoftime/bloodmagic/api/impl/BloodMagicAPI.java
Normal file
|
@ -0,0 +1,101 @@
|
|||
package wayoftime.bloodmagic.api.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import wayoftime.bloodmagic.altar.ComponentType;
|
||||
import wayoftime.bloodmagic.api.IBloodMagicAPI;
|
||||
import wayoftime.bloodmagic.util.BMLog;
|
||||
|
||||
public class BloodMagicAPI implements IBloodMagicAPI
|
||||
{
|
||||
|
||||
public static final BloodMagicAPI INSTANCE = new BloodMagicAPI();
|
||||
|
||||
// private final BloodMagicBlacklist blacklist;
|
||||
private final BloodMagicRecipeRegistrar recipeRegistrar;
|
||||
// private final BloodMagicValueManager valueManager;
|
||||
private final Multimap<ComponentType, BlockState> altarComponents;
|
||||
|
||||
public BloodMagicAPI()
|
||||
{
|
||||
// this.blacklist = new BloodMagicBlacklist();
|
||||
this.recipeRegistrar = new BloodMagicRecipeRegistrar();
|
||||
// this.valueManager = new BloodMagicValueManager();
|
||||
this.altarComponents = ArrayListMultimap.create();
|
||||
}
|
||||
|
||||
// @Nonnull
|
||||
// @Override
|
||||
// public BloodMagicBlacklist getBlacklist()
|
||||
// {
|
||||
// return blacklist;
|
||||
// }
|
||||
//
|
||||
@Nonnull
|
||||
@Override
|
||||
public BloodMagicRecipeRegistrar getRecipeRegistrar()
|
||||
{
|
||||
return recipeRegistrar;
|
||||
}
|
||||
//
|
||||
// @Nonnull
|
||||
// @Override
|
||||
// public BloodMagicValueManager getValueManager()
|
||||
// {
|
||||
// return valueManager;
|
||||
// }
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
if (component != null)
|
||||
{
|
||||
BMLog.API_VERBOSE.info("Registered {} as a {} altar component.", state, componentType);
|
||||
altarComponents.put(component, state);
|
||||
} else
|
||||
BMLog.API.warn("Invalid Altar component type: {}.", componentType);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
if (component != null)
|
||||
{
|
||||
BMLog.API_VERBOSE.info("Unregistered {} from being a {} altar component.", state, componentType);
|
||||
altarComponents.remove(component, state);
|
||||
} else
|
||||
BMLog.API.warn("Invalid Altar component type: {}.", componentType);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<BlockState> getComponentStates(ComponentType component)
|
||||
{
|
||||
return (List<BlockState>) altarComponents.get(component);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package wayoftime.bloodmagic.api.impl;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import wayoftime.bloodmagic.altar.ComponentType;
|
||||
import wayoftime.bloodmagic.api.IBloodMagicAPI;
|
||||
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
|
||||
|
||||
public class BloodMagicCorePlugin
|
||||
{
|
||||
public static final BloodMagicCorePlugin INSTANCE = new BloodMagicCorePlugin();
|
||||
|
||||
public void register(IBloodMagicAPI apiInterface)
|
||||
{
|
||||
apiInterface.registerAltarComponent(Blocks.GLOWSTONE.getDefaultState(), ComponentType.GLOWSTONE.name());
|
||||
apiInterface.registerAltarComponent(Blocks.SEA_LANTERN.getDefaultState(), ComponentType.GLOWSTONE.name());
|
||||
apiInterface.registerAltarComponent(Blocks.BEACON.getDefaultState(), ComponentType.BEACON.name());
|
||||
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.BLANK_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.SPEED_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.SACRIFICE_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.SELF_SACRIFICE_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.DISPLACEMENT_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.CAPACITY_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.AUGMENTED_CAPACITY_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.ORB_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.ACCELERATION_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
apiInterface.registerAltarComponent(BloodMagicBlocks.CHARGING_RUNE.get().getDefaultState(), ComponentType.BLOODRUNE.name());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,484 @@
|
|||
package wayoftime.bloodmagic.api.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
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.impl.recipe.RecipeARC;
|
||||
import wayoftime.bloodmagic.api.impl.recipe.RecipeAlchemyArray;
|
||||
import wayoftime.bloodmagic.api.impl.recipe.RecipeBloodAltar;
|
||||
import wayoftime.bloodmagic.api.impl.recipe.RecipeTartaricForge;
|
||||
import wayoftime.bloodmagic.common.recipe.BloodMagicRecipeType;
|
||||
|
||||
public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar
|
||||
{
|
||||
|
||||
// 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)
|
||||
{
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
if (input.isEmpty())
|
||||
return null;
|
||||
|
||||
List<RecipeBloodAltar> altarRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ALTAR);
|
||||
|
||||
for (RecipeBloodAltar recipe : altarRecipes) if (recipe.getInput().test(input))
|
||||
return recipe;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RecipeARC getARC(World world, @Nonnull ItemStack input, @Nonnull ItemStack arcToolInput, @Nonnull FluidStack inputFluid)
|
||||
{
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
Preconditions.checkNotNull(arcToolInput, "tool cannot be null.");
|
||||
if (input.isEmpty() || arcToolInput.isEmpty())
|
||||
return null;
|
||||
|
||||
List<RecipeARC> arcRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ARC);
|
||||
|
||||
for (RecipeARC recipe : arcRecipes)
|
||||
{
|
||||
if (recipe.getInput().test(input) && recipe.getTool().test(arcToolInput))
|
||||
{
|
||||
if (recipe.getFluidIngredient() == null)
|
||||
{
|
||||
return recipe;
|
||||
} else if (recipe.getFluidIngredient().test(inputFluid))
|
||||
{
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (input.isEmpty())
|
||||
// return null;
|
||||
//
|
||||
// List<RecipeBloodAltar> altarRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ALTAR);
|
||||
//
|
||||
// for (RecipeBloodAltar recipe : altarRecipes) if (recipe.getInput().test(input))
|
||||
// return recipe;
|
||||
|
||||
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 RecipeTartaricForge getTartaricForge(World world, @Nonnull List<ItemStack> input)
|
||||
{
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
if (input.isEmpty())
|
||||
return null;
|
||||
|
||||
List<RecipeTartaricForge> tartaricForgeRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.TARTARICFORGE);
|
||||
mainLoop: for (RecipeTartaricForge recipe : tartaricForgeRecipes)
|
||||
{
|
||||
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.test(input.get(i)))
|
||||
{
|
||||
matched = true;
|
||||
recipeInput.remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched)
|
||||
continue mainLoop;
|
||||
}
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
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
|
||||
* @param input
|
||||
* @param catalyst
|
||||
* @return If false and the recipe is nonnull, it is a partial match. If true,
|
||||
* the returned recipe is a full match.
|
||||
*/
|
||||
@Nullable
|
||||
public Pair<Boolean, RecipeAlchemyArray> getAlchemyArray(World world, @Nonnull ItemStack input, @Nonnull ItemStack catalyst)
|
||||
{
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
if (input.isEmpty())
|
||||
return null;
|
||||
|
||||
List<RecipeAlchemyArray> altarRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ARRAY);
|
||||
|
||||
RecipeAlchemyArray partialMatch = null;
|
||||
for (RecipeAlchemyArray recipe : altarRecipes)
|
||||
{
|
||||
if (recipe.getBaseInput().test(input))
|
||||
{
|
||||
if (recipe.getAddedInput().test(catalyst))
|
||||
{
|
||||
return Pair.of(true, recipe);
|
||||
} else if (partialMatch == null)
|
||||
{
|
||||
partialMatch = recipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Pair.of(false, partialMatch);
|
||||
}
|
||||
|
||||
public Set<RecipeBloodAltar> getAltarRecipes(World world)
|
||||
{
|
||||
return ImmutableSet.copyOf(world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ALTAR));
|
||||
}
|
||||
|
||||
public Set<RecipeTartaricForge> getTartaricForgeRecipes(World world)
|
||||
{
|
||||
return ImmutableSet.copyOf(world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.TARTARICFORGE));
|
||||
}
|
||||
|
||||
public Set<RecipeAlchemyArray> getAlchemyArrayRecipes(World world)
|
||||
{
|
||||
return ImmutableSet.copyOf(world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ARRAY));
|
||||
}
|
||||
|
||||
public Set<RecipeAlchemyArray> getCraftingAlchemyArrayRecipes(World world)
|
||||
{
|
||||
Set<RecipeAlchemyArray> recipes = Set.copyOf(world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ARRAY));
|
||||
Set<RecipeAlchemyArray> copyRecipes = Set.of();
|
||||
for (RecipeAlchemyArray recipe : recipes)
|
||||
{
|
||||
if (!recipe.getOutput().isEmpty())
|
||||
{
|
||||
copyRecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package wayoftime.bloodmagic.api.impl.recipe;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import wayoftime.bloodmagic.api.inventory.IgnoredIInventory;
|
||||
|
||||
public abstract class BloodMagicRecipe implements IRecipe<IgnoredIInventory>
|
||||
{
|
||||
private final ResourceLocation id;
|
||||
|
||||
protected BloodMagicRecipe(ResourceLocation id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this recipe to a PacketBuffer.
|
||||
*
|
||||
* @param buffer The buffer to write to.
|
||||
*/
|
||||
public abstract void write(PacketBuffer buffer);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull IgnoredIInventory inv, @Nonnull World world)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic()
|
||||
{
|
||||
// Note: If we make this non dynamic, we can make it show in vanilla's crafting
|
||||
// book and also then obey the recipe locking.
|
||||
// For now none of that works/makes sense in our concept so don't lock it
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull IgnoredIInventory inv)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
package wayoftime.bloodmagic.api.impl.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import wayoftime.bloodmagic.api.event.recipes.FluidStackIngredient;
|
||||
|
||||
public abstract class RecipeARC extends BloodMagicRecipe
|
||||
{
|
||||
public static final int MAX_RANDOM_OUTPUTS = 3;
|
||||
|
||||
@Nonnull
|
||||
private final Ingredient input;
|
||||
@Nonnull
|
||||
private final Ingredient arc_tool;
|
||||
private final FluidStackIngredient inputFluid;
|
||||
@Nonnull
|
||||
private final ItemStack output;
|
||||
private final FluidStack outputFluid;
|
||||
|
||||
private final List<Pair<ItemStack, Double>> addedItems;
|
||||
|
||||
protected RecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, FluidStackIngredient inputFluid, ItemStack output, FluidStack outputFluid)
|
||||
{
|
||||
this(id, input, arc_tool, inputFluid, output, new ArrayList<Pair<ItemStack, Double>>(), outputFluid);
|
||||
}
|
||||
|
||||
protected RecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, FluidStackIngredient inputFluid, ItemStack output, List<Pair<ItemStack, Double>> addedItems, FluidStack outputFluid)
|
||||
{
|
||||
super(id);
|
||||
this.input = input;
|
||||
this.arc_tool = arc_tool;
|
||||
this.inputFluid = inputFluid;
|
||||
this.output = output;
|
||||
this.addedItems = addedItems;
|
||||
this.outputFluid = outputFluid;
|
||||
}
|
||||
|
||||
public RecipeARC addRandomOutput(ItemStack stack, double chance)
|
||||
{
|
||||
if (addedItems.size() >= MAX_RANDOM_OUTPUTS)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
addedItems.add(Pair.of(stack, chance));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final Ingredient getInput()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final Ingredient getTool()
|
||||
{
|
||||
return arc_tool;
|
||||
}
|
||||
|
||||
public final FluidStackIngredient getFluidIngredient()
|
||||
{
|
||||
return inputFluid;
|
||||
}
|
||||
|
||||
public final FluidStack getFluidOutput()
|
||||
{
|
||||
return outputFluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
NonNullList<Ingredient> list = NonNullList.create();
|
||||
list.add(getInput());
|
||||
list.add(getTool());
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ItemStack> getAllListedOutputs()
|
||||
{
|
||||
List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
|
||||
list.add(output.copy());
|
||||
for (Pair<ItemStack, Double> pair : addedItems)
|
||||
{
|
||||
list.add(pair.getLeft().copy());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ItemStack> getAllOutputs(Random rand)
|
||||
{
|
||||
List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
|
||||
list.add(output.copy());
|
||||
for (Pair<ItemStack, Double> pair : addedItems)
|
||||
{
|
||||
if (rand.nextDouble() < pair.getRight())
|
||||
list.add(pair.getLeft().copy());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
input.write(buffer);
|
||||
arc_tool.write(buffer);
|
||||
buffer.writeItemStack(output);
|
||||
buffer.writeInt(addedItems.size());
|
||||
for (Pair<ItemStack, Double> pair : addedItems)
|
||||
{
|
||||
buffer.writeItemStack(pair.getLeft());
|
||||
buffer.writeDouble(pair.getValue());
|
||||
}
|
||||
|
||||
buffer.writeBoolean(inputFluid != null);
|
||||
if (inputFluid != null)
|
||||
{
|
||||
inputFluid.write(buffer);
|
||||
}
|
||||
|
||||
buffer.writeBoolean(outputFluid != null);
|
||||
if (outputFluid != null)
|
||||
{
|
||||
outputFluid.writeToPacket(buffer);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package wayoftime.bloodmagic.api.impl.recipe;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class RecipeAlchemyArray extends BloodMagicRecipe
|
||||
{
|
||||
private final ResourceLocation id;
|
||||
private final ResourceLocation texture;
|
||||
@Nonnull
|
||||
private final Ingredient baseInput;
|
||||
@Nonnull
|
||||
private final Ingredient addedInput;
|
||||
@Nonnull
|
||||
private final ItemStack output;
|
||||
|
||||
protected RecipeAlchemyArray(ResourceLocation id, ResourceLocation texture, @Nonnull Ingredient baseIngredient, @Nonnull Ingredient addedIngredient, @Nonnull ItemStack result)
|
||||
{
|
||||
super(id);
|
||||
this.id = id;
|
||||
this.texture = texture;
|
||||
this.baseInput = baseIngredient;
|
||||
this.addedInput = addedIngredient;
|
||||
this.output = result;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final ResourceLocation getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final ResourceLocation getTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final Ingredient getBaseInput()
|
||||
{
|
||||
return baseInput;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final Ingredient getAddedInput()
|
||||
{
|
||||
return addedInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
NonNullList<Ingredient> list = NonNullList.create();
|
||||
list.add(getBaseInput());
|
||||
list.add(getAddedInput());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final ItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
if (texture != null)
|
||||
{
|
||||
buffer.writeBoolean(true);
|
||||
buffer.writeResourceLocation(texture);
|
||||
} else
|
||||
{
|
||||
buffer.writeBoolean(false);
|
||||
}
|
||||
|
||||
baseInput.write(buffer);
|
||||
addedInput.write(buffer);
|
||||
buffer.writeItemStack(output);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package wayoftime.bloodmagic.api.impl.recipe;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import wayoftime.bloodmagic.altar.AltarTier;
|
||||
|
||||
public abstract class RecipeBloodAltar extends BloodMagicRecipe
|
||||
{
|
||||
@Nonnull
|
||||
private final Ingredient input;
|
||||
@Nonnull
|
||||
private final ItemStack output;
|
||||
@Nonnull
|
||||
private final AltarTier minimumTier;
|
||||
@Nonnegative
|
||||
private final int syphon;
|
||||
@Nonnegative
|
||||
private final int consumeRate;
|
||||
@Nonnegative
|
||||
private final int drainRate;
|
||||
|
||||
public RecipeBloodAltar(ResourceLocation id, @Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier, @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate)
|
||||
{
|
||||
super(id);
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
Preconditions.checkArgument(minimumTier >= 0, "minimumTier cannot be negative.");
|
||||
Preconditions.checkArgument(minimumTier <= AltarTier.MAXTIERS, "minimumTier cannot be higher than max tier");
|
||||
Preconditions.checkArgument(syphon >= 0, "syphon cannot be negative.");
|
||||
Preconditions.checkArgument(consumeRate >= 0, "consumeRate cannot be negative.");
|
||||
Preconditions.checkArgument(drainRate >= 0, "drain cannot be negative.");
|
||||
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.minimumTier = AltarTier.values()[minimumTier];
|
||||
this.syphon = syphon;
|
||||
this.consumeRate = consumeRate;
|
||||
this.drainRate = drainRate;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final Ingredient getInput()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
NonNullList<Ingredient> list = NonNullList.create();
|
||||
list.add(getInput());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final ItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public AltarTier getMinimumTier()
|
||||
{
|
||||
return minimumTier;
|
||||
}
|
||||
|
||||
@Nonnegative
|
||||
public final int getSyphon()
|
||||
{
|
||||
return syphon;
|
||||
}
|
||||
|
||||
@Nonnegative
|
||||
public final int getConsumeRate()
|
||||
{
|
||||
return consumeRate;
|
||||
}
|
||||
|
||||
@Nonnegative
|
||||
public final int getDrainRate()
|
||||
{
|
||||
return drainRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
input.write(buffer);
|
||||
buffer.writeItemStack(output);
|
||||
buffer.writeInt(minimumTier.ordinal());
|
||||
buffer.writeInt(syphon);
|
||||
buffer.writeInt(consumeRate);
|
||||
buffer.writeInt(drainRate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package wayoftime.bloodmagic.api.impl.recipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class RecipeTartaricForge extends BloodMagicRecipe
|
||||
{
|
||||
@Nonnull
|
||||
private final List<Ingredient> input;
|
||||
@Nonnull
|
||||
private final ItemStack output;
|
||||
@Nonnegative
|
||||
private final double minimumSouls;
|
||||
@Nonnegative
|
||||
private final double soulDrain;
|
||||
|
||||
public RecipeTartaricForge(ResourceLocation id, @Nonnull List<Ingredient> input, @Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain)
|
||||
{
|
||||
super(id);
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
|
||||
Preconditions.checkArgument(soulDrain >= 0, "soulDrain cannot be negative.");
|
||||
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.minimumSouls = minimumSouls;
|
||||
this.soulDrain = soulDrain;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final List<Ingredient> getInput()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final ItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
@Nonnegative
|
||||
public final double getMinimumSouls()
|
||||
{
|
||||
return minimumSouls;
|
||||
}
|
||||
|
||||
@Nonnegative
|
||||
public final double getSoulDrain()
|
||||
{
|
||||
return soulDrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer)
|
||||
{
|
||||
buffer.writeInt(input.size());
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
{
|
||||
input.get(i).write(buffer);
|
||||
}
|
||||
buffer.writeItemStack(output);
|
||||
buffer.writeDouble(minimumSouls);
|
||||
buffer.writeDouble(soulDrain);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package wayoftime.bloodmagic.api.inventory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class IgnoredIInventory implements IInventory
|
||||
{
|
||||
public static final IgnoredIInventory INSTANCE = new IgnoredIInventory();
|
||||
|
||||
private IgnoredIInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, @Nonnull ItemStack stack)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer(@Nonnull PlayerEntity player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package wayoftime.bloodmagic.api.providers;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import wayoftime.bloodmagic.api.text.IHasTextComponent;
|
||||
import wayoftime.bloodmagic.api.text.IHasTranslationKey;
|
||||
|
||||
public interface IBaseProvider extends IHasTextComponent, IHasTranslationKey
|
||||
{
|
||||
ResourceLocation getRegistryName();
|
||||
|
||||
default String getName()
|
||||
{
|
||||
return getRegistryName().getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITextComponent getTextComponent()
|
||||
{
|
||||
return new TranslationTextComponent(getTranslationKey());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package wayoftime.bloodmagic.api.providers;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public interface IEntityTypeProvider extends IBaseProvider
|
||||
{
|
||||
|
||||
@Nonnull
|
||||
EntityType<?> getEntityType();
|
||||
|
||||
@Override
|
||||
default ResourceLocation getRegistryName()
|
||||
{
|
||||
return getEntityType().getRegistryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITextComponent getTextComponent()
|
||||
{
|
||||
return getEntityType().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default String getTranslationKey()
|
||||
{
|
||||
return getEntityType().getTranslationKey();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package wayoftime.bloodmagic.api.text;
|
||||
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public interface IHasTextComponent
|
||||
{
|
||||
ITextComponent getTextComponent();
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package wayoftime.bloodmagic.api.text;
|
||||
|
||||
public interface IHasTranslationKey
|
||||
{
|
||||
String getTranslationKey();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue