Ore dict support for solderer
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
### 0.7.7
|
||||
**Bugfixes**
|
||||
- Fix buggy reequip animation on wireless grid
|
||||
- Fixed buggy reequip animation on wireless grid
|
||||
- Fixed solderer not supporting ore dictionary
|
||||
- Fixed recipes not supporting ore dictionary
|
||||
|
||||
**Features**
|
||||
- Added the Stack Upgrade
|
||||
|
@@ -16,6 +16,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import refinedstorage.item.ItemUpgrade;
|
||||
|
||||
public class RefinedStorageUtils {
|
||||
@@ -94,42 +96,63 @@ public class RefinedStorageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean compareStack(ItemStack first, ItemStack second) {
|
||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||
public static boolean compareStack(ItemStack left, ItemStack right) {
|
||||
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||
}
|
||||
|
||||
public static boolean compareStack(ItemStack first, ItemStack second, int flags) {
|
||||
if (first == null && second == null) {
|
||||
public static boolean compareStack(ItemStack left, ItemStack right, int flags) {
|
||||
if (left == null && right == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((first == null && second != null) || (first != null && second == null)) {
|
||||
if ((left == null && right != null) || (left != null && right == null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) {
|
||||
if (first.getItemDamage() != second.getItemDamage()) {
|
||||
if (left.getItemDamage() != right.getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
||||
if (first.hasTagCompound() && !first.getTagCompound().equals(second.getTagCompound())) {
|
||||
if (left.hasTagCompound() && !left.getTagCompound().equals(right.getTagCompound())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
||||
if (first.stackSize != second.stackSize) {
|
||||
if (left.stackSize != right.stackSize) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return first.getItem() == second.getItem();
|
||||
return left.getItem() == right.getItem();
|
||||
}
|
||||
|
||||
public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) {
|
||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE);
|
||||
public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
|
||||
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE);
|
||||
}
|
||||
|
||||
public static boolean compareStackOreDict(ItemStack left, ItemStack right) {
|
||||
if (left == null && right == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((left == null && right != null) || (left != null && right == null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int[] leftIds = OreDictionary.getOreIDs(left);
|
||||
int[] rightIds = OreDictionary.getOreIDs(right);
|
||||
|
||||
for (int i : rightIds) {
|
||||
if (ArrayUtils.contains(leftIds, i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getSpeed(IItemHandler handler) {
|
||||
|
@@ -69,6 +69,8 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
||||
if (storage != null && storage.isDirty()) {
|
||||
storage.writeToNBT(disks.getStackInSlot(i).getTagCompound());
|
||||
storage.markClean();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package refinedstorage.tile.solderer;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
|
||||
@@ -16,31 +15,21 @@ public class SoldererRegistry {
|
||||
|
||||
public static ISoldererRecipe getRecipe(IItemHandler items) {
|
||||
for (ISoldererRecipe recipe : recipes) {
|
||||
boolean ok = true;
|
||||
boolean found = true;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i))) {
|
||||
ok = false;
|
||||
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !RefinedStorageUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
|
||||
found = false;
|
||||
}
|
||||
|
||||
if (items.getStackInSlot(i) != null && recipe.getRow(i) != null) {
|
||||
if (items.getStackInSlot(i).stackSize < recipe.getRow(i).stackSize) {
|
||||
ok = false;
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ISoldererRecipe getRecipe(ItemStack result) {
|
||||
for (ISoldererRecipe recipe : recipes) {
|
||||
if (RefinedStorageUtils.compareStack(result, recipe.getResult())) {
|
||||
if (found) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
@@ -39,44 +39,48 @@ public class TileSolderer extends TileMachine {
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
|
||||
|
||||
boolean wasWorking = working;
|
||||
|
||||
if (newRecipe == null) {
|
||||
if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && items.getStackInSlot(3) == null) {
|
||||
stop();
|
||||
} else if (newRecipe != recipe) {
|
||||
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
|
||||
} else {
|
||||
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
|
||||
|
||||
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
|
||||
recipe = newRecipe;
|
||||
progress = 0;
|
||||
working = true;
|
||||
if (newRecipe == null) {
|
||||
stop();
|
||||
} else if (newRecipe != recipe) {
|
||||
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
} else if (working) {
|
||||
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
|
||||
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
|
||||
recipe = newRecipe;
|
||||
progress = 0;
|
||||
working = true;
|
||||
|
||||
if (progress >= recipe.getDuration()) {
|
||||
if (items.getStackInSlot(3) != null) {
|
||||
items.getStackInSlot(3).stackSize += recipe.getResult().stackSize;
|
||||
} else {
|
||||
items.setStackInSlot(3, recipe.getResult());
|
||||
markDirty();
|
||||
}
|
||||
} else if (working) {
|
||||
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (recipe.getRow(i) != null) {
|
||||
items.extractItem(i, recipe.getRow(i).stackSize, false);
|
||||
if (progress >= recipe.getDuration()) {
|
||||
if (items.getStackInSlot(3) != null) {
|
||||
items.getStackInSlot(3).stackSize += recipe.getResult().stackSize;
|
||||
} else {
|
||||
items.setStackInSlot(3, recipe.getResult());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (recipe.getRow(i) != null) {
|
||||
items.extractItem(i, recipe.getRow(i).stackSize, false);
|
||||
}
|
||||
}
|
||||
|
||||
recipe = null;
|
||||
progress = 0;
|
||||
// Don't set working to false yet, wait till the next update because we may have
|
||||
// another stack waiting.
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
recipe = null;
|
||||
progress = 0;
|
||||
// Don't set working to false yet, wait till the next update because we may have
|
||||
// another stack waiting.
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user