Ore dict support for solderer

This commit is contained in:
Raoul Van den Berge
2016-05-31 19:30:09 +02:00
parent d73440fef9
commit 4e6fa9d2e0
5 changed files with 76 additions and 56 deletions

View File

@@ -2,7 +2,9 @@
### 0.7.7 ### 0.7.7
**Bugfixes** **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** **Features**
- Added the Stack Upgrade - Added the Stack Upgrade

View File

@@ -16,6 +16,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
import refinedstorage.item.ItemUpgrade; import refinedstorage.item.ItemUpgrade;
public class RefinedStorageUtils { public class RefinedStorageUtils {
@@ -94,42 +96,63 @@ public class RefinedStorageUtils {
} }
} }
public static boolean compareStack(ItemStack first, ItemStack second) { public static boolean compareStack(ItemStack left, ItemStack right) {
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY); return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
} }
public static boolean compareStack(ItemStack first, ItemStack second, int flags) { public static boolean compareStack(ItemStack left, ItemStack right, int flags) {
if (first == null && second == null) { if (left == null && right == null) {
return true; return true;
} }
if ((first == null && second != null) || (first != null && second == null)) { if ((left == null && right != null) || (left != null && right == null)) {
return false; return false;
} }
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) { if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) {
if (first.getItemDamage() != second.getItemDamage()) { if (left.getItemDamage() != right.getItemDamage()) {
return false; return false;
} }
} }
if ((flags & COMPARE_NBT) == COMPARE_NBT) { if ((flags & COMPARE_NBT) == COMPARE_NBT) {
if (first.hasTagCompound() && !first.getTagCompound().equals(second.getTagCompound())) { if (left.hasTagCompound() && !left.getTagCompound().equals(right.getTagCompound())) {
return false; return false;
} }
} }
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) { if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
if (first.stackSize != second.stackSize) { if (left.stackSize != right.stackSize) {
return false; return false;
} }
} }
return first.getItem() == second.getItem(); return left.getItem() == right.getItem();
} }
public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) { public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE); 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) { public static int getSpeed(IItemHandler handler) {

View File

@@ -69,6 +69,8 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
if (storage != null && storage.isDirty()) { if (storage != null && storage.isDirty()) {
storage.writeToNBT(disks.getStackInSlot(i).getTagCompound()); storage.writeToNBT(disks.getStackInSlot(i).getTagCompound());
storage.markClean(); storage.markClean();
markDirty();
} }
} }
} }

View File

@@ -1,6 +1,5 @@
package refinedstorage.tile.solderer; package refinedstorage.tile.solderer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorageUtils; import refinedstorage.RefinedStorageUtils;
@@ -16,31 +15,21 @@ public class SoldererRegistry {
public static ISoldererRecipe getRecipe(IItemHandler items) { public static ISoldererRecipe getRecipe(IItemHandler items) {
for (ISoldererRecipe recipe : recipes) { for (ISoldererRecipe recipe : recipes) {
boolean ok = true; boolean found = true;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i))) { if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !RefinedStorageUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
ok = false; found = false;
} }
if (items.getStackInSlot(i) != null && recipe.getRow(i) != null) { if (items.getStackInSlot(i) != null && recipe.getRow(i) != null) {
if (items.getStackInSlot(i).stackSize < recipe.getRow(i).stackSize) { if (items.getStackInSlot(i).stackSize < recipe.getRow(i).stackSize) {
ok = false; found = false;
} }
} }
} }
if (ok) { if (found) {
return recipe;
}
}
return null;
}
public static ISoldererRecipe getRecipe(ItemStack result) {
for (ISoldererRecipe recipe : recipes) {
if (RefinedStorageUtils.compareStack(result, recipe.getResult())) {
return recipe; return recipe;
} }
} }

View File

@@ -39,10 +39,13 @@ public class TileSolderer extends TileMachine {
@Override @Override
public void updateMachine() { public void updateMachine() {
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
boolean wasWorking = working; boolean wasWorking = working;
if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && items.getStackInSlot(3) == null) {
stop();
} else {
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
if (newRecipe == null) { if (newRecipe == null) {
stop(); stop();
} else if (newRecipe != recipe) { } else if (newRecipe != recipe) {
@@ -79,6 +82,7 @@ public class TileSolderer extends TileMachine {
markDirty(); markDirty();
} }
} }
}
if (wasWorking != working) { if (wasWorking != working) {
RefinedStorageUtils.updateBlock(worldObj, pos); RefinedStorageUtils.updateBlock(worldObj, pos);