Ore dict support for solderer
This commit is contained in:
@@ -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
|
||||||
|
@@ -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) {
|
||||||
|
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,44 +39,48 @@ 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 (newRecipe == null) {
|
if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && items.getStackInSlot(3) == null) {
|
||||||
stop();
|
stop();
|
||||||
} else if (newRecipe != recipe) {
|
} else {
|
||||||
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
|
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
|
||||||
|
|
||||||
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
|
if (newRecipe == null) {
|
||||||
recipe = newRecipe;
|
stop();
|
||||||
progress = 0;
|
} else if (newRecipe != recipe) {
|
||||||
working = true;
|
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
|
||||||
|
|
||||||
markDirty();
|
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
|
||||||
}
|
recipe = newRecipe;
|
||||||
} else if (working) {
|
progress = 0;
|
||||||
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
|
working = true;
|
||||||
|
|
||||||
if (progress >= recipe.getDuration()) {
|
markDirty();
|
||||||
if (items.getStackInSlot(3) != null) {
|
|
||||||
items.getStackInSlot(3).stackSize += recipe.getResult().stackSize;
|
|
||||||
} else {
|
|
||||||
items.setStackInSlot(3, recipe.getResult());
|
|
||||||
}
|
}
|
||||||
|
} else if (working) {
|
||||||
|
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
if (progress >= recipe.getDuration()) {
|
||||||
if (recipe.getRow(i) != null) {
|
if (items.getStackInSlot(3) != null) {
|
||||||
items.extractItem(i, recipe.getRow(i).stackSize, false);
|
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