Fixed drainContainers not checking to see if it can fill

This commit is contained in:
modmuss50 2015-05-16 21:55:27 +01:00
parent 44a21fd13d
commit 1726d4c7a3
2 changed files with 11 additions and 27 deletions

View file

@ -103,7 +103,7 @@ public class TileThermalGenerator extends TileEntity implements IWrenchable,
{
if (fluid != null)
{
if (FluidRegistry.getFluidName(fluid.getID()).contentEquals("lava"))
if (fluid == FluidRegistry.LAVA)
{
return true;
}

View file

@ -11,24 +11,16 @@ import net.minecraftforge.fluids.IFluidHandler;
public class FluidUtils {
public static boolean drainContainers(IFluidHandler fluidHandler,
IInventory inv, int inputSlot, int outputSlot)
{
IInventory inv, int inputSlot, int outputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
if (input != null)
{
if (input != null) {
FluidStack fluidInContainer = getFluidStackInContainer(input);
ItemStack emptyItem = input.getItem().getContainerItem(input);
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)
{
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.canFill(ForgeDirection.UP, fluidInContainer.getFluid())) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer,
true);
if (emptyItem != null)
@ -45,21 +37,15 @@ public class FluidUtils {
}
public static boolean fillContainers(IFluidHandler fluidHandler,
IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill)
{
IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
ItemStack filled = getFilledContainer(fluidToFill, input);
if (filled != null
&& (output == null || (output.stackSize < output
.getMaxStackSize() && ItemUtils.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)
{
if (drain != null && drain.amount == fluidInContainer.amount) {
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer,
true);
if (output == null)
@ -73,13 +59,11 @@ public class FluidUtils {
return false;
}
public static FluidStack getFluidStackInContainer(ItemStack stack)
{
public static FluidStack getFluidStackInContainer(ItemStack stack) {
return FluidContainerRegistry.getFluidForFilledItem(stack);
}
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty)
{
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
if (fluid == null || empty == null)
return null;
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid,