Disabled salvaging function of ore processors

There were several bugs that are not resolved but a few still remain.
The main one is near zero output from salvaged. Which even though its
not a big issue it still means that players lose items when they should
get stuff back.
This commit is contained in:
DarkGuardsman 2013-11-05 02:01:30 -05:00
parent 4537211850
commit 96d136a3f4
2 changed files with 51 additions and 43 deletions

View file

@ -5,7 +5,9 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.OreDictionary;
@ -21,7 +23,7 @@ import dark.core.common.items.ItemOreDirv;
import dark.core.prefab.helpers.AutoCraftingManager;
/** Recipes for ore processor machines
*
*
* @author DarkGuardsman */
public class MachineRecipeHandler
{
@ -48,12 +50,12 @@ public class MachineRecipeHandler
MachineRecipeHandler.newAltProcessorOutput(ProcessorType.CRUSHER, Block.cobblestoneMossy, Block.cobblestone);
MachineRecipeHandler.newAltProcessorOutput(ProcessorType.CRUSHER, Item.stick, null);
//TODO replace these with ItemOreDirv
//TODO replace these with ItemOreDirv glass shards
MachineRecipeHandler.newAltProcessorOutput(ProcessorType.CRUSHER, Block.glass, Block.sand);
}
/** Creates a new recipe for the type of processor machine
*
*
* @param type - machine type
* @param in - input item, stacksize is ignored
* @param out - output item */
@ -63,7 +65,7 @@ public class MachineRecipeHandler
}
/** Creates a new recipe for the type of processor machine
*
*
* @param type - machine type
* @param in - input item, stacksize is ignored
* @param out - output item
@ -75,7 +77,7 @@ public class MachineRecipeHandler
}
/** Creates a new recipe for the type of processor machine
*
*
* @param type - machine type
* @param in - input item, stacksize is ignored
* @param out - output item
@ -171,7 +173,7 @@ public class MachineRecipeHandler
/** Gets the lit of items that are created from the input item stack. General this will be an
* array of one item. However, in salavaging cases it can be up to 8 items.
*
*
* @param type - Processor type
* @param inputStack - item stack input ignores stacksize
* @return array of itemStacks */
@ -194,7 +196,8 @@ public class MachineRecipeHandler
}
if (reList == null)
{
reList = salvageItem(type, inputStack);
//TODO Disabled due to bug and needs to be fixed to make the processors more functional
//reList = salvageItem(type, inputStack);
}
return reList;
}
@ -202,7 +205,7 @@ public class MachineRecipeHandler
}
/** Salvages an itemStack for the items used to craft it
*
*
* @param type - processor type used to determine damage results
* @param stack - itemStack being salvaged
* @return Array of all items salvaged */
@ -212,16 +215,16 @@ public class MachineRecipeHandler
}
/** Salvages an itemStack for the items used to craft it
*
*
* @param type - processor type used to determine damage results
* @param stack - itemStack being salvaged
* @param damage - damage the output items. Eg ironIngot becomes ironDust, or ironScraps
* @return Array of all items salvaged */
public static ItemStack[] salvageItem(ProcessorType type, ItemStack stack, boolean damage)
{
float bar = 0.3f;
float bar = 0.1f;
//Allow tools and armor to be salvaged but at a very low rate
if (stack.isItemDamaged())
if ((stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemTool) && stack.isItemDamaged())
{
bar = (stack.getItemDamage() / stack.getMaxDamage());
}
@ -240,7 +243,7 @@ public class MachineRecipeHandler
}
/** Salvages an itemStack for the items used to craft it
*
*
* @param stack - itemStack being salvaged
* @param bar - chance per item that the random must be above inorder to salvage the output
* @return Array of all items salvaged */
@ -248,20 +251,26 @@ public class MachineRecipeHandler
{
//TODO find a way around having to force recipe to be the same stack size of the salvage. Maybe percentage based salvaging or min stacksize from machine?
ItemStack[] recipeList = AutoCraftingManager.getReverseRecipe(stack.copy(), stack.stackSize);
ItemStack[] reList = new ItemStack[recipeList.length];
for (int i = 0; i < recipeList.length; i++)
if (recipeList != null)
{
if (recipeList[i] != null && random.nextFloat() >= bar)
ItemStack[] reList = new ItemStack[recipeList.length];
boolean items = false;
for (int i = 0; i < recipeList.length; i++)
{
reList[i] = recipeList[i];
if (recipeList[i].itemID < Block.blocksList.length && Block.blocksList[recipeList[i].itemID] != null && recipeList[i].getItemDamage() > 16)
if (random.nextFloat() >= bar)
{
reList[i].setItemDamage(0);
}
reList[i] = recipeList[i].copy();
items = true;
if (recipeList[i].itemID < Block.blocksList.length && Block.blocksList[recipeList[i].itemID] != null && recipeList[i].getItemDamage() > 16)
{
reList[i].setItemDamage(0);
}
}
}
return items ? reList : null;
}
return reList;
return null;
}
public static ItemStack[] getOuputNormal(ProcessorType type, ItemStack stack)

View file

@ -23,7 +23,7 @@ import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.ReflectionHelper;
/** Rewrite of the imprinter crafting system into its own manageable class
*
*
* @author DarkGuardsman */
public class AutoCraftingManager
{
@ -127,7 +127,7 @@ public class AutoCraftingManager
}
/** Does this player's inventory contain the required resources to craft this item?
*
*
* @return Required items to make the desired item. */
public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem)
{
@ -212,45 +212,44 @@ public class AutoCraftingManager
}
else if (object instanceof ShapelessRecipes)
{
return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]).clone();
return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[9]).clone();
}
else if (object instanceof ShapedOreRecipe)
{
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
Object[] recipeItems = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
List<ItemStack> actualResources = new ArrayList<ItemStack>();
ItemStack[] actualResources;
if (recipeItems != null)
{
for (Object obj : recipeItems)
actualResources = new ItemStack[recipeItems.length];
for (int i = 0; i < recipeItems.length; i++)
{
if (obj instanceof ItemStack)
if (recipeItems[i] instanceof ItemStack)
{
ItemStack recipeItem = (ItemStack) obj;
actualResources.add(recipeItem.copy());
actualResources[i] = ((ItemStack)recipeItems[i]).copy();
}
else if (obj instanceof ArrayList)
else if (recipeItems[i] instanceof ArrayList)
{
Object[] ingredientsArray = ((ArrayList) obj).toArray();
Object[] ingredientsArray = ((ArrayList) recipeItems[i]).toArray();
for (int x = 0; x < ingredientsArray.length; x++)
{
if (ingredientsArray[x] != null && ingredientsArray[x] instanceof ItemStack)
{
ItemStack recipeItem = (ItemStack) ingredientsArray[x];
actualResources.add(recipeItem.copy());
actualResources[i] = ((ItemStack)ingredientsArray[x]).copy();
break;
}
}
}
}
return actualResources.toArray(new ItemStack[1]);
return actualResources;
}
}
else if (object instanceof ShapelessOreRecipe)
{
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
return (ItemStack[]) ((ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input")).toArray(new ItemStack[1]).clone();
return (ItemStack[]) ((ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input")).toArray(new ItemStack[9]).clone();
}
}
}
@ -261,7 +260,7 @@ public class AutoCraftingManager
}
/** Gets the itemStacks in the inv based on slots
*
*
* @param inv - @IInventory instance
* @param slots - slot # to be used
* @return array of itemStack the same size as the slots input array */
@ -281,7 +280,7 @@ public class AutoCraftingManager
}
/** Returns if the following inventory has the following resource required.
*
*
* @param recipeItems - The items to be checked for the recipes. */
public ArrayList<ItemStack> hasResource(Object[] recipeItems)
{
@ -369,7 +368,7 @@ public class AutoCraftingManager
}
/** Decreases the stack by a set amount
*
*
* @param stack - starting stack
* @param amount - amount of items
* @return the edited stack */
@ -400,7 +399,7 @@ public class AutoCraftingManager
}
/** Checks if an item exist within the inv array
*
*
* @param recipeItem - itemstack being searched for
* @param containingItems - inv array containing the search bounds
* @return the point in the array the item was found -1 = the item was null or not valid -2 =
@ -432,14 +431,14 @@ public class AutoCraftingManager
/** Checks if itemstack are equal based on crafting result rather than normal itemstack this is
* done so that if the itemstack returns with
*
*
* @param recipeItem - itemstack being compared
* @param checkStack - itemstack being comparted
* @return true if the items are a match for each other
*
*
* If the item can't be stack and is able to take damage the item will be check on damaged
* status
*
*
* If the item's meta data is not normal or in other words equals 32767 the meta data will be
* ignored */
public static boolean areStacksEqual(ItemStack recipeItem, ItemStack checkStack)
@ -460,7 +459,7 @@ public class AutoCraftingManager
}
/** Consumes an item checking for extra conditions like container items
*
*
* @param stack - starting itemStack
* @param ammount - amount to consume
* @return what is left of the itemStack if any */
@ -505,7 +504,7 @@ public class AutoCraftingManager
}
/** Used to automatically remove selected items from crafting inv
*
*
* @param requiredItems - items that are to be removed */
public void consumeItems(ItemStack... requiredItems)
{