From 1044d2fea150b998879e03c4a85f9673f1c0c73c Mon Sep 17 00:00:00 2001 From: Takakura Anri Date: Thu, 5 Nov 2020 20:30:10 +0800 Subject: [PATCH] unused cleanup --- .travis.yml | 2 +- .../recipehandler/DefaultRecipeHandler.java | 59 ---- .../IPrototypedIngredientAlternatives.java | 36 --- .../recipehandler/IRecipeDefinition.java | 127 -------- .../recipehandler/IRecipeHandler.java | 60 ---- ...entAlternativesItemStackOredictionary.java | 154 --------- .../PrototypedIngredientAlternativesList.java | 104 ------ .../recipehandler/RecipeDefinition.java | 170 ---------- .../api/ingredient/IIngredientMatcher.java | 147 --------- .../api/ingredient/IIngredientSerializer.java | 43 --- .../api/ingredient/IMixedIngredients.java | 146 --------- .../api/ingredient/IPrototypedIngredient.java | 83 ----- .../api/ingredient/IngredientComponent.java | 303 ------------------ .../IngredientComponentCategoryType.java | 80 ----- .../ingredient/IngredientInstanceWrapper.java | 49 --- .../api/ingredient/MixedIngredients.java | 81 ----- .../ingredient/MixedIngredientsAdapter.java | 133 -------- .../api/ingredient/PrototypedIngredient.java | 80 ----- ...hCapabilitiesEventIngredientComponent.java | 21 -- ...IngredientComponentCapabilityAttacher.java | 33 -- ...entComponentCapabilityAttacherAdapter.java | 29 -- ...entComponentCapabilityAttacherManager.java | 52 --- ...aultIngredientComponentStorageHandler.java | 49 --- .../storage/IIngredientComponentStorage.java | 117 ------- .../IIngredientComponentStorageHandler.java | 33 -- .../IIngredientComponentStorageSlotted.java | 72 ----- ...redientComponentStorageWrapperHandler.java | 60 ---- .../IngredientComponentStorageEmpty.java | 57 ---- ...ngredientComponentStorageSlottedEmpty.java | 42 --- 29 files changed, 1 insertion(+), 2421 deletions(-) delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/DefaultRecipeHandler.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IPrototypedIngredientAlternatives.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeDefinition.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeHandler.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesItemStackOredictionary.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesList.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/RecipeDefinition.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientMatcher.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientSerializer.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IMixedIngredients.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IPrototypedIngredient.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponent.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponentCategoryType.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientInstanceWrapper.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredients.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredientsAdapter.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/PrototypedIngredient.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/AttachCapabilitiesEventIngredientComponent.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IIngredientComponentCapabilityAttacher.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherAdapter.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherManager.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/DefaultIngredientComponentStorageHandler.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorage.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageHandler.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageSlotted.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageWrapperHandler.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageEmpty.java delete mode 100644 src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageSlottedEmpty.java diff --git a/.travis.yml b/.travis.yml index f221c1f..96f2cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ cache: install: ./gradlew setupCiWorkspace script: - - ./gradlew setupCiWorkspace build \ No newline at end of file + - ./gradlew build \ No newline at end of file diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/DefaultRecipeHandler.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/DefaultRecipeHandler.java deleted file mode 100644 index f15f495..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/DefaultRecipeHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch; -import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; -import org.cyclops.commoncapabilities.api.ingredient.MixedIngredients; -import org.cyclops.commoncapabilities.api.ingredient.PrototypedIngredient; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Set; - -/** - * A default recipe handler that contains a dirt to diamonds recipe. - * @author rubensworks - */ -public class DefaultRecipeHandler implements IRecipeHandler { - @Override - public Set> getRecipeInputComponents() { - return Sets.newHashSet(IngredientComponent.ITEMSTACK); - } - - @Override - public Set> getRecipeOutputComponents() { - return Sets.newHashSet(IngredientComponent.ITEMSTACK); - } - - @Override - public boolean isValidSizeInput(IngredientComponent component, int size) { - return component == IngredientComponent.ITEMSTACK && size == 1; - } - - @Override - public List getRecipes() { - return Lists.newArrayList( - RecipeDefinition.ofIngredient(IngredientComponent.ITEMSTACK, - Lists.newArrayList(new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, new ItemStack(Blocks.DIRT), ItemMatch.EXACT)), - MixedIngredients.ofInstance(IngredientComponent.ITEMSTACK, new ItemStack(Items.DIAMOND)) - ) - ); - } - - @Nullable - @Override - public IMixedIngredients simulate(IMixedIngredients input) { - List ingredients = input.getInstances(IngredientComponent.ITEMSTACK); - if (input.getComponents().size() == 1 && ingredients.size() == 1) { - if (IngredientComponent.ITEMSTACK.getMatcher().matchesExactly(ingredients.get(0), new ItemStack(Blocks.DIRT))) { - return MixedIngredients.ofInstance(IngredientComponent.ITEMSTACK, new ItemStack(Items.DIAMOND)); - } - } - return null; - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IPrototypedIngredientAlternatives.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IPrototypedIngredientAlternatives.java deleted file mode 100644 index 2cf20c1..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IPrototypedIngredientAlternatives.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import it.unimi.dsi.fastutil.bytes.Byte2ObjectArrayMap; -import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; -import net.minecraft.nbt.NBTBase; -import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import java.util.Collection; - -/** - * A holder for a list of {@link org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient} alternatives. - * - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @author rubensworks - */ -public interface IPrototypedIngredientAlternatives { - - public static Byte2ObjectMap> SERIALIZERS = new Byte2ObjectArrayMap<>(); - - public Collection> getAlternatives(); - - public ISerializer getSerializer(); - - public static interface ISerializer> { - - public byte getId(); - - public NBTBase serialize(IngredientComponent ingredientComponent, A alternatives); - - public A deserialize(IngredientComponent ingredientComponent, NBTBase tag); - - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeDefinition.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeDefinition.java deleted file mode 100644 index d9c50e5..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeDefinition.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ResourceLocation; -import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Defines the inputs and outputs of a recipe. - * Inputs are ingredient prototypes for ingredient component types. - * Outputs are exact instances for ingredient component types. - * - * Implementing classes should properly implement the equals and hashCode methods. - * - * @author rubensworks - */ -public interface IRecipeDefinition extends Comparable { - - /** - * @return The input ingredient component types. - */ - public Set> getInputComponents(); - - /** - * Get the input prototypes of a certain type. - * - * The first list contains a list of ingredients, - * whereas the deeper second list contains different prototype-based alternatives for the ingredient at this position. - * - * @param ingredientComponent An ingredient component type. - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @return Input prototypes. - */ - public List> getInputs(IngredientComponent ingredientComponent); - - /** - * @return The output ingredients. - */ - public IMixedIngredients getOutput(); - - /** - * Deserialize a recipe to NBT. - * @param recipe A recipe. - * @return An NBT representation of the given recipe. - */ - public static NBTTagCompound serialize(IRecipeDefinition recipe) { - NBTTagCompound tag = new NBTTagCompound(); - NBTTagCompound inputTag = new NBTTagCompound(); - for (IngredientComponent component : recipe.getInputComponents()) { - NBTTagList instances = new NBTTagList(); - for (IPrototypedIngredientAlternatives ingredient : recipe.getInputs(component)) { - NBTTagCompound subTag = new NBTTagCompound(); - IPrototypedIngredientAlternatives.ISerializer serializer = ingredient.getSerializer(); - subTag.setTag("val", serializer.serialize(component, ingredient)); - subTag.setByte("type", serializer.getId()); - instances.appendTag(subTag); - } - inputTag.setTag(component.getRegistryName().toString(), instances); - } - tag.setTag("input", inputTag); - tag.setTag("output", IMixedIngredients.serialize(recipe.getOutput())); - return tag; - } - - /** - * Deserialize a recipe from NBT - * @param tag An NBT tag. - * @return A new mixed recipe instance. - * @throws IllegalArgumentException If the given tag is invalid or does not contain data on the given recipe. - */ - public static RecipeDefinition deserialize(NBTTagCompound tag) throws IllegalArgumentException { - Map, List>> inputs = Maps.newIdentityHashMap(); - if (!tag.hasKey("input")) { - throw new IllegalArgumentException("A recipe tag did not contain a valid input tag"); - } - if (!tag.hasKey("output")) { - throw new IllegalArgumentException("A recipe tag did not contain a valid output tag"); - } - NBTTagCompound inputTag = tag.getCompoundTag("input"); - for (String componentName : inputTag.getKeySet()) { - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); - if (component == null) { - throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); - } - NBTBase subTag = inputTag.getTag(componentName); - if (!(subTag instanceof NBTTagList)) { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid list of instances"); - } - NBTTagList instancesTag = (NBTTagList) subTag; - List> instances = Lists.newArrayList(); - for (NBTBase instanceTag : instancesTag) { - IPrototypedIngredientAlternatives.ISerializer alternativeSerializer; - NBTBase deserializeTag; - if (instanceTag instanceof NBTTagList) { - // TODO: remove backwards compat in 1.13 - alternativeSerializer = PrototypedIngredientAlternativesList.SERIALIZER; - deserializeTag = instanceTag; - } else if (instanceTag instanceof NBTTagCompound) { - NBTTagCompound instanceTagCompound = (NBTTagCompound) instanceTag; - byte type = instanceTagCompound.getByte("type"); - alternativeSerializer = IPrototypedIngredientAlternatives.SERIALIZERS.get(type); - if (alternativeSerializer == null) { - throw new IllegalArgumentException("Could not find a prototyped ingredient alternative serializer for id " + type); - } - deserializeTag = ((NBTTagCompound) instanceTag).getTag("val"); - } else { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid reference to instances"); - } - IPrototypedIngredientAlternatives alternatives = alternativeSerializer.deserialize(component, deserializeTag); - instances.add(alternatives); - } - inputs.put(component, instances); - } - IMixedIngredients output = IMixedIngredients.deserialize(tag.getCompoundTag("output")); - return new RecipeDefinition(inputs, output); - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeHandler.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeHandler.java deleted file mode 100644 index 58a5112..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/IRecipeHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Set; - -/** - * An IRecipeHandler is able to process recipes. - * - * It is used to expose the possible recipes the target can handle, - * and simulate what output will be produced based on a certain input. - * - * It may also expose further information on how the inputs and outputs - * must be handled. - * - * @author rubensworks - */ -public interface IRecipeHandler { - - /** - * @return The input recipe component types that are possible for recipes in this handler. - */ - public Set> getRecipeInputComponents(); - - /** - * @return The output recipe component types that are possible for recipes in this handler. - */ - public Set> getRecipeOutputComponents(); - - /** - * Check if the given size of recipe component instances are valid for the given recipe component type. - * @param component The component type. - * @param size A certain length of recipe component instances. - * @return If the given size of recipe component instances can be used by this recipe handler. - */ - public boolean isValidSizeInput(IngredientComponent component, int size); - - /** - * @return Recipes that are available through this handler, this list is not necessarily exhaustive, but SHOULD be. - * No consistent order should be assumed from in collection. - */ - public Collection getRecipes(); - - /** - * Test if the given recipe input can be handled by this handler. - * - * This method is mainly meant to be indicative. - * No actual crafting processes should be crafted because of this, - * i.e., calling this method should not have any effects on the state of this recipe handler. - * - * @param input A recipe input. - * @return The simulated output, or null if no valid recipe for the given input was found. - */ - @Nullable - public IMixedIngredients simulate(IMixedIngredients input); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesItemStackOredictionary.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesItemStackOredictionary.java deleted file mode 100644 index ced7341..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesItemStackOredictionary.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.Lists; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.NonNullList; -import net.minecraftforge.common.util.Constants; -import net.minecraftforge.oredict.OreDictionary; -import org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher; -import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; -import org.cyclops.commoncapabilities.api.ingredient.PrototypedIngredient; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * An oredictionary-based {@link IPrototypedIngredientAlternatives} implementation. - * @author rubensworks - */ -public class PrototypedIngredientAlternativesItemStackOredictionary implements IPrototypedIngredientAlternatives { - - public static final PrototypedIngredientAlternativesItemStackOredictionary.Serializer SERIALIZER = new PrototypedIngredientAlternativesItemStackOredictionary.Serializer(); - static { - SERIALIZERS.put((byte) 1, SERIALIZER); - } - - private static final LoadingCache> CACHE_OREDICT = CacheBuilder.newBuilder() - .expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader>() { - @Override - public List load(String key) throws Exception { - return OreDictionary.getOres(key); - } - }); - - private final List keys; - private final Integer matchCondition; - private final long quantity; - - public PrototypedIngredientAlternativesItemStackOredictionary(List keys, Integer matchCondition, long quantity) { - this.keys = keys; - this.matchCondition = matchCondition; - this.quantity = quantity; - } - - /** - * Get a list of variants from the given stack if its damage value is the wildcard value, - * otherwise the list will only contain the given itemstack. - * @param itemStack The itemstack - * @return The list of variants. - */ - public static List getItemStackVariants(ItemStack itemStack) { - NonNullList output = NonNullList.create(); - if(itemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { - itemStack.getItem().getSubItems(CreativeTabs.SEARCH, output); - } else { - output.add(itemStack); - } - return output; - } - - public Collection> getAlternatives() { - IIngredientMatcher matcher = IngredientComponent.ITEMSTACK.getMatcher(); - return this.keys.stream().flatMap((key) -> { - try { - return CACHE_OREDICT.get(key).stream(); - } catch (ExecutionException e) { - return Stream.empty(); - } - }).flatMap(itemStack -> getItemStackVariants(itemStack).stream()) - .map(itemStack -> matcher.withQuantity(itemStack, getQuantity())) - .map(itemStack -> new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, itemStack, this.matchCondition)) - .collect(Collectors.toList()); - } - - @Override - public ISerializer getSerializer() { - return SERIALIZER; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof IPrototypedIngredientAlternatives - && this.getAlternatives().equals(((IPrototypedIngredientAlternatives) obj).getAlternatives()); - } - - @Override - public int hashCode() { - int inputsHash = 333; - for (IPrototypedIngredient value : getAlternatives()) { - inputsHash |= value.hashCode(); - } - return 1235 | inputsHash << 2; - } - - public long getQuantity() { - return quantity; - } - - @Override - public String toString() { - return "[PrototypedIngredientAlternativesList: " + getAlternatives().toString() + "]"; - } - - public static class Serializer implements IPrototypedIngredientAlternatives.ISerializer { - @Override - public byte getId() { - return 1; - } - - @Override - public NBTBase serialize(IngredientComponent ingredientComponent, PrototypedIngredientAlternativesItemStackOredictionary alternatives) { - NBTTagCompound tag = new NBTTagCompound(); - NBTTagList keys = new NBTTagList(); - for (String key : alternatives.keys) { - keys.appendTag(new NBTTagString(key)); - } - tag.setTag("keys", keys); - tag.setInteger("match", alternatives.matchCondition); - tag.setLong("quantity", alternatives.quantity); - return tag; - } - - @Override - public PrototypedIngredientAlternativesItemStackOredictionary deserialize(IngredientComponent ingredientComponent, NBTBase tag) { - NBTTagCompound tagCompound = (NBTTagCompound) tag; - if (!tagCompound.hasKey("keys")) { - throw new IllegalArgumentException("A oredict prototyped alternatives did not contain valid keys"); - } - if (!tagCompound.hasKey("match")) { - throw new IllegalArgumentException("A oredict prototyped alternatives did not contain a valid match"); - } - NBTTagList keysTag = tagCompound.getTagList("keys", Constants.NBT.TAG_STRING); - List keys = Lists.newArrayList(); - for (NBTBase key : keysTag) { - keys.add(((NBTTagString) key).getString()); - } - int matchCondition = tagCompound.getInteger("match"); - long quantity = tagCompound.hasKey("quantity") ? tagCompound.getLong("quantity") : 1; // TODO: remove check in 1.13 - return new PrototypedIngredientAlternativesItemStackOredictionary(keys, matchCondition, quantity); - } - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesList.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesList.java deleted file mode 100644 index 1806ecf..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/PrototypedIngredientAlternativesList.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import com.google.common.collect.Lists; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import org.cyclops.commoncapabilities.api.ingredient.IIngredientSerializer; -import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; -import org.cyclops.commoncapabilities.api.ingredient.PrototypedIngredient; - -import java.util.Collection; -import java.util.List; - -/** - * A list-based {@link IPrototypedIngredientAlternatives} implementation. - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @author rubensworks - */ -public class PrototypedIngredientAlternativesList implements IPrototypedIngredientAlternatives { - - public static final PrototypedIngredientAlternativesList.Serializer SERIALIZER = new PrototypedIngredientAlternativesList.Serializer(); - - private final List> alternatives; - - public PrototypedIngredientAlternativesList(List> alternatives) { - this.alternatives = alternatives; - } - - public Collection> getAlternatives() { - return this.alternatives; - } - - @Override - public ISerializer getSerializer() { - return SERIALIZER; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof IPrototypedIngredientAlternatives - && this.getAlternatives().equals(((IPrototypedIngredientAlternatives) obj).getAlternatives()); - } - - @Override - public int hashCode() { - int inputsHash = 333; - for (IPrototypedIngredient value : getAlternatives()) { - inputsHash |= value.hashCode(); - } - return 1235 | inputsHash << 2; - } - - @Override - public String toString() { - return "[PrototypedIngredientAlternativesList: " + alternatives.toString() + "]"; - } - - public static class Serializer implements IPrototypedIngredientAlternatives.ISerializer> { - @Override - public byte getId() { - return 0; - } - - @Override - public NBTBase serialize(IngredientComponent ingredientComponent, PrototypedIngredientAlternativesList alternatives) { - NBTTagList prototypes = new NBTTagList(); - IIngredientSerializer serializer = ingredientComponent.getSerializer(); - for (IPrototypedIngredient prototypedIngredient : (List) (List) alternatives.alternatives) { - NBTTagCompound prototypeTag = new NBTTagCompound(); - prototypeTag.setTag("prototype", serializer.serializeInstance(prototypedIngredient.getPrototype())); - prototypeTag.setTag("condition", serializer.serializeCondition(prototypedIngredient.getCondition())); - prototypes.appendTag(prototypeTag); - } - return prototypes; - } - - @Override - public PrototypedIngredientAlternativesList deserialize(IngredientComponent ingredientComponent, NBTBase tag) { - String componentName = ingredientComponent.getName().toString(); - NBTTagList instancesTag = (NBTTagList) tag; - List> instances = Lists.newArrayList(); - IIngredientSerializer serializer = ingredientComponent.getSerializer(); - for (NBTBase prototypeTag : instancesTag) { - if (!(prototypeTag instanceof NBTTagCompound)) { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid sublist with NBTTagCompunds"); - } - NBTTagCompound safePrototypeTag = (NBTTagCompound) prototypeTag; - if (!safePrototypeTag.hasKey("prototype")) { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid sublist with a prototype entry"); - } - if (!safePrototypeTag.hasKey("condition")) { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid sublist with a condition entry"); - } - instances.add(new PrototypedIngredient<>(ingredientComponent, - serializer.deserializeInstance(safePrototypeTag.getTag("prototype")), - serializer.deserializeCondition(safePrototypeTag.getTag("condition")))); - } - return new PrototypedIngredientAlternativesList<>(instances); - } - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/RecipeDefinition.java b/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/RecipeDefinition.java deleted file mode 100644 index 6b6096b..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/capability/recipehandler/RecipeDefinition.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.cyclops.commoncapabilities.api.capability.recipehandler; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; -import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; -import org.cyclops.commoncapabilities.api.ingredient.MixedIngredients; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * A recipe definition based on maps. - * @author rubensworks - */ -public class RecipeDefinition implements IRecipeDefinition { - - private final Map, List>> inputs; - private final IMixedIngredients output; - - public RecipeDefinition(Map, List>> inputs, - IMixedIngredients output) { - this.inputs = inputs; - this.output = output; - } - - @Override - public Set> getInputComponents() { - return inputs.keySet(); - } - - @Override - public List> getInputs(IngredientComponent ingredientComponent) { - return (List>) (List) inputs.getOrDefault(ingredientComponent, Collections.emptyList()); - } - - @Override - public IMixedIngredients getOutput() { - return output; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof IRecipeDefinition) { - IRecipeDefinition that = (IRecipeDefinition) obj; - if (Sets.newHashSet(this.getInputComponents()).equals(Sets.newHashSet(that.getInputComponents())) - && this.getOutput().equals(that.getOutput())) { - for (IngredientComponent component : getInputComponents()) { - if (!this.getInputs(component).equals(that.getInputs(component))) { - return false; - } - } - return true; - } - } - return false; - } - - @Override - public int hashCode() { - int inputsHash = 333; - for (List> values : inputs.values()) { - inputsHash |= values.hashCode(); - } - return 578 | inputsHash << 2 | output.hashCode(); - } - - @Override - public String toString() { - return "[RecipeDefinition input: " + inputs.toString() + "; output: " + output.toString() + "]"; - } - - /** - * Create a new recipe definition for a single component type input and a list of alternatives. - * @param component A component type. - * @param alternatives The alternatives for the given component type. - * @param output The recipe output. - * @param The instance type. - * @param The recipe target type, may be Void. - * @param The matching condition parameter, may be Void. - * @return A new recipe definition. - */ - public static RecipeDefinition ofAlternatives(IngredientComponent component, - List> alternatives, - IMixedIngredients output) { - Map, List>> inputs = Maps.newIdentityHashMap(); - inputs.put(component, (List) alternatives); - return new RecipeDefinition(inputs, output); - } - - /** - * Create a new recipe definition for a single component type input and a list of instances. - * @param component A component type. - * @param ingredients The ingredients for the given component type. - * @param output The recipe output. - * @param The instance type. - * @param The recipe target type, may be Void. - * @param The matching condition parameter, may be Void. - * @return A new recipe definition. - */ - public static RecipeDefinition ofIngredients(IngredientComponent component, - List>> ingredients, - IMixedIngredients output) { - return ofAlternatives(component, ingredients.stream() - .map(PrototypedIngredientAlternativesList::new) - .collect(Collectors.toList()), output); - } - - /** - * Create a new recipe definittion for a single component type input and a single instance. - * @param component A component type. - * @param ingredient An ingredient for the given component type. - * @param output The recipe output. - * @param The instance type. - * @param The recipe target type, may be Void. - * @param The matching condition parameter, may be Void. - * @return A new recipe definition. - */ - public static RecipeDefinition ofIngredient(IngredientComponent component, - List> ingredient, - IMixedIngredients output) { - List>> ingredients = Lists.newArrayList(); - ingredients.add(ingredient); - return ofIngredients(component, ingredients, output); - } - - @Override - public int compareTo(IRecipeDefinition that) { - // Compare output - int compOutput = this.getOutput().compareTo(that.getOutput()); - if (compOutput != 0) { - return compOutput; - } - - // Compare input components - int compComp = MixedIngredients.compareCollection(this.getInputComponents(), that.getInputComponents()); - if (compComp != 0) { - return compComp; - } - - // Compare input instances - for (IngredientComponent component : getInputComponents()) { - List> thisInputs = this.getInputs(component); - List> thatInputs = that.getInputs(component); - - if (thisInputs.size() != thatInputs.size()) { - return thisInputs.size() - thatInputs.size(); - } - - Object[] aArray = thisInputs.toArray(); - Object[] bArray = thatInputs.toArray(); - for (int i = 0; i < aArray.length; i++) { - int compCol = MixedIngredients.compareCollection( - ((IPrototypedIngredientAlternatives) aArray[i]).getAlternatives(), - ((IPrototypedIngredientAlternatives) bArray[i]).getAlternatives() - ); - if (compCol != 0) { - return compCol; - } - } - } - - return 0; - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientMatcher.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientMatcher.java deleted file mode 100644 index 513739c..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientMatcher.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import java.util.Comparator; - -/** - * An instance matcher for certain instance and condition types. - * @param The instance type to match. - * @param The matching condition parameter. - * @author rubensworks - */ -public interface IIngredientMatcher extends Comparator { - - /** - * If the given object is an instance of the ingredient type. - * @param object An object. - * @return If the object is a valid instance of the ingredient component type. - */ - public boolean isInstance(Object object); - - /** - * @return The match condition that is used to match any instance based on a prototype. - */ - public M getAnyMatchCondition(); - - /** - * @return The match condition that is used to match instances exactly based on a prototype. - */ - public M getExactMatchCondition(); - - /** - * @return The match condition that is used to match instances exactly based on a prototype, - * excluding the quantity. - */ - public M getExactMatchNoQuantityCondition(); - - /** - * Create a new match condition based on the given condition that includes the second condition. - * @param matchCondition The match condition to start from. - * @param with The match condition to include. - * @return A new match condition that is the combination of both. - */ - public M withCondition(M matchCondition, M with); - - /** - * Create a new match condition based on the given condition that excludes the second condition. - * @param matchCondition The match condition to start from. - * @param without A match condition to exclude. - * @return A new match condition that is the first one without the second one. - */ - public M withoutCondition(M matchCondition, M without); - - /** - * Check if the given match condition contains at least the given condition. - * @param matchCondition The match condition to start from. - * @param searchCondition A match condition to search for. - * @return If the first condition contains at least the second condition. - */ - public boolean hasCondition(M matchCondition, M searchCondition); - - /** - * Check if the two given instances match based on the given match conditions. - * @param a A first instance. - * @param b A second instance. - * @param matchCondition A condition under which the matching should be done. - * @return If the two given instances match under the given conditions. - */ - public boolean matches(T a, T b, M matchCondition); - - /** - * Check if the two given instances are equal. - * @param a A first instance. - * @param b A second instance. - * @return If the two given instances are equal. - */ - public default boolean matchesExactly(T a, T b) { - return matches(a, b, getExactMatchCondition()); - } - - /** - * @return The instance that acts as an 'empty' instance. - * For ItemStacks, this would be ItemStack.EMPTY. - */ - public T getEmptyInstance(); - - /** - * Check if the given entity matches the empty instance, - * as provided by {@link #getEmptyInstance()}. - * @param instance An instance. - * @return If the instance is empty. - */ - public default boolean isEmpty(T instance) { - return instance == getEmptyInstance(); - } - - /** - * Hash the given instance. - * This must be calculated quickly. - * @param instance An instance. - * @return A hashcode for the given instance. - */ - public int hash(T instance); - - /** - * Create a deep copy of the given instance. - * @param instance An instance. - * @return A copy of the given instance. - */ - public T copy(T instance); - - /** - * Get the quantity in the given instance. - * @param instance An instance. - * @return The instance quantity. - */ - public long getQuantity(T instance); - - /** - * Create a copy of the given instance with the given quantity. - * @param instance An instance. - * @param quantity The new instance quantity. - * @return The copied instance with the new quantity. - * @throws ArithmeticException If the given quantity does not fit into the instance anymore. - */ - public T withQuantity(T instance, long quantity) throws ArithmeticException; - - /** - * @return The maximum allowed quantity for instances. - */ - public long getMaximumQuantity(); - - /** - * Compare two conditions with each other. - * @param a A first condition. - * @param b A second condition. - * @return The comparison result. - */ - public int conditionCompare(M a, M b); - - /** - * Return the localized name of the given instance. - * This should not include the instance quantity. - * @param instance An instance. - * @return The localized name of the given instance. - */ - public String localize(T instance); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientSerializer.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientSerializer.java deleted file mode 100644 index d28769e..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IIngredientSerializer.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import net.minecraft.nbt.NBTBase; - -/** - * An serializer for instances and condition parameters of a certain component type. - * @param The instance type to match. - * @param The matching condition parameter. - * @author rubensworks - */ -public interface IIngredientSerializer { - - /** - * Serialize an instance to NBT. - * @param instance An instance. - * @return An NBT tag. - */ - public NBTBase serializeInstance(T instance); - - /** - * Deserialize an instance from NBT. - * @param tag An NBT tag. - * @return An instance. - * @throws IllegalArgumentException If the given tag is invalid or does not contain data on the given instance. - */ - public T deserializeInstance(NBTBase tag) throws IllegalArgumentException; - - /** - * Serialize a match condition to NBT. - * @param matchCondition A match condition. - * @return An NBT tag. - */ - public NBTBase serializeCondition(M matchCondition); - - /** - * Deserialize a match condition from NBT. - * @param tag An NBT tag. - * @return A match condition. - * @throws IllegalArgumentException If the given tag is invalid or does not contain data on the given match condition. - */ - public M deserializeCondition(NBTBase tag) throws IllegalArgumentException; - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IMixedIngredients.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IMixedIngredients.java deleted file mode 100644 index 1a2e422..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IMixedIngredients.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ResourceLocation; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * A collection of ingredient instances of different types. - * @author rubensworks - */ -public interface IMixedIngredients extends Comparable { - - /** - * @return The ingredient component types. - */ - public Set> getComponents(); - - /** - * Get the instances of a certain type. - * @param ingredientComponent An ingredient component type. - * @param The instance type. - * @return Instances. - */ - public List getInstances(IngredientComponent ingredientComponent); - - /** - * Get the first non-empty instance of the given type. - * @param ingredientComponent An ingredient component type. - * @param The instance type. - * @return The first non-empty instance, or the empty instance if none could be found. - */ - public default T getFirstNonEmpty(IngredientComponent ingredientComponent) { - IIngredientMatcher matcher = ingredientComponent.getMatcher(); - for (T instance : getInstances(ingredientComponent)) { - if (!matcher.isEmpty(instance)) { - return instance; - } - } - return matcher.getEmptyInstance(); - } - - /** - * Check if at least all ingredients from the supplied mixed ingredients are contained in this mixed ingredients. - * This mixed ingredients could contain more ingredients. - * @param that The ingredients to look for. - * @return If at least all ingredients in that are contained in this. - */ - public default boolean containsAll(IMixedIngredients that) { - if (!this.getComponents().containsAll(that.getComponents())) { - return false; - } - - for (IngredientComponent component : that.getComponents()) { - List thisInstances = Lists.newArrayList(this.getInstances(component)); - List thatInstances = that.getInstances(component); - IIngredientMatcher matcher = component.getMatcher(); - - for (Object thatInstance : thatInstances) { - boolean found = false; - Iterator it = thisInstances.iterator(); - while (it.hasNext() && !found) { - if (matcher.matchesExactly(thatInstance, it.next())) { - found = true; - it.remove(); - } - } - - if (!found) { - return false; - } - } - } - - return true; - } - - /** - * @return If at least one non-empty ingredient is present. - */ - public default boolean isEmpty() { - for (IngredientComponent component : getComponents()) { - IIngredientMatcher matcher = component.getMatcher(); - for (Object instance : getInstances(component)) { - if (!matcher.isEmpty(instance)) { - return false; - } - } - } - return true; - } - - /** - * Deserialize ingredients to NBT. - * @param ingredients Ingredients. - * @return An NBT representation of the given ingredients. - */ - public static NBTTagCompound serialize(IMixedIngredients ingredients) { - NBTTagCompound tag = new NBTTagCompound(); - for (IngredientComponent component : ingredients.getComponents()) { - NBTTagList instances = new NBTTagList(); - IIngredientSerializer serializer = component.getSerializer(); - for (Object instance : ingredients.getInstances(component)) { - instances.appendTag(serializer.serializeInstance(instance)); - } - tag.setTag(component.getRegistryName().toString(), instances); - } - return tag; - } - - /** - * Deserialize ingredients from NBT - * @param tag An NBT tag. - * @return A new mixed ingredients instance. - * @throws IllegalArgumentException If the given tag is invalid or does not contain data on the given ingredients. - */ - public static MixedIngredients deserialize(NBTTagCompound tag) throws IllegalArgumentException { - Map, List> ingredients = Maps.newIdentityHashMap(); - for (String componentName : tag.getKeySet()) { - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); - if (component == null) { - throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); - } - NBTBase subTag = tag.getTag(componentName); - if (!(subTag instanceof NBTTagList)) { - throw new IllegalArgumentException("The ingredient component type " + componentName + " did not contain a valid list of instances"); - } - NBTTagList instancesTag = (NBTTagList) subTag; - IIngredientSerializer serializer = component.getSerializer(); - List instances = Lists.newArrayList(); - for (NBTBase instanceTag : instancesTag) { - instances.add(serializer.deserializeInstance(instanceTag)); - } - ingredients.put(component, instances); - } - return new MixedIngredients(ingredients); - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IPrototypedIngredient.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IPrototypedIngredient.java deleted file mode 100644 index fad6730..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IPrototypedIngredient.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.util.Constants; - -/** - * An ingredient that is identified by a given instance and can be matched with other instances under a given condition. - * - * Implementing classes should properly implement the equals and hashCode methods. - * - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @author rubensworks - */ -public interface IPrototypedIngredient extends Comparable> { - - /** - * @return The type of ingredient component this prototype exists for. - */ - public IngredientComponent getComponent(); - - /** - * @return The prototype of this ingredient. - */ - public T getPrototype(); - - /** - * @return The condition under which the prototype instance can be matched. - */ - public M getCondition(); - - /** - * Deserialize an ingredient to NBT. - * @param prototypedIngredient Ingredient. - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @return An NBT representation of the given ingredient. - */ - public static NBTTagCompound serialize(IPrototypedIngredient prototypedIngredient) { - NBTTagCompound tag = new NBTTagCompound(); - - IngredientComponent component = prototypedIngredient.getComponent(); - tag.setString("ingredientComponent", component.getName().toString()); - - IIngredientSerializer serializer = component.getSerializer(); - tag.setTag("prototype", serializer.serializeInstance(prototypedIngredient.getPrototype())); - tag.setTag("condition", serializer.serializeCondition(prototypedIngredient.getCondition())); - - return tag; - } - - /** - * Deserialize an ingredient from NBT - * @param tag An NBT tag. - * @return A new ingredient instance. - * @throws IllegalArgumentException If the given tag is invalid or does not contain data on the given ingredient. - */ - public static PrototypedIngredient deserialize(NBTTagCompound tag) throws IllegalArgumentException { - if (!tag.hasKey("ingredientComponent", Constants.NBT.TAG_STRING)) { - throw new IllegalArgumentException("Could not find a ingredientComponent entry in the given tag"); - } - if (!tag.hasKey("prototype")) { - throw new IllegalArgumentException("Could not find a prototype entry in the given tag"); - } - if (!tag.hasKey("condition")) { - throw new IllegalArgumentException("Could not find a condition entry in the given tag"); - } - - String componentName = tag.getString("ingredientComponent"); - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); - if (component == null) { - throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); - } - - IIngredientSerializer serializer = component.getSerializer(); - Object prototype = serializer.deserializeInstance(tag.getTag("prototype")); - Object condition = serializer.deserializeCondition(tag.getTag("condition")); - - return new PrototypedIngredient(component, prototype, condition); -} - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponent.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponent.java deleted file mode 100644 index 5a1c0ad..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponent.java +++ /dev/null @@ -1,303 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityDispatcher; -import net.minecraftforge.common.capabilities.CapabilityInject; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.IForgeRegistryEntry; -import net.minecraftforge.registries.RegistryBuilder; -import org.cyclops.commoncapabilities.api.ingredient.capability.AttachCapabilitiesEventIngredientComponent; -import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage; -import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageHandler; -import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageWrapperHandler; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * A IngredientComponent is a type of component that can be used as ingredients inside recipes. - * - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - * @author rubensworks - */ -@Mod.EventBusSubscriber -public final class IngredientComponent implements IForgeRegistryEntry>, - Comparable> { - - public static IForgeRegistry> REGISTRY; - - @SubscribeEvent - public static void onRegistriesCreate(RegistryEvent.NewRegistry event) { - REGISTRY = new RegistryBuilder>() - .setName(new ResourceLocation("commoncapabilities", "registry:ingredientcomponents")) - .setType((Class>) (Class) IngredientComponent.class) - .create(); - } - - @GameRegistry.ObjectHolder("minecraft:itemstack") - public static final IngredientComponent ITEMSTACK = null; - @GameRegistry.ObjectHolder("minecraft:fluidstack") - public static final IngredientComponent FLUIDSTACK = null; - @GameRegistry.ObjectHolder("minecraft:energy") - public static final IngredientComponent ENERGY = null; - - @CapabilityInject(IIngredientComponentStorageHandler.class) - private static Capability CAPABILITY_INGREDIENT_COMPONENT_STORAGE_HANDLER = null; - - private static Map, IngredientComponent> STORAGE_WRAPPER_CAPABILITIES_COMPONENTS = Maps.newIdentityHashMap(); - - private final IIngredientMatcher matcher; - private final IIngredientSerializer serializer; - private final List> categoryTypes; - private final List> storageWrapperCapabilities; - private final Map, IIngredientComponentStorageWrapperHandler> storageWrapperHandler; - private final IngredientComponentCategoryType primaryQuantifier; - private final CapabilityDispatcher capabilityDispatcher; - private ResourceLocation name; - private String translationKey; - - public IngredientComponent(ResourceLocation name, IIngredientMatcher matcher, - IIngredientSerializer serializer, - List> categoryTypes) { - this.setRegistryName(name); - this.matcher = matcher; - this.serializer = serializer; - this.categoryTypes = Lists.newArrayList(categoryTypes); - this.storageWrapperCapabilities = Lists.newArrayList(); - this.storageWrapperHandler = Maps.newIdentityHashMap(); - this.capabilityDispatcher = gatherCapabilities(); - - // Validate if the combination of all match conditions equals the exact match condition. - M matchCondition = this.matcher.getAnyMatchCondition(); - IngredientComponentCategoryType primaryQuantifier = null; - for (IngredientComponentCategoryType categoryType : this.categoryTypes) { - matchCondition = this.matcher.withCondition(matchCondition, categoryType.getMatchCondition()); - if (categoryType.isPrimaryQuantifier()) { - if (primaryQuantifier != null) { - throw new IllegalArgumentException("Found more than one primary quantifier in category types."); - } - primaryQuantifier = categoryType; - } - } - this.primaryQuantifier = primaryQuantifier; - if (!Objects.equals(matchCondition, this.getMatcher().getExactMatchCondition())) { - throw new IllegalArgumentException("The given category types when combined do not conform to the " + - "exact match conditions of the matcher."); - } - } - - public IngredientComponent(String name, IIngredientMatcher matcher, IIngredientSerializer serializer, - List> categoryTypes) { - this(new ResourceLocation(name), matcher, serializer, categoryTypes); - gatherCapabilities(); - } - - public ResourceLocation getName() { - return name; - } - - @Override - public String toString() { - return "[IngredientComponent " + this.name + " " + hashCode() + "]"; - } - - @Override - public IngredientComponent setRegistryName(ResourceLocation name) { - this.name = name; - return this; - } - - @Nullable - @Override - public ResourceLocation getRegistryName() { - return this.name; - } - - @Override - public Class> getRegistryType() { - return (Class) IngredientComponent.class; - } - - protected CapabilityDispatcher gatherCapabilities() { - AttachCapabilitiesEventIngredientComponent event = new AttachCapabilitiesEventIngredientComponent<>(this); - MinecraftForge.EVENT_BUS.post(event); - return event.getCapabilities().size() > 0 ? new CapabilityDispatcher(event.getCapabilities()) : null; - } - - /** - * If this component has the given capability. - * @param capability The capability to check. - * @return If this has the given capability/ - */ - public boolean hasCapability(Capability capability) { - return capabilityDispatcher != null && capabilityDispatcher.hasCapability(capability, null); - } - - /** - * Get the given capability. - * @param capability The capability to get. - * @param The capability type. - * @return The capability instance. - */ - public TC getCapability(Capability capability) { - return capabilityDispatcher == null ? null : capabilityDispatcher.getCapability(capability, null); - } - - public IngredientComponent setTranslationKey(String translationKey) { - this.translationKey = translationKey; - return this; - } - - /** - * @return The unlocalized name. - */ - public String getTranslationKey() { - return translationKey; - } - - /** - * @return A matcher instance for comparing instances of this component type. - */ - public IIngredientMatcher getMatcher() { - return matcher; - } - - /** - * @return A (de)serializer instance for this component type. - */ - public IIngredientSerializer getSerializer() { - return serializer; - } - - /** - * @return The category types of this component. - */ - public List> getCategoryTypes() { - return categoryTypes; - } - - /** - * Wrap the given instance inside an equals, hashCode and compareTo-safe holder. - * @param instance An instance. - * @return The wrapped instance. - */ - public IngredientInstanceWrapper wrap(T instance) { - return new IngredientInstanceWrapper<>(this, instance); - } - - /** - * @return The primary quantifier category type, can be null. - */ - @Nullable - public IngredientComponentCategoryType getPrimaryQuantifier() { - return primaryQuantifier; - } - - /** - * Set the storage wrapper handler for this component. - * @param capability The capability for the storage wrapper. - * @param storageWrapperHandler The storage wrapper handler. - * @param The capability type. - */ - public void setStorageWrapperHandler(Capability capability, - IIngredientComponentStorageWrapperHandler storageWrapperHandler) { - if (capability != null && this.storageWrapperHandler.put(capability, storageWrapperHandler) == null) { - this.storageWrapperCapabilities.add(capability); - IngredientComponent previousValue = IngredientComponent.STORAGE_WRAPPER_CAPABILITIES_COMPONENTS.put(capability, this); - if (previousValue != null) { - throw new IllegalStateException(String.format( - "Tried registering a storage capability (%s) for %s that was already registered to %s", - capability.getName(), this, previousValue)); - } - } - } - - /** - * Get the storage wrapper handler for this component. - * @param capability The capability to get the storage wrapper for. - * @param The external storage type. - * @return The storage wrapper handler, can be null if none has been assigned. - */ - @SuppressWarnings("unchecked") - @Nullable - public IIngredientComponentStorageWrapperHandler getStorageWrapperHandler(Capability capability) { - return (IIngredientComponentStorageWrapperHandler) storageWrapperHandler.get(capability); - } - - /** - * @return All supported capabilities that have registered wrapper handlers - */ - public Collection> getStorageWrapperHandlerCapabilities() { - return this.storageWrapperCapabilities; - } - - /** - * Get the ingredient component that was attached to the given storage capability. - * @param capability A storage capability. - * @return The attached ingredient component, or null. - */ - @Nullable - public static IngredientComponent getIngredientComponentForStorageCapability(Capability capability) { - return IngredientComponent.STORAGE_WRAPPER_CAPABILITIES_COMPONENTS.get(capability); - } - - /** - * Get the ingredient storage within the given capability provider. - * - * This will first check if the capability provider has a {@link IIngredientComponentStorageHandler} capability - * and it will try to fetch the storage from there. - * If this fails, then the storage wrapper handlers that are registered in this ingredient component - * will be iterated and the first successful one will be returned. - * - * @param capabilityProvider A capability provider. - * @param facing The side to get the storage from. - * @return An ingredient storage, or null if it does not exist. - */ - @SuppressWarnings("unchecked") - @Nullable - public IIngredientComponentStorage getStorage(ICapabilityProvider capabilityProvider, - @Nullable EnumFacing facing) { - // Check IIngredientComponentStorageHandler capability - if (capabilityProvider.hasCapability(CAPABILITY_INGREDIENT_COMPONENT_STORAGE_HANDLER, facing)) { - IIngredientComponentStorageHandler storageHandler = capabilityProvider.getCapability( - CAPABILITY_INGREDIENT_COMPONENT_STORAGE_HANDLER, facing); - IIngredientComponentStorage storage = storageHandler.getStorage(this); - if (storage != null) { - return storage; - } - } - - // Check registered wrapper handlers - for (Capability capability : getStorageWrapperHandlerCapabilities()) { - IIngredientComponentStorageWrapperHandler wrapperHandler = getStorageWrapperHandler(capability); - IIngredientComponentStorage storage = wrapperHandler.getComponentStorage(capabilityProvider, facing); - if (storage != null) { - return storage; - } - } - - // Otherwise, fail - return null; - } - - @Override - public int compareTo(IngredientComponent that) { - return this.getName().compareTo(that.getName()); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponentCategoryType.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponentCategoryType.java deleted file mode 100644 index 375ea39..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientComponentCategoryType.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import net.minecraft.util.ResourceLocation; - -import java.util.function.Function; - -/** - * A categorizer for an instance type. - * @param An instance type. - * @param A category type. - * @param A classifier type. - * @author rubensworks - */ -public class IngredientComponentCategoryType { - - private final ResourceLocation name; - private final Class categoryType; - private final boolean referenceEqual; - private final Function classifier; - private final M matchCondition; - private final boolean primaryQuantifier; - - public IngredientComponentCategoryType(ResourceLocation name, Class categoryType, boolean referenceEqual, - Function classifier, M matchCondition, boolean primaryQuantifier) { - this.name = name; - this.categoryType = categoryType; - this.referenceEqual = referenceEqual; - this.classifier = classifier; - this.matchCondition = matchCondition; - this.primaryQuantifier = primaryQuantifier; - } - - /** - * @return The name of this category. - */ - public ResourceLocation getName() { - return name; - } - - /** - * @return The category class. - */ - public Class getCategoryType() { - return categoryType; - } - - /** - * @return If elements of the given category type can be compared using reference-equality. - * This should be set to true where possible, as it will lead to better performance. - */ - public boolean isReferenceEqual() { - return referenceEqual; - } - - /** - * @return A classifier function that will map an instance to a category of the given type. - */ - public Function getClassifier() { - return classifier; - } - - /** - * @return The match condition that identifies exactly this this category type. - */ - public M getMatchCondition() { - return matchCondition; - } - - /** - * @return If this categorizer is indicative of instance quantities. - */ - public boolean isPrimaryQuantifier() { - return primaryQuantifier; - } - - @Override - public String toString() { - return "[IngredientComponentCategoryType " + this.name + "]"; - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientInstanceWrapper.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientInstanceWrapper.java deleted file mode 100644 index 63a5cd0..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/IngredientInstanceWrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -/** - * A wrapper around an ingredient component instance that properly implements the - * {@link #equals(Object)}, {@link #hashCode()} and {@link #compareTo(Object)} methods. - * @author rubensworks - */ -public class IngredientInstanceWrapper implements Comparable> { - - private final IngredientComponent component; - private final T instance; - - public IngredientInstanceWrapper(IngredientComponent component, T instance) { - this.component = component; - this.instance = instance; - } - - public IngredientComponent getComponent() { - return component; - } - - public T getInstance() { - return instance; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IngredientInstanceWrapper)) { - return false; - } - IngredientInstanceWrapper wrapper = (IngredientInstanceWrapper) obj; - if (wrapper.getComponent() != this.getComponent()) { - return false; - } - Object thatInstance = wrapper.getInstance(); - IIngredientMatcher matcher = getComponent().getMatcher(); - return matcher.isInstance(thatInstance) && matcher.matchesExactly(getInstance(), (T) thatInstance); - } - - @Override - public int hashCode() { - return getComponent().getMatcher().hash(getInstance()); - } - - @Override - public int compareTo(IngredientInstanceWrapper o) { - return getComponent().getMatcher().compare(getInstance(), o.getInstance()); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredients.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredients.java deleted file mode 100644 index b6d54e1..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredients.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Raw implementation of mixed ingredients. - * @author rubensworks - */ -public class MixedIngredients extends MixedIngredientsAdapter { - - private final Map, List> ingredients; - - public MixedIngredients(Map, List> ingredients) { - this.ingredients = ingredients; - - // Ensure that the lists are non-empty - for (Map.Entry, List> entry : this.ingredients.entrySet()) { - if (entry.getValue().isEmpty()) { - throw new IllegalArgumentException(String.format("Invalid MixedIngredients input, empty list for %s", - entry.getKey().getName())); - } - } - } - - @Override - public Set> getComponents() { - return ingredients.keySet(); - } - - @Override - public List getInstances(IngredientComponent ingredientComponent) { - return (List) ingredients.getOrDefault(ingredientComponent, Collections.emptyList()); - } - - public static MixedIngredients ofInstances(IngredientComponent component, Collection instances) { - Map, List> ingredients = Maps.newIdentityHashMap(); - ingredients.put(component, instances instanceof ArrayList ? (List) instances : Lists.newArrayList(instances)); - return new MixedIngredients(ingredients); - } - - /** - * Create a new ingredients for a single instance. - * @param component A component type. - * @param instance An instance. - * @param The instance type. - * @return New ingredients. - */ - public static MixedIngredients ofInstance(IngredientComponent component, T instance) { - return ofInstances(component, Lists.newArrayList(instance)); - } - - /** - * Create ingredients from the given recipe's input. - * This will create the ingredients based on the first prototype of the recipe's inputs. - * @param recipe A recipe. - * @return New ingredients. - */ - public static MixedIngredients fromRecipeInput(IRecipeDefinition recipe) { - Map, List> ingredients = Maps.newIdentityHashMap(); - for (IngredientComponent component : recipe.getInputComponents()) { - IIngredientMatcher matcher = component.getMatcher(); - List instances = recipe.getInputs(component).stream() - .map(ingredient -> { - IPrototypedIngredient firstIngredient = Iterables.getFirst(ingredient.getAlternatives(), null); - if (firstIngredient == null) { - return matcher.getEmptyInstance(); - } - return firstIngredient.getPrototype(); - }) - .collect(Collectors.toList()); - ingredients.put(component, instances); - } - return new MixedIngredients(ingredients); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredientsAdapter.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredientsAdapter.java deleted file mode 100644 index 4d086b0..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/MixedIngredientsAdapter.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import com.google.common.collect.Sets; - -import java.util.Collection; -import java.util.Comparator; -import java.util.List; - -/** - * Abstract implementation of mixed ingredients. - * @author rubensworks - */ -public abstract class MixedIngredientsAdapter implements IMixedIngredients { - - @Override - public boolean equals(Object obj) { - if (obj instanceof IMixedIngredients) { - IMixedIngredients that = (IMixedIngredients) obj; - if (Sets.newHashSet(this.getComponents()).equals(Sets.newHashSet(that.getComponents()))) { - for (IngredientComponent component : getComponents()) { - List thisInstances = this.getInstances(component); - List thatInstances = that.getInstances(component); - IIngredientMatcher matcher = component.getMatcher(); - if (thisInstances.size() == thatInstances.size()) { - for (int i = 0; i < thisInstances.size(); i++) { - if (!matcher.matchesExactly(thisInstances.get(i), thatInstances.get(i))) { - return false; - } - } - } else { - return false; - } - } - return true; - } - } - return false; - } - - @Override - public int hashCode() { - int hash = 902; - for (IngredientComponent component : getComponents()) { - hash |= component.hashCode() << 2; - IIngredientMatcher matcher = component.getMatcher(); - for (Object instance : getInstances(component)) { - hash |= matcher.hash(instance); - } - } - return hash; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (IngredientComponent component : getComponents()) { - sb.append('{'); - sb.append(component); - sb.append(':'); - sb.append(getInstances(component)); - sb.append('}'); - } - return "[MixedIngredients ingredients: " + sb + "]"; - } - - @Override - public int compareTo(IMixedIngredients that) { - // Compare input components - int compComp = MixedIngredientsAdapter.compareCollection(this.getComponents(), that.getComponents()); - if (compComp != 0) { - return compComp; - } - - // Compare instances - for (IngredientComponent component : getComponents()) { - int compInstance = MixedIngredientsAdapter.compareCollection( - this.getInstances(component), that.getInstances(component), component.getMatcher()); - if (compInstance != 0) { - return compInstance; - } - } - - return 0; - } - - /** - * Compare two collections with comparable elements. - * @param a A first collection. - * @param b A second collection. - * @param The type of the elements. - * @return The comparator value. - */ - public static > int compareCollection(Collection a, Collection b) { - if (a.size() != b.size()) { - return a.size() - b.size(); - } - - Object[] aArray = a.toArray(); - Object[] bArray = b.toArray(); - for (int i = 0; i < aArray.length; i++) { - int compComp = ((T) aArray[i]).compareTo((T) bArray[i]); - if (compComp != 0) { - return compComp; - } - } - return 0; - } - - /** - * Compare two collections with a custom comparator. - * @param a A first collection. - * @param b A second collection. - * @param comparator The element comparator. - * @param The type of the elements. - * @return The comparator value. - */ - public static int compareCollection(Collection a, Collection b, - Comparator comparator) { - if (a.size() != b.size()) { - return a.size() - b.size(); - } - - Object[] aArray = a.toArray(); - Object[] bArray = b.toArray(); - for (int i = 0; i < aArray.length; i++) { - int compComp = comparator.compare((T) aArray[i], (T) bArray[i]); - if (compComp != 0) { - return compComp; - } - } - return 0; - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/PrototypedIngredient.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/PrototypedIngredient.java deleted file mode 100644 index 7ebd99e..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/PrototypedIngredient.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient; - -import java.util.Objects; - -/** - * A raw prototyped ingredient. - * - * @param The instance type. - * @param The matching condition parameter, may be Void. - * @author rubensworks - */ -public class PrototypedIngredient implements IPrototypedIngredient { - - private final IngredientComponent ingredientComponent; - private final T prototype; - private final M condition; - - public PrototypedIngredient(IngredientComponent ingredientComponent, T prototype, M condition) { - this.ingredientComponent = ingredientComponent; - this.prototype = prototype; - this.condition = condition; - } - - @Override - public IngredientComponent getComponent() { - return ingredientComponent; - } - - @Override - public T getPrototype() { - return prototype; - } - - @Override - public M getCondition() { - return condition; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof IPrototypedIngredient) { - IPrototypedIngredient that = (IPrototypedIngredient) obj; - return this.getComponent().equals(that.getComponent()) - && this.getComponent().getMatcher().matchesExactly(this.getPrototype(), (T) that.getPrototype()) - && Objects.equals(this.getCondition(), that.getCondition()); - } - return false; - } - - @Override - public int hashCode() { - return 394 | this.getComponent().hashCode() << 4 - | this.getComponent().getMatcher().hash(this.getPrototype()) << 2 - | this.getCondition().hashCode(); - } - - @Override - public String toString() { - return "[PrototypedIngredient ingredientComponent: " + ingredientComponent.toString() - + "; prototype: " + Objects.toString(prototype) - + "; condition: " + Objects.toString(condition) - + "]"; - } - - @Override - public int compareTo(IPrototypedIngredient that) { - int compComp = this.getComponent().compareTo(that.getComponent()); - if (compComp != 0) { - return compComp; - } - - IIngredientMatcher matcher = this.getComponent().getMatcher(); - int compProt = matcher.compare(this.getPrototype(), (T) that.getPrototype()); - if (compProt != 0) { - return compProt; - } - - return matcher.conditionCompare(this.getCondition(), (M) that.getCondition()); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/AttachCapabilitiesEventIngredientComponent.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/AttachCapabilitiesEventIngredientComponent.java deleted file mode 100644 index 14e3b4a..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/AttachCapabilitiesEventIngredientComponent.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.capability; - -import net.minecraftforge.event.AttachCapabilitiesEvent; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -/** - * Event for when an {@link IngredientComponent} is being constructed. - * @param The instance type. - * @param The matching condition parameter. - * @author rubensworks - */ -public class AttachCapabilitiesEventIngredientComponent extends AttachCapabilitiesEvent> { - - public AttachCapabilitiesEventIngredientComponent(IngredientComponent ingredientComponent) { - super((Class>) (Class) IngredientComponent.class, ingredientComponent); - } - - public IngredientComponent getIngredientComponent() { - return getObject(); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IIngredientComponentCapabilityAttacher.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IIngredientComponentCapabilityAttacher.java deleted file mode 100644 index 1e3d1de..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IIngredientComponentCapabilityAttacher.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.capability; - -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -/** - * Instances of this interfaces can be used to attach a {@link ICapabilityProvider} - * to instances of {@link IngredientComponent} that are selected by name. - * @param The instance type. - * @param The matching condition parameter. - * @author rubensworks - */ -public interface IIngredientComponentCapabilityAttacher { - - /** - * @return The unique name of the capability to attach to. - */ - public ResourceLocation getTargetName(); - - /** - * @return An internally unique name for the capability provider that will be attached. - */ - public ResourceLocation getCapabilityProviderName(); - - /** - * Create a capability provider for the given ingredient component instance. - * @param ingredientComponent An ingredient component. - * @return A capability provider instance. - */ - public ICapabilityProvider createCapabilityProvider(IngredientComponent ingredientComponent); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherAdapter.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherAdapter.java deleted file mode 100644 index d8b0ee1..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherAdapter.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.capability; - -import net.minecraft.util.ResourceLocation; - -/** - * A base implementation of {@link IIngredientComponentCapabilityAttacher}. - * @author rubensworks - */ -public abstract class IngredientComponentCapabilityAttacherAdapter implements IIngredientComponentCapabilityAttacher { - - private final ResourceLocation targetName; - private final ResourceLocation capabilityProviderName; - - public IngredientComponentCapabilityAttacherAdapter(ResourceLocation targetName, ResourceLocation capabilityProviderName) { - this.targetName = targetName; - this.capabilityProviderName = capabilityProviderName; - } - - @Override - public ResourceLocation getTargetName() { - return this.targetName; - } - - @Override - public ResourceLocation getCapabilityProviderName() { - return this.capabilityProviderName; - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherManager.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherManager.java deleted file mode 100644 index 82a4ba1..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/capability/IngredientComponentCapabilityAttacherManager.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.capability; - -import com.google.common.collect.Multimap; -import com.google.common.collect.MultimapBuilder; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -/** - * A helper manager that can be used to easily attach capabilities to ingredient components. - * This manager must be instantiated during mod initialization, - * and instances of {@link IIngredientComponentCapabilityAttacher} can be registered to it. - * - * When the ingredient components are being registered later on, - * this manager will ensure that the registered attachers are called, - * and that their capabilities are attached. - * - * @author rubensworks - */ -public class IngredientComponentCapabilityAttacherManager { - - private final Multimap> attachers; - - public IngredientComponentCapabilityAttacherManager() { - this.attachers = MultimapBuilder.hashKeys().arrayListValues().build(); - MinecraftForge.EVENT_BUS.register(this); - } - - /** - * Register the given capability attacher. - * @param attacher A capability attacher that will be called when the corresponding capability is instantiated. - */ - public void addAttacher(IIngredientComponentCapabilityAttacher attacher) { - this.attachers.put(attacher.getTargetName(), attacher); - } - - @SubscribeEvent - public void onIngredientComponentsLoad(AttachCapabilitiesEventIngredientComponent event) { - onIngredientComponentLoad(event, event.getIngredientComponent()); - - } - - protected void onIngredientComponentLoad(AttachCapabilitiesEventIngredientComponent event, - IngredientComponent ingredientComponent) { - for (IIngredientComponentCapabilityAttacher attacher : attachers.get(ingredientComponent.getName())) { - event.addCapability(attacher.getCapabilityProviderName(), ((IIngredientComponentCapabilityAttacher) attacher) - .createCapabilityProvider(ingredientComponent)); - } - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/DefaultIngredientComponentStorageHandler.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/DefaultIngredientComponentStorageHandler.java deleted file mode 100644 index 5c51ea3..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/DefaultIngredientComponentStorageHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import com.google.common.collect.Maps; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; - -/** - * Default implementation of {@link IIngredientComponentStorageHandler}. - * @author rubensworks - */ -public class DefaultIngredientComponentStorageHandler implements IIngredientComponentStorageHandler { - - private final Map, IIngredientComponentStorage> storages; - - public DefaultIngredientComponentStorageHandler() { - this.storages = Maps.newIdentityHashMap(); - } - - @Override - public Collection> getComponents() { - return storages.keySet(); - } - - @SuppressWarnings("unchecked") - @Nullable - @Override - public IIngredientComponentStorage getStorage(IngredientComponent ingredientComponent) { - return (IIngredientComponentStorage) storages.get(ingredientComponent); - } - - /** - * Set the storage for the given ingredient component. - * @param ingredientComponent The ingredient component. - * @param storage The ingredient component storage, or null if it should be removed. - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - */ - public void setStorage(IngredientComponent ingredientComponent, - @Nullable IIngredientComponentStorage storage) { - if (storage == null) { - storages.remove(ingredientComponent); - } else { - storages.put(ingredientComponent, storage); - } - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorage.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorage.java deleted file mode 100644 index fe3b912..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorage.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nonnull; -import java.util.Iterator; - -/** - * A minimal storage for a type of ingredient component. - * - * By not taking into account slots, the storage provider instead of the consumer - * is responsible for providing an efficient insertion and extraction algorithm. - * - * The is interface defines no requirements on how instances must be stored internally. - * For example, an implementing storage could combine internally several instances together - * that are equal to each other and take the sum of their quantities. - * - * Note: The storage provider MUST ensure deterministic behaviour for extraction and insertion. - * For example, the three first returned ingredients hereafter must equal each other. - *
- *          ingredient1 = insert(myIngredient, true);
- *          ingredient2 = insert(myIngredient, true);
- *          ingredient3 = insert(myIngredient, false);
- *          ingredient4 = insert(myIngredient, true); // Can be different again
- *       
- * The same applies to extraction. - * - * This should not be used as a capability, - * instead the {@link IIngredientComponentStorageHandler} capability should be used, - * as this can hold storage for different ingredient components. - * - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - * @author rubensworks - */ -public interface IIngredientComponentStorage extends Iterable { - - /** - * @return The ingredient component type this storage applies to. - */ - public IngredientComponent getComponent(); - - /** - * Get all ingredients in this storage. - * @return An iterator over all available ingredients in this storage. - */ - public Iterator iterator(); - - /** - * Find all ingredients matching the given prototype from the storage. - * - * Calling this method will not modify the storage in any way. - * Results from this method MUST NOT be modified. - * - * @param prototype The ingredient to search for. - * @param matchCondition The flags to compare the given prototype - * by according to {@link IngredientComponent#getMatcher()}. - * @return An iterator over ingredients that match the given prototype, which may potentially be empty. - */ - public Iterator iterator(@Nonnull T prototype, M matchCondition); - - /** - * @return The maximum allowed quantity over all instances. - */ - public long getMaxQuantity(); - - /** - * Inserts an ingredient into the storage and return the remainder. - * The ingredient should not be modified in this function! - * - * @param ingredient Ingredient to insert. - * @param simulate If true, the insertion is only simulated. - * @return The remaining ingredient that was not inserted (if the entire ingredient is accepted, - * then return {@link org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher#getEmptyInstance()}). - * May be the same as the input ingredient if unchanged, otherwise a new ingredient. - **/ - public T insert(@Nonnull T ingredient, boolean simulate); - - /** - * Extract an ingredient matching the given prototype from the storage. - * - * Note that only the extracted ingredient must match the prototype under the given condition. - * Internally, ingredients can be combined and matched in any way. - * For example, an exact match could be produced by combining several ingredients. - * - * If the primary quantifier (as identified by {@link IngredientComponent#getPrimaryQuantifier()}) - * IS NOT part of the match condition, then the quantity of the given prototype MUST be interpreted - * as the maximum quantity that must be extracted. - * - * If the primary quantifier (as identified by {@link IngredientComponent#getPrimaryQuantifier()}) - * IS part of the match condition, then the quantity of the given prototype MUST be interpreted - * as the exact quantity that must be extracted. - * If the storage has a HIGHER OR EQUAL available quantity, - * then the storage MUST allow the given quantity to be extracted. - * If the storage on the other hand has a LOWER available quantity, - * then extraction is not allowed. - * - * @param prototype The ingredient to search for. - * @param matchCondition The flags to compare the given prototype - * by according to {@link IngredientComponent#getMatcher()}. - * @param simulate If true, the insertion is only simulated - * @return Ingredient extracted from the slot, must be {@link org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher#getEmptyInstance()}, - * if nothing can be extracted - */ - public T extract(@Nonnull T prototype, M matchCondition, boolean simulate); - - /** - * Extract any ingredient, but the given maximum amount from the storage. - * - * @param maxQuantity The maximum amount to extract. - * @param simulate If true, the insertion is only simulated - * @return Ingredient extracted from the slot, must be {@link org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher#getEmptyInstance()}, - * if nothing can be extracted - */ - public T extract(long maxQuantity, boolean simulate); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageHandler.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageHandler.java deleted file mode 100644 index 185b4a2..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageHandler.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nullable; -import java.util.Collection; - -/** - * A capability that can hold ingredient component storages. - * - * A capability separate from {@link IIngredientComponentStorage} - * is needed because multiple storages could be exposed by a single capability provider. - * - * @author rubensworks - */ -public interface IIngredientComponentStorageHandler { - - /** - * @return The ingredient component types this handler holds. - */ - public Collection> getComponents(); - - /** - * Get the storage for the given ingredient component, - * @param ingredientComponent The ingredient component. - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - * @return The ingredient component storage, or null if it is not available. - */ - @Nullable - public IIngredientComponentStorage getStorage(IngredientComponent ingredientComponent); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageSlotted.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageSlotted.java deleted file mode 100644 index 1edb536..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageSlotted.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import javax.annotation.Nonnull; - -/** - * A minimal slot-based storage for a type of ingredient component. - * - * This is an extension of the slotless {@link IIngredientComponentStorage}. - * - * The is interface defines no requirements on how instances must be stored internally. - * For example, an implementing storage could combine internally several instances together - * that are equal to each other and take the sum of their quantities. - * - * This should not be used as a capability, - * instead the {@link IIngredientComponentStorageHandler} capability should be used, - * as this can hold storage for different ingredient components. - * - * @see IIngredientComponentStorage - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - * @author rubensworks - */ -public interface IIngredientComponentStorageSlotted extends IIngredientComponentStorage { - - /** - * @return The number of available slots. - **/ - public int getSlots(); - - /** - * Get the ingredient that is contained in the given slot. - * - * Note: The returned ingredient MUST NOT not be modified by the caller. - * - * @param slot A slot number. - * @return The contained ingredient. - */ - public T getSlotContents(int slot); - - /** - * Get the maximum allowed quantity in the given slot. - * @param slot A slot number. - * @return The maximum allowed in the given slot. - */ - public long getMaxQuantity(int slot); - - - /** - * Inserts an ingredient into the storage in the given slot and return the remainder. - * The ingredient should not be modified in this function! - * - * @param slot A slot number to insert to. - * @param ingredient Ingredient to insert. - * @param simulate If true, the insertion is only simulated. - * @return The remaining ingredient that was not inserted (if the entire ingredient is accepted, - * then return {@link org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher#getEmptyInstance()}). - * May be the same as the input ingredient if unchanged, otherwise a new ingredient. - **/ - public T insert(int slot, @Nonnull T ingredient, boolean simulate); - - /** - * Extract the at most the given quantity from the ingredient from the given slot in the storage. - * - * @param slot A slot number to extract from. - * @param maxQuantity The maximum amount to extract. - * @param simulate If true, the insertion is only simulated - * @return Ingredient extracted from the slot, must be {@link org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher#getEmptyInstance()}, - * if nothing can be extracted - */ - public T extract(int slot, long maxQuantity, boolean simulate); - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageWrapperHandler.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageWrapperHandler.java deleted file mode 100644 index 46badce..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IIngredientComponentStorageWrapperHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nullable; - -/** - * A handler for wrapping external storage interfaces into {@link IIngredientComponentStorage} - * and the other way ({@link IIngredientComponentStorage} into external storage interfaces). - * - * @param The instance type. - * @param The matching condition parameter, may be Void. Instances MUST properly implement the equals method. - * @param The external storage type. - * @author rubensworks - */ -public interface IIngredientComponentStorageWrapperHandler { - - /** - * @return The ingredient component. - */ - public IngredientComponent getComponent(); - - /** - * Wrap the given storage. - * @param storage The external storage to wrap. - * @return A component storage. - */ - public IIngredientComponentStorage wrapComponentStorage(S storage); - - /** - * Wrap the given storage. - * @param componentStorage The component storage to wrap. - * @return A component storage. - */ - public S wrapStorage(IIngredientComponentStorage componentStorage); - - /** - * Get the storage within the given capability provider. - * @param capabilityProvider A capability provider. - * @param facing The side to get the storage from. - * @return A storage, or null if it does not exist. - */ - @Nullable - public S getStorage(ICapabilityProvider capabilityProvider, @Nullable EnumFacing facing); - - /** - * Get the ingredient storage within the given capability provider. - * @param capabilityProvider A capability provider. - * @param facing The side to get the storage from. - * @return An ingredient storage, or null if it does not exist. - */ - public default IIngredientComponentStorage getComponentStorage(ICapabilityProvider capabilityProvider, - @Nullable EnumFacing facing) { - S storage = getStorage(capabilityProvider, facing); - return storage == null ? new IngredientComponentStorageEmpty<>(getComponent()) : wrapComponentStorage(storage); - } - -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageEmpty.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageEmpty.java deleted file mode 100644 index 9805a87..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageEmpty.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.Iterator; - -/** - * A dummy ingredient component storage that is empty. - * @author rubensworks - */ -public class IngredientComponentStorageEmpty implements IIngredientComponentStorage { - - private final IngredientComponent component; - - public IngredientComponentStorageEmpty(IngredientComponent component) { - this.component = component; - } - - @Override - public IngredientComponent getComponent() { - return component; - } - - @Override - public Iterator iterator() { - return Collections.emptyIterator(); - } - - @Override - public Iterator iterator(@Nonnull T prototype, M matchFlags) { - return Collections.emptyIterator(); - } - - @Override - public long getMaxQuantity() { - return 0; - } - - @Nonnull - @Override - public T insert(@Nonnull T ingredient, boolean simulate) { - return ingredient; - } - - @Nonnull - @Override - public T extract(@Nonnull T prototype, M matchFlags, boolean simulate) { - return getComponent().getMatcher().getEmptyInstance(); - } - - @Override - public T extract(long maxQuantity, boolean simulate) { - return getComponent().getMatcher().getEmptyInstance(); - } -} diff --git a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageSlottedEmpty.java b/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageSlottedEmpty.java deleted file mode 100644 index 8013f45..0000000 --- a/src/api/java/org/cyclops/commoncapabilities/api/ingredient/storage/IngredientComponentStorageSlottedEmpty.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.cyclops.commoncapabilities.api.ingredient.storage; - -import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; - -import javax.annotation.Nonnull; - -/** - * A dummy slotted ingredient component storage that is empty. - * @author rubensworks - */ -public class IngredientComponentStorageSlottedEmpty extends IngredientComponentStorageEmpty - implements IIngredientComponentStorageSlotted { - - public IngredientComponentStorageSlottedEmpty(IngredientComponent component) { - super(component); - } - - @Override - public int getSlots() { - return 0; - } - - @Override - public T getSlotContents(int slot) { - return getComponent().getMatcher().getEmptyInstance(); - } - - @Override - public long getMaxQuantity(int slot) { - return 0; - } - - @Override - public T insert(int slot, @Nonnull T ingredient, boolean simulate) { - return ingredient; - } - - @Override - public T extract(int slot, long maxQuantity, boolean simulate) { - return getComponent().getMatcher().getEmptyInstance(); - } -}