Fix #364. Cleanup of Liquid/Fluid handling, handle IFluidContainerItem

This commit is contained in:
mezz committed 2014-12-13 01:42:52 -08:00
1 parent 5c4bd5307c
commit 5ea4770a2d
32 files changed
+518 -715

No files matched your search

@@ -17,6 +17,7 @@ import forestry.api.core.ForestryAPI;
import forestry.api.recipes.ICraftingProvider;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.gadgets.TileBase;
@@ -222,13 +223,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_CAN) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN));
if (container != null && RecipeManager.isInput(container.fluid)) {
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank));
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_CAN, null);
}
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
}
checkRecipe();
@@ -461,8 +456,8 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
return FluidContainerRegistry.isEmptyContainer(itemstack);
if(slotIndex == SLOT_CAN) {
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
return container != null && RecipeManager.isInput(container.fluid);
FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemstack);
return RecipeManager.isInput(fluidStack);
}
return false;
@@ -10,28 +10,11 @@
******************************************************************************/
package forestry.factory.gadgets;
import forestry.api.core.ForestryAPI;
import forestry.api.recipes.ICarpenterManager;
import forestry.api.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.gadgets.TileBase;
import forestry.core.gadgets.TilePowered;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.utils.TileInventoryAdapter;
import forestry.core.utils.Utils;
import forestry.factory.gui.ContainerCarpenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@@ -42,17 +25,36 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import forestry.api.core.EnumErrorCode;
import forestry.api.core.ForestryAPI;
import forestry.api.recipes.ICarpenterManager;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.gadgets.TileBase;
import forestry.core.gadgets.TilePowered;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.utils.TileInventoryAdapter;
import forestry.core.utils.Utils;
import forestry.factory.gui.ContainerCarpenter;
public class MachineCarpenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
@@ -144,14 +146,14 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
@Override
public void addCrating(ItemStack itemStack) {
ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained(itemStack);
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY),
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, FluidRegistry.getFluidStack(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY),
ForestryItem.crate.getItemStack(), itemStack, new Object[] { "###", "###", "###", '#', uncrated });
addRecipe(null, new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage()), new Object[] { "#", Character.valueOf('#'), itemStack });
addRecipe(null, new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage()), new Object[] { "#", '#', itemStack });
}
@Override
public void addCrating(String toCrate, ItemStack unpack, ItemStack crated) {
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY),
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, FluidRegistry.getFluidStack(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY),
ForestryItem.crate.getItemStack(), crated, new Object[] { "###", "###", "###", '#', toCrate });
addRecipe(null, new ItemStack(unpack.getItem(), 9, unpack.getItemDamage()), new Object[] { "#", '#', crated });
}
@@ -322,22 +324,15 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
@Override
public void updateServerSide() {
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
if (worldObj.getTotalWorldTime() % 20 != 0)
return;
// Check if we have suitable items waiting in the item slot
if (accessibleInventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(accessibleInventory.getStackInSlot(SLOT_CAN_INPUT));
if (container != null && RecipeManager.isResourceLiquid(container.fluid)) {
accessibleInventory.setInventorySlotContents(SLOT_CAN_INPUT,
StackUtils.replenishByContainer(this, accessibleInventory.getStackInSlot(SLOT_CAN_INPUT), container, resourceTank));
if (accessibleInventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0)
accessibleInventory.setInventorySlotContents(SLOT_CAN_INPUT, null);
}
FluidHelper.drainContainers(tankManager, accessibleInventory, SLOT_CAN_INPUT);
}
if (worldObj.getTotalWorldTime() % 40 * 10 != 0)
if (worldObj.getTotalWorldTime() % 40 != 0)
return;
if (currentRecipe == null) {
@@ -10,8 +10,29 @@
******************************************************************************/
package forestry.factory.gadgets;
import buildcraft.api.statements.ITriggerExternal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import cpw.mods.fml.common.Optional;
import forestry.api.core.EnumErrorCode;
import forestry.api.core.ForestryAPI;
import forestry.api.fuels.FuelManager;
@@ -19,6 +40,7 @@ import forestry.api.recipes.IFermenterManager;
import forestry.api.recipes.IVariableFermentable;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
@@ -29,29 +51,10 @@ import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import forestry.factory.triggers.FactoryTriggers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import buildcraft.api.statements.ITriggerExternal;
public class MachineFermenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
@@ -135,7 +138,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) {
addRecipe(resource, fermentationValue, modifier, output, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000));
addRecipe(resource, fermentationValue, modifier, output, FluidRegistry.getFluidStack(Defaults.LIQUID_WATER, 1000));
}
public static Recipe findMatchingRecipe(ItemStack res, FluidStack liqu) {
@@ -161,6 +164,8 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
}
public static boolean isLiquidResource(FluidStack liquid) {
if (liquid == null)
return false;
return recipeFluidInputs.contains(liquid.getFluid());
}
@@ -247,33 +252,20 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
@Override
public void updateServerSide() {
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_INPUT) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_INPUT));
if (container != null && RecipeManager.isLiquidResource(container.fluid)) {
inventory.setInventorySlotContents(SLOT_INPUT, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_INPUT), container, resourceTank));
if (inventory.getStackInSlot(SLOT_INPUT).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_INPUT, null);
}
}
// Can/capsule input/output needs to be handled here.
if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), productTank.getFluid());
if (container != null) {
inventory.setInventorySlotContents(SLOT_CAN_OUTPUT, bottleIntoContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), inventory.getStackInSlot(SLOT_CAN_OUTPUT), container,
productTank));
if (inventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_CAN_INPUT, null);
}
}
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
if (worldObj.getTotalWorldTime() % 20 != 0)
return;
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_INPUT) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_INPUT);
}
// Can/capsule input/output needs to be handled here.
if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidStack fluidStack = productTank.getFluid();
if (fluidStack != null)
FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid());
}
if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null) {
if (resourceTank.getFluidAmount() < fuelCurrentFerment)
@@ -550,11 +542,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
if (slotIndex == SLOT_INPUT) {
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
return container != null && RecipeManager.isLiquidResource(container.fluid);
FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemstack);
return RecipeManager.isLiquidResource(fluidStack);
}
if (slotIndex == SLOT_CAN_INPUT && LiquidHelper.isEmptyContainer(itemstack)) {
if (slotIndex == SLOT_CAN_INPUT && FluidHelper.isEmptyContainer(itemstack)) {
return true;
}
if (slotIndex == SLOT_FUEL && FuelManager.fermenterFuel.containsKey(itemstack))
@@ -18,6 +18,7 @@ import forestry.api.fuels.MoistenerFuel;
import forestry.api.recipes.IMoistenerManager;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.gadgets.TileBase;
@@ -27,7 +28,6 @@ import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import net.minecraft.entity.player.EntityPlayer;
@@ -38,7 +38,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
@@ -204,13 +203,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
// Check if we have suitable water container waiting in the item slot
if (inventory.getStackInSlot(SLOT_PRODUCT) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_PRODUCT));
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
inventory.setInventorySlotContents(SLOT_PRODUCT, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_PRODUCT), container, resourceTank));
if (inventory.getStackInSlot(SLOT_PRODUCT).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_PRODUCT, null);
}
FluidHelper.drainContainers(tankManager, inventory, SLOT_PRODUCT);
}
// Let's get to work
@@ -620,8 +613,8 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
Fluid fluid = FluidHelper.getFluidInContainer(stack);
if (fluid != null && resourceTank.accepts(fluid)) {
return inventory.addStack(stack, SLOT_PRODUCT, 1, false, doAdd);
}
@@ -10,21 +10,6 @@
******************************************************************************/
package forestry.factory.gadgets;
import forestry.api.core.BiomeHelper;
import forestry.api.core.EnumErrorCode;
import forestry.api.core.ForestryAPI;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.gadgets.TileBase;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.GuiId;
import forestry.core.utils.Fluids;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@@ -32,18 +17,35 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import forestry.api.core.BiomeHelper;
import forestry.api.core.EnumErrorCode;
import forestry.api.core.ForestryAPI;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.gadgets.TileBase;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.GuiId;
import forestry.core.utils.Fluids;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
public class MachineRaintank extends TileBase implements ISidedInventory, ILiquidTankContainer {
/* CONSTANTS */
public static final short SLOT_RESOURCE = 0;
public static final short SLOT_PRODUCT = 1;
private static final FluidStack STACK_WATER = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.RAINTANK_AMOUNT_PER_UPDATE);
private static final FluidStack STACK_WATER = FluidRegistry.getFluidStack(Defaults.LIQUID_WATER, Defaults.RAINTANK_AMOUNT_PER_UPDATE);
/* MEMBER */
public FilteredTank resourceTank;
@@ -132,7 +134,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
tryToStartFillling();
else {
fillingTime--;
if (fillingTime <= 0 && LiquidHelper.fillContainers(this, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get()))
if (fillingTime <= 0 && FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get()))
fillingTime = 0;
}
}
@@ -143,7 +145,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
private void tryToStartFillling() {
// Nothing to do if no empty cans are available
if (!LiquidHelper.fillContainers(this, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get(), false))
if (!FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get(), false))
return;
fillingTime = Defaults.RAINTANK_FILLING_TIME;
@@ -262,7 +264,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
if (slotIndex != SLOT_RESOURCE)
return false;
return LiquidHelper.getEmptyContainer(itemstack, STACK_WATER) != null;
return FluidHelper.isFillableContainer(itemstack, STACK_WATER);
}
/* SMP GUI */
@@ -16,6 +16,7 @@ import forestry.api.recipes.ISqueezerManager;
import forestry.api.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
@@ -230,21 +231,16 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
@Override
public void updateServerSide() {
if (worldObj.getTotalWorldTime() % 20 != 0)
return;
// Can/capsule input/output needs to be handled here.
if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), productTank.getFluid());
if (container != null) {
inventory.setInventorySlotContents(SLOT_CAN_OUTPUT, bottleIntoContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), inventory.getStackInSlot(SLOT_CAN_OUTPUT), container, productTank));
if (inventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_CAN_INPUT, null);
}
FluidStack fluidStack = productTank.getFluid();
if (fluidStack != null)
FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid());
}
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
return;
checkRecipe();
if (getErrorState() == EnumErrorCode.NORECIPE && currentRecipe != null)
setErrorState(EnumErrorCode.OK);
@@ -436,11 +432,11 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
if(slotIndex == SLOT_CAN_INPUT) {
return LiquidHelper.isEmptyContainer(itemstack);
return FluidHelper.isEmptyContainer(itemstack);
}
if(slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) {
if (LiquidHelper.isEmptyContainer(itemstack))
if (FluidHelper.isEmptyContainer(itemstack))
return false;
if (RecipeManager.canUse(itemstack))
@@ -504,7 +500,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
// Try to add to can slot if input is from top or bottom.
if (LiquidHelper.isEmptyContainer(stack)) {
if (FluidHelper.isEmptyContainer(stack)) {
return inventory.addStack(stack, SLOT_CAN_INPUT, 1, false, doAdd);
} else {
return inventory.addStack(stack, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, false, doAdd);
@@ -10,12 +10,30 @@
******************************************************************************/
package forestry.factory.gadgets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import forestry.api.core.EnumErrorCode;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
import forestry.api.recipes.IStillManager;
import forestry.api.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
@@ -26,25 +44,8 @@ import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class MachineStill extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
@@ -177,32 +178,22 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
@Override
public void updateServerSide() {
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
return;
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_CAN) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN));
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank));
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_CAN, null);
}
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
}
// Can product liquid if possible
if (inventory.getStackInSlot(SLOT_RESOURCE) != null) {
FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_RESOURCE), productTank.getFluid());
if (container != null) {
inventory.setInventorySlotContents(SLOT_PRODUCT, bottleIntoContainer(inventory.getStackInSlot(SLOT_RESOURCE), inventory.getStackInSlot(SLOT_PRODUCT), container, productTank));
if (inventory.getStackInSlot(SLOT_RESOURCE).stackSize <= 0)
inventory.setInventorySlotContents(SLOT_RESOURCE, null);
FluidStack fluidStack = productTank.getFluid();
if (fluidStack != null) {
FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid());
}
}
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
return;
checkRecipe();
if (getErrorState() == EnumErrorCode.NORECIPE && currentRecipe != null)
setErrorState(EnumErrorCode.OK);
@@ -335,10 +326,10 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
int inventorySlot;
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
if (container != null && resourceTank.accepts(container.fluid.getFluid()))
Fluid fluid = FluidHelper.getFluidInContainer(stack);
if (fluid != null && resourceTank.accepts(fluid))
inventorySlot = SLOT_CAN;
else if (LiquidHelper.isEmptyContainer(stack))
else if (FluidHelper.isEmptyContainer(stack))
inventorySlot = SLOT_RESOURCE;
else
return 0;
@@ -447,11 +438,11 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
return false;
if(slotIndex == SLOT_RESOURCE)
return LiquidHelper.isEmptyContainer(itemstack);
return FluidHelper.isEmptyContainer(itemstack);
if(slotIndex == SLOT_CAN) {
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
return container != null && resourceTank.accepts(container.fluid.getFluid());
Fluid fluid = FluidHelper.getFluidInContainer(itemstack);
return fluid != null && resourceTank.accepts(fluid);
}
return false;