diff --git a/api/forestry b/api/forestry index 12e4ed1e4..281004a13 160000 --- a/api/forestry +++ b/api/forestry @@ -1 +1 @@ -Subproject commit 12e4ed1e4bef77ef02eccd5bbea14675f8436ca3 +Subproject commit 281004a13d0a99385ec2bd0bdea5b23afaab195d diff --git a/src/main/java/forestry/factory/DummyManagers.java b/src/main/java/forestry/factory/DummyManagers.java index 68de0b912..d8cf70414 100644 --- a/src/main/java/forestry/factory/DummyManagers.java +++ b/src/main/java/forestry/factory/DummyManagers.java @@ -9,6 +9,7 @@ import net.minecraftforge.fluids.FluidStack; import forestry.api.recipes.ICarpenterManager; import forestry.api.recipes.ICentrifugeManager; +import forestry.api.recipes.ICentrifugeRecipe; import forestry.api.recipes.IFabricatorManager; import forestry.api.recipes.IFermenterManager; import forestry.api.recipes.IMoistenerManager; @@ -42,6 +43,16 @@ public class DummyManagers { public static class CentrifugeManager implements ICentrifugeManager { + @Override + public void addRecipe(ICentrifugeRecipe recipe) { + + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, Map products) { + + } + @Override public void addRecipe(int timePerItem, ItemStack resource, HashMap products) { diff --git a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java index fabb8bcc4..657a982cf 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java +++ b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java @@ -10,11 +10,15 @@ ******************************************************************************/ package forestry.factory.gadgets; +import com.google.common.collect.ImmutableMap; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; import java.util.Stack; @@ -33,6 +37,7 @@ import cpw.mods.fml.common.Optional; import forestry.api.core.ForestryAPI; import forestry.api.recipes.ICentrifugeManager; +import forestry.api.recipes.ICentrifugeRecipe; import forestry.core.EnumErrorCode; import forestry.core.config.Config; import forestry.core.config.Defaults; @@ -55,93 +60,8 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { public static final int SLOT_PRODUCT_1 = 1; public static final int SLOT_PRODUCT_COUNT = 9; - /* RECIPE MANAGMENT */ - public static class Recipe { - - public final int timePerItem; - public final ItemStack resource; - public final HashMap products; - - public Recipe(int timePerItem, ItemStack resource, HashMap products) { - this.timePerItem = timePerItem; - this.resource = resource; - this.products = products; - - for (ItemStack item : products.keySet()) { - if (item == null) { - throw new IllegalArgumentException("Tried to register a null product of " + resource); - } - } - } - - public boolean matches(ItemStack res) { - return StackUtils.isCraftingEquivalent(resource, res); - } - } - - public static class RecipeManager implements ICentrifugeManager { - - public static final ArrayList recipes = new ArrayList(); - - @Override - public void addRecipe(int timePerItem, ItemStack resource, HashMap products) { - recipes.add(new Recipe(timePerItem, resource, products)); - } - - @Override - public void addRecipe(int timePerItem, ItemStack resource, ItemStack[] produce, int[] chances) { - HashMap products = new HashMap(); - - int i = 0; - for (ItemStack prod : produce) { - products.put(prod, chances[i]); - i++; - } - - addRecipe(timePerItem, resource, products); - } - - @Override - public void addRecipe(int timePerItem, ItemStack resource, ItemStack primary, ItemStack secondary, int chance) { - HashMap products = new HashMap(); - products.put(primary, 100); - if (secondary != null) { - products.put(secondary, chance); - } - addRecipe(timePerItem, resource, products); - } - - @Override - public void addRecipe(int timePerItem, ItemStack resource, ItemStack primary) { - HashMap products = new HashMap(); - products.put(primary, 100); - addRecipe(timePerItem, resource, products); - } - - public static Recipe findMatchingRecipe(ItemStack item) { - for (Recipe recipe : recipes) { - if (recipe.matches(item)) { - return recipe; - } - } - return null; - } - - @Override - public Map getRecipes() { - HashMap recipeList = new HashMap(); - - for (Recipe recipe : recipes) { - Set productsKeys = recipe.products.keySet(); - recipeList.put(new Object[]{recipe.resource}, productsKeys.toArray(new ItemStack[productsKeys.size()])); - } - - return recipeList; - } - } - /* MEMBER */ - public MachineCentrifuge.Recipe currentRecipe; + public ICentrifugeRecipe currentRecipe; private final Stack pendingProducts = new Stack(); private int productionTime; @@ -237,13 +157,8 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { } // We are done, add products to queue - for (Map.Entry entry : currentRecipe.products.entrySet()) { - if (entry.getValue() >= 100) { - pendingProducts.push(entry.getKey().copy()); - } else if (worldObj.rand.nextInt(100) < entry.getValue()) { - pendingProducts.push(entry.getKey().copy()); - } - } + Collection products = currentRecipe.getProducts(worldObj.rand); + pendingProducts.addAll(products); getInternalInventory().decrStackSize(SLOT_RESOURCE, 1); checkRecipe(); @@ -254,7 +169,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { } public void checkRecipe() { - Recipe machingRecipe = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); + ICentrifugeRecipe machingRecipe = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); if (currentRecipe != machingRecipe) { currentRecipe = machingRecipe; @@ -271,8 +186,8 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { return; } - productionTime = currentRecipe.timePerItem; - timePerItem = currentRecipe.timePerItem; + productionTime = currentRecipe.getProcessingTime(); + timePerItem = currentRecipe.getProcessingTime(); } private boolean tryAddPending() { @@ -362,4 +277,135 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT); } } + + /* RECIPE MANAGEMENT */ + public static class CentrifugeRecipe implements ICentrifugeRecipe { + + private final int processingTime; + private final ItemStack input; + private final Map outputs; + + public CentrifugeRecipe(int processingTime, ItemStack input, Map outputs) { + this.processingTime = processingTime; + this.input = input; + this.outputs = outputs; + + for (ItemStack item : outputs.keySet()) { + if (item == null) { + throw new IllegalArgumentException("Tried to register a null product of " + input); + } + } + } + + @Override + public ItemStack getInput() { + return input; + } + + @Override + public int getProcessingTime() { + return processingTime; + } + + @Override + public Collection getProducts(Random random) { + List products = new ArrayList(); + + for (Map.Entry entry : this.outputs.entrySet()) { + float probability = entry.getValue(); + + if (probability >= 1.0) { + products.add(entry.getKey().copy()); + } else if (random.nextFloat() < probability) { + products.add(entry.getKey().copy()); + } + } + + return products; + } + + @Override + public Map getAllProducts() { + return ImmutableMap.copyOf(outputs); + } + } + + public static class RecipeManager implements ICentrifugeManager { + + public static final List recipes = new ArrayList(); + + @Override + public void addRecipe(ICentrifugeRecipe recipe) { + recipes.add(recipe); + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, Map products) { + ICentrifugeRecipe recipe = new CentrifugeRecipe(timePerItem, resource, products); + addRecipe(recipe); + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, HashMap products) { + Map floatProducts = new HashMap(); + for (Map.Entry entry : products.entrySet()) { + floatProducts.put(entry.getKey(), entry.getValue() / 100.0f); + } + + addRecipe(timePerItem, resource, floatProducts); + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, ItemStack[] produce, int[] chances) { + Map products = new HashMap(); + + int i = 0; + for (ItemStack prod : produce) { + products.put(prod, chances[i] / 100f); + i++; + } + + addRecipe(timePerItem, resource, products); + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, ItemStack primary, ItemStack secondary, int chance) { + Map products = new HashMap(); + products.put(primary, 1.0f); + if (secondary != null) { + products.put(secondary, chance / 100f); + } + addRecipe(timePerItem, resource, products); + } + + @Override + public void addRecipe(int timePerItem, ItemStack resource, ItemStack primary) { + Map products = new HashMap(); + products.put(primary, 1.0f); + addRecipe(timePerItem, resource, products); + } + + public static ICentrifugeRecipe findMatchingRecipe(ItemStack item) { + for (ICentrifugeRecipe recipe : recipes) { + ItemStack recipeInput = recipe.getInput(); + if (StackUtils.isCraftingEquivalent(recipeInput, item)) { + return recipe; + } + } + return null; + } + + @Override + public Map getRecipes() { + HashMap recipeList = new HashMap(); + + for (ICentrifugeRecipe recipe : recipes) { + Set productsKeys = recipe.getAllProducts().keySet(); + recipeList.put(new Object[]{recipe.getInput()}, productsKeys.toArray(new ItemStack[productsKeys.size()])); + } + + return recipeList; + } + } + } diff --git a/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java b/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java index a34c99be1..583885777 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java @@ -11,10 +11,12 @@ package forestry.factory.recipes; import java.util.ArrayList; +import java.util.List; import java.util.Map.Entry; import net.minecraft.item.ItemStack; +import forestry.api.recipes.ICentrifugeRecipe; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.factory.gadgets.MachineCentrifuge; @@ -51,17 +53,17 @@ public class CraftGuideCentrifuge implements RecipeProvider { ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Defaults.DEFINITION_CENTRIFUGE_META); RecipeTemplate template = generator.createRecipeTemplate(slots, machine); - for (MachineCentrifuge.Recipe recipe : MachineCentrifuge.RecipeManager.recipes) { + for (ICentrifugeRecipe recipe : MachineCentrifuge.RecipeManager.recipes) { Object[] array = new Object[11]; - ArrayList> entries = new ArrayList>(recipe.products.entrySet()); + List> entries = new ArrayList>(recipe.getAllProducts().entrySet()); for (int i = 0; i < Math.min(entries.size(), 9); i++) { - Entry entry = entries.get(i); + Entry entry = entries.get(i); array[i] = entry.getValue() > 0 ? new Object[]{entry.getKey(), entry.getValue()} : null; } - array[9] = recipe.resource; + array[9] = recipe.getInput(); array[10] = machine; generator.addRecipe(template, array); diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index eb76b3452..22080800d 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.plugins; +import com.google.common.collect.ImmutableMap; + import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -628,50 +630,97 @@ public class PluginApiculture extends ForestryPlugin { // / CENTRIFUGE // Honey combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 0), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Cocoa combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 1), ForestryItem.beeswax.getItemStack(), new ItemStack(Items.dye, 1, 3), 50); - // Simmering combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 2), ForestryItem.refractoryWax.getItemStack(), ForestryItem.phosphor.getItemStack(2), 70); - // Stringy combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 3), ForestryItem.propolis.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); - // Dripping combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 5), ForestryItem.honeydew.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); - // Frozen combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 4), new ItemStack[]{ForestryItem.beeswax.getItemStack(), - ForestryItem.honeyDrop.getItemStack(), new ItemStack(Items.snowball), ForestryItem.pollenCluster.getItemStack(1, 1)}, new int[]{80, 70, 40, 20}); - // Silky combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 6), ForestryItem.honeyDrop.getItemStack(), ForestryItem.propolis.getItemStack(1, 3), 80); - // Parched combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 7), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Mysterious combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 8), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.propolis.getItemStack(1, 2)}, new int[]{40, 100}); - // Irradiated combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 9), new ItemStack[]{}, new int[]{}); - // Powdery combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 10), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.gunpowder)}, new int[]{20, 20, 90}); - // Reddened Combs - RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 11), - new ItemStack[]{ForestryItem.honeyDrop.getItemStack(2, 1)}, new int[]{100}); - // Darkened Combs - RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 12), - new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 1)}, new int[]{100}); - // Omega Combs - RecipeManagers.centrifugeManager.addRecipe(400, ForestryItem.beeComb.getItemStack(1, 13), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 2)}, new int[]{100}); - // Wheaten Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 14), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.wheat)}, new int[]{20, 20, 80}); - // Mossy Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 15), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Mellow Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 16), new ItemStack[]{ForestryItem.honeydew.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.quartz)}, new int[]{60, 20, 30}); + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 0), ImmutableMap.of( + ForestryItem.beeswax.getItemStack(), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.9f + )); - // Silk - RecipeManagers.centrifugeManager.addRecipe(5, ForestryItem.propolis.getItemStack(1, 3), new ItemStack[]{ - ForestryItem.craftingMaterial.getItemStack(1, 2), ForestryItem.propolis.getItemStack()}, new int[]{60, 10}); + // Cocoa combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 1), ImmutableMap.of( + ForestryItem.beeswax.getItemStack(), 1.0f, + new ItemStack(Items.dye, 1, 3), 0.5f + )); + + // Simmering combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 2), ImmutableMap.of( + ForestryItem.refractoryWax.getItemStack(), 1.0f, + ForestryItem.phosphor.getItemStack(2), 0.7f + )); + + // Stringy combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 3), ImmutableMap.of( + ForestryItem.propolis.getItemStack(), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.4f + )); + + // Dripping combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 5), ImmutableMap.of( + ForestryItem.honeydew.getItemStack(), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.4f + )); + + // Frozen combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 4), ImmutableMap.of( + ForestryItem.beeswax.getItemStack(), 0.8f, + ForestryItem.honeyDrop.getItemStack(), 0.7f, + new ItemStack(Items.snowball), 0.4f, + ForestryItem.pollenCluster.getItemStack(1, 1), 0.2f + )); + + // Silky combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 6), ImmutableMap.of( + ForestryItem.honeyDrop.getItemStack(), 1.0f, + ForestryItem.propolis.getItemStack(1, 3), 0.8f + )); + + // Parched combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 7), ImmutableMap.of( + ForestryItem.beeswax.getItemStack(), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.9f + )); + + // Mysterious combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 8), ImmutableMap.of( + ForestryItem.propolis.getItemStack(1, 2), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.4f + )); + + // Irradiated combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 9), ImmutableMap.of( + )); + + // Powdery combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 10), ImmutableMap.of( + ForestryItem.honeyDrop.getItemStack(), 0.2f, + ForestryItem.beeswax.getItemStack(), 0.2f, + new ItemStack(Items.gunpowder), 0.9f + )); + + // Wheaten Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 14), ImmutableMap.of( + ForestryItem.honeyDrop.getItemStack(), 0.2f, + ForestryItem.beeswax.getItemStack(), 0.2f, + new ItemStack(Items.wheat), 0.8f + )); + + // Mossy Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 15), ImmutableMap.of( + ForestryItem.beeswax.getItemStack(), 1.0f, + ForestryItem.honeyDrop.getItemStack(), 0.9f + )); + + // Mellow Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 16), ImmutableMap.of( + ForestryItem.honeydew.getItemStack(), 0.6f, + ForestryItem.beeswax.getItemStack(), 0.2f, + new ItemStack(Items.quartz), 0.3f + )); + + // Silky Propolis + RecipeManagers.centrifugeManager.addRecipe(5, ForestryItem.propolis.getItemStack(1, 3), ImmutableMap.of( + ForestryItem.craftingMaterial.getItemStack(1, 2), 0.6f, + ForestryItem.propolis.getItemStack(), 0.1f + )); // / FERMENTER RecipeManagers.fermenterManager.addRecipe(ForestryItem.honeydew.getItemStack(), 500, 1.0f, Fluids.SHORT_MEAD.getFluid(1), Fluids.HONEY.getFluid(1)); diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index f2c80a548..247d9ad15 100644 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.plugins; +import com.google.common.collect.ImmutableMap; + import java.util.EnumSet; import net.minecraft.init.Blocks; @@ -278,7 +280,7 @@ public class PluginIC2 extends ForestryPlugin { } if (resin != null) { - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), ImmutableMap.of(resin, 1.0f)); } else { Proxies.log.fine("Missing IC2 resin, skipping centrifuge recipe for propolis to resin."); }