added centrifuge recipe + moved itemUtils to its own class
This commit is contained in:
parent
91495286db
commit
fcfc6ed1df
7 changed files with 129 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
|||
package techreborn.util;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
@ -18,7 +19,7 @@ public class FluidUtils {
|
|||
if (input != null) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(output, emptyItem, true, true)))) {
|
||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(output, emptyItem, true, true)))) {
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used >= fluidInContainer.amount) {
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||
|
@ -39,7 +40,7 @@ public class FluidUtils {
|
|||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(filled, output, true, true)))) {
|
||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(filled, output, true, true)))) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (drain != null && drain.amount == fluidInContainer.amount) {
|
||||
|
@ -64,27 +65,4 @@ public class FluidUtils {
|
|||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
|
||||
}
|
||||
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
|
||||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
}
|
||||
|
|
33
src/main/java/techreborn/util/ItemUtils.java
Normal file
33
src/main/java/techreborn/util/ItemUtils.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package techreborn.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* Created by mark on 12/04/15.
|
||||
*/
|
||||
public class ItemUtils {
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
|
||||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue