Merge branch 'dev' of github.com:ForestryMC/ForestryMC into inventory-cleanup

Conflicts:
	src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java
	src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java
	src/main/java/forestry/core/gui/ContainerForestry.java
	src/main/java/forestry/energy/gadgets/EngineBronze.java
	src/main/java/forestry/energy/gadgets/MachineGenerator.java
	src/main/java/forestry/factory/gadgets/MachineBottler.java
	src/main/java/forestry/factory/gadgets/MachineCarpenter.java
	src/main/java/forestry/factory/gadgets/MachineFabricator.java
	src/main/java/forestry/factory/gadgets/MachineFermenter.java
	src/main/java/forestry/factory/gadgets/MachineMoistener.java
	src/main/java/forestry/factory/gadgets/MachineRaintank.java
	src/main/java/forestry/factory/gadgets/MachineStill.java
	src/main/java/forestry/factory/gadgets/TileWorktable.java
	src/main/java/forestry/farming/gadgets/TileFarmPlain.java
	src/main/java/forestry/farming/gui/ContainerFarm.java
This commit is contained in:
CovertJaguar committed 2014-12-13 16:39:40 -08:00
commit 3326f4db03
71 files changed
+1449 -1557

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;
@@ -226,13 +227,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();
@@ -444,9 +439,15 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
if (slotIndex == SLOT_RESOURCE)
return FluidContainerRegistry.isEmptyContainer(itemstack);
<<<<<<< HEAD
if (slotIndex == SLOT_CAN) {
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
return container != null && RecipeManager.isInput(container.fluid);
=======
if(slotIndex == SLOT_CAN) {
FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemstack);
return RecipeManager.isInput(fluidStack);
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
}
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.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.inventory.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,41 @@ 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;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.utils.Utils;
import forestry.factory.gui.ContainerCarpenter;
public class MachineCarpenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
@@ -144,16 +151,28 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
@Override
public void addCrating(ItemStack itemStack) {
ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained(itemStack);
<<<<<<< HEAD
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(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(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[] { "#", '#', itemStack });
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
}
@Override
public void addCrating(String toCrate, ItemStack unpack, ItemStack crated) {
<<<<<<< HEAD
addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(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});
=======
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 });
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
}
@Override
@@ -320,22 +339,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;
TileInventoryAdapter accessibleInventory = getInternalInventory();
// 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,28 +10,14 @@
******************************************************************************/
package forestry.factory.gadgets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import forestry.api.core.EnumErrorCode;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
import forestry.api.recipes.IFabricatorManager;
import forestry.core.config.Defaults;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.gadgets.TileBase;
import forestry.core.gadgets.TilePowered;
import forestry.core.interfaces.ICrafter;
@@ -39,20 +25,38 @@ import forestry.core.interfaces.ICraftingPlan;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
<<<<<<< HEAD
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.inventory.InventoryAdapter;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class MachineFabricator extends TilePowered implements ICrafter, ISpecialInventory, ILiquidTankContainer {
/* RECIPE MANAGMENT */
public static class Recipe {
private final ItemStack plan;
private final FluidStack molten;
private final ShapedRecipeCustom internal;
@@ -62,20 +66,8 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
this.internal = internal;
}
public boolean matches(ItemStack plan) {
if (this.plan == null)
return true;
else if (plan == null)
return false;
if (this.plan.getItemDamage() == Defaults.WILDCARD)
return plan.getItem() == this.plan.getItem();
else
return plan.isItemEqual(this.plan);
}
public boolean matches(ItemStack plan, ItemStack[][] resources) {
if (!this.matches(plan))
if (this.plan != null && !StackUtils.isCraftingEquivalent(this.plan, plan))
return false;
return internal.matches(resources);
@@ -106,9 +98,9 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
}
public static class Smelting {
ItemStack resource;
FluidStack product;
int meltingPoint;
private final ItemStack resource;
private final FluidStack product;
private final int meltingPoint;
public Smelting(ItemStack resource, FluidStack molten, int meltingPoint) {
if(resource == null)
@@ -121,10 +113,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
this.meltingPoint = meltingPoint;
}
public boolean matches(ItemStack resource) {
return this.resource.isItemEqual(resource);
}
public boolean matches(FluidStack product) {
return this.product.isFluidEqual(product);
}
@@ -156,30 +144,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
smeltings.add(new Smelting(resource, molten, meltingPoint));
}
public static Recipe findMatchingRecipe(ItemStack plan) {
for (Recipe recipe : recipes)
if (recipe.matches(plan))
return recipe;
return null;
}
public static Recipe findMatchingRecipeIfSmelted(ItemStack plan, FluidStack liquid, ItemStack itemToMelt, ItemStack[] resources) {
Smelting smelting = findMatchingSmelting(itemToMelt);
if (smelting == null || (liquid != null && !smelting.matches(liquid)))
return findMatchingRecipe(plan, liquid, resources);
FluidStack liquidIfSmelted;
if (liquid != null) {
liquidIfSmelted = liquid.copy();
liquidIfSmelted.amount += smelting.getProduct().amount * itemToMelt.stackSize;
} else {
liquidIfSmelted = smelting.getProduct().copy();
liquidIfSmelted.amount *= itemToMelt.stackSize;
}
return findMatchingRecipe(plan, liquidIfSmelted, resources);
}
public static Recipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
ItemStack[][] gridResources = new ItemStack[3][3];
for (int i = 0; i < 3; i++)
@@ -207,7 +171,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
return null;
for (Smelting smelting : smeltings)
if (smelting.matches(resource))
if (StackUtils.isCraftingEquivalent(smelting.resource, resource))
return smelting;
return null;
@@ -233,7 +197,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
return recipeList;
}
}
/* CONSTANTS */
@@ -243,6 +206,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
public static final short SLOT_PLAN = 1;
public static final short SLOT_RESULT = 2;
public static final short SLOT_CRAFTING_1 = 3;
public static final short SLOT_CRAFTING_COUNT = 9;
public static final short SLOT_INVENTORY_1 = 12;
public static final short SLOT_INVENTORY_COUNT = 18;
@@ -372,20 +336,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
this.heat--;
}
public Object[] getPlan() {
if (inventory.getStackInSlot(SLOT_PLAN) == null)
return null;
Recipe myRecipe = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN));
if (myRecipe == null)
return null;
return myRecipe.internal.getIngredients();
}
private Recipe getRecipe() {
return RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(),
inventory.getStacks(SLOT_CRAFTING_1, 9));
ItemStack plan = inventory.getStackInSlot(SLOT_PLAN);
ItemStack[] crafting = inventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting);
}
/* ICRAFTER */
@@ -416,8 +370,8 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
FluidStack liquid = myRecipe.molten;
// Remove resources
if (removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, false)) {
removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, true);
if (removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT), player, false)) {
removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT), player, true);
moltenTank.drain(liquid.amount, true);
} else if (consumeRecipe) {
removeFromCraftMatrix(myRecipe);
@@ -463,9 +417,16 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
@Override
public boolean hasWork() {
Recipe recipe = RecipeManager.findMatchingRecipeIfSmelted(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(), inventory.getStackInSlot(SLOT_METAL),
inventory.getStacks(SLOT_CRAFTING_1, 9));
return recipe != null;
ItemStack itemToMelt = inventory.getStackInSlot(SLOT_METAL);
Smelting smelting = RecipeManager.findMatchingSmelting(itemToMelt);
FluidStack liquid = smelting.getProduct();
if (moltenTank.fill(liquid, false) > 0)
return true;
ItemStack plan = inventory.getStackInSlot(SLOT_PLAN);
ItemStack[] resources = inventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
return RecipeManager.findMatchingRecipe(plan, liquid, resources) != null;
}
public int getHeatScaled(int i) {
@@ -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;
@@ -28,30 +50,17 @@ import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
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 +144,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 +170,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 +258,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 +548,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;
@@ -26,8 +27,12 @@ import forestry.core.interfaces.IRenderableMachine;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import net.minecraft.entity.player.EntityPlayer;
@@ -38,7 +43,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 +208,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 +618,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.inventory.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,40 @@ 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;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
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 +139,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 +150,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 +269,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;
@@ -25,26 +43,14 @@ import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
=======
import forestry.core.utils.InventoryAdapter;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
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 +183,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 +331,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 +443,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;
@@ -10,23 +10,8 @@
******************************************************************************/
package forestry.factory.gadgets;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import forestry.api.core.ForestryAPI;
import forestry.api.core.INBTTagable;
import forestry.core.gadgets.TileBase;
import forestry.core.gui.ContainerDummy;
import forestry.core.interfaces.ICrafter;
import forestry.core.network.ForestryPacket;
import forestry.core.network.GuiId;
@@ -34,10 +19,23 @@ import forestry.core.network.PacketIds;
import forestry.core.network.PacketTileNBT;
import forestry.core.network.PacketTileUpdate;
import forestry.core.proxy.Proxies;
<<<<<<< HEAD
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.PlainInventory;
import forestry.core.utils.StackUtils;
import forestry.core.inventory.TileInventoryAdapter;
=======
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.RecipeUtil;
import forestry.core.utils.TileInventoryAdapter;
import forestry.factory.recipes.RecipeMemory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
>>>>>>> 5ea4770a2d5fef57cf52fb7c81f33671f8086740
public class TileWorktable extends TileBase implements ICrafter {
@@ -47,298 +45,9 @@ public class TileWorktable extends TileBase implements ICrafter {
public final static int SLOT_CRAFTING_RESULT = 9;
public final static short SLOT_INVENTORY_1 = 0;
public final static short SLOT_INVENTORY_COUNT = 18;
private final static Container DUMMY_CONTAINER = new ContainerDummy();
private final static RecipeBridge RECIPE_BRIDGE = new RecipeBridge();
private static class RecipeBridge {
public ItemStack findMatchingRecipe(InventoryCrafting crafting, World world) {
return CraftingManager.getInstance().findMatchingRecipe(crafting, world);
}
}
/* RECIPE MEMORY */
public static final class Recipe implements INBTTagable {
private InventoryAdapter matrix;
private long lastUsed;
private boolean locked;
private World cachedWorld;
private ItemStack cachedRecipeOutput;
public Recipe(InventoryCrafting crafting) {
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
}
public Recipe(NBTTagCompound nbttagcompound) {
readFromNBT(nbttagcompound);
}
public void setCacheWorld(World world) {
this.cachedWorld = world;
}
private boolean updateCachedRecipeOutput() {
if (cachedRecipeOutput != null)
return true;
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
for (int i = 0; i < crafting.getSizeInventory(); i++) {
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
cachedRecipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, cachedWorld);
return cachedRecipeOutput != null;
}
public void updateLastUse(World world) {
lastUsed = world.getTotalWorldTime();
setCacheWorld(world);
}
public void toogleLock() {
locked = !locked;
}
public InventoryAdapter getMatrix() {
return matrix;
}
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) {
if (updateCachedRecipeOutput())
return cachedRecipeOutput;
return null;
}
public ItemStack getRecipeOutput() {
if (updateCachedRecipeOutput())
return cachedRecipeOutput;
return null;
}
public long getLastUsed() {
return this.lastUsed;
}
public boolean isLocked() {
return this.locked;
}
public int getRecipeSize() {
return matrix.getSizeInventory();
}
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
if (!updateCachedRecipeOutput())
return false;
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, world);
return ItemStack.areItemStacksEqual(cachedRecipeOutput, recipeOutput);
}
@Override
public final void readFromNBT(NBTTagCompound nbttagcompound) {
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
matrix.readFromNBT(nbttagcompound);
sanitizeMatrix();
lastUsed = nbttagcompound.getLong("LastUsed");
locked = nbttagcompound.getBoolean("Locked");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
sanitizeMatrix();
matrix.writeToNBT(nbttagcompound);
nbttagcompound.setLong("LastUsed", lastUsed);
nbttagcompound.setBoolean("Locked", locked);
}
/**
* This is a nasty hack to hide a bug where the recipe stacks somehow
* get the stackSize set to -1. Which makes the recipe no longer work,
* ever. I've seen the bug, even inspected the NBT data of an afflicted
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
*/
private void sanitizeMatrix() {
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
ItemStack stack = matrix.getStackInSlot(slot);
if (stack != null)
stack.stackSize = 1;
}
}
}
public static class RecipeMemory implements INBTTagable, IInventory {
private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
private long lastUpdate;
public final int capacity = 9;
public long getLastUpdate() {
return lastUpdate;
}
public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) {
lastUpdate = world.getTotalWorldTime();
recipe.updateLastUse(world);
Recipe memory = getMemorized(crafting, world);
if (memory != null) {
int index = recipes.indexOf(memory);
recipes.set(index, recipe);
return;
}
if (recipes.size() < capacity) {
recipes.add(recipe);
return;
}
Recipe oldest = null;
for (Recipe existing : recipes) {
if (oldest != null && oldest.getLastUsed() < existing.getLastUsed())
continue;
if (existing.isLocked())
continue;
oldest = existing;
}
if (oldest != null) {
recipes.remove(oldest);
recipes.add(recipe);
}
}
public Recipe getRecipe(int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex);
return null;
}
public ItemStack getRecipeOutput(int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex).getRecipeOutput();
else
return null;
}
public boolean isLocked(int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex).isLocked();
return false;
}
public void toggleLock(World world, int recipeIndex) {
lastUpdate = world.getTotalWorldTime();
if (recipes.size() > recipeIndex)
recipes.get(recipeIndex).toogleLock();
}
private Recipe getMemorized(InventoryCrafting crafting, World world) {
for (Recipe recipe : recipes) {
if (recipe.hasSameOutput(crafting, world))
return recipe;
}
return null;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
recipes = new LinkedList<Recipe>();
if (!nbttagcompound.hasKey("RecipeMemory"))
return;
NBTTagList nbttaglist = nbttagcompound.getTagList("RecipeMemory", 10);
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
recipes.add(new Recipe(nbttagcompound2));
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
NBTTagList nbttaglist = new NBTTagList();
for (Recipe recipe : recipes) {
if (recipe != null) {
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
recipe.writeToNBT(nbttagcompound2);
nbttaglist.appendTag(nbttagcompound2);
}
}
nbttagcompound.setTag("RecipeMemory", nbttaglist);
}
@Override
public int getSizeInventory() {
return recipes.size();
}
@Override
public ItemStack getStackInSlot(int i) {
return getRecipeOutput(i);
}
@Override
public ItemStack decrStackSize(int i, int j) {
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
}
@Override
public String getInventoryName() {
return "";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public void markDirty() {
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return false;
}
}
/* MEMBERS */
private Recipe currentRecipe;
private RecipeMemory.Recipe currentRecipe;
private InventoryCrafting currentCrafting;
private final RecipeMemory memorized;
private final TileInventoryAdapter craftingInventory;
@@ -393,6 +102,12 @@ public class TileWorktable extends TileBase implements ICrafter {
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
}
@Override
public void validate() {
super.validate();
memorized.validate(worldObj);
}
/* RECIPE SELECTION */
public RecipeMemory getMemory() {
return memorized;
@@ -406,9 +121,7 @@ public class TileWorktable extends TileBase implements ICrafter {
return;
}
Recipe recipe = memorized.getRecipe(recipeIndex);
recipe.sanitizeMatrix();
IInventory matrix = recipe.getMatrix();
IInventory matrix = memorized.getRecipeMatrix(recipeIndex);
if (matrix == null)
return;
@@ -420,20 +133,20 @@ public class TileWorktable extends TileBase implements ICrafter {
/* CRAFTING */
public void setRecipe(InventoryCrafting crafting) {
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, worldObj);
ItemStack recipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, worldObj);
if (recipeOutput == null) {
currentRecipe = null;
currentCrafting = null;
} else {
currentRecipe = new Recipe(crafting);
currentRecipe = new RecipeMemory.Recipe(crafting);
currentCrafting = crafting;
}
updateCraftResult(currentCrafting);
updateCraftResult();
}
private void updateCraftResult(InventoryCrafting inventorycrafting) {
private void updateCraftResult() {
if (currentRecipe != null) {
ItemStack result = currentRecipe.getCraftingResult(inventorycrafting);
ItemStack result = currentRecipe.getRecipeOutput(worldObj);
if (result != null) {
craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy());
return;
@@ -447,56 +160,11 @@ public class TileWorktable extends TileBase implements ICrafter {
if (currentRecipe == null)
return false;
// Need at least one matched set
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
if (StackUtils.containsSets(set, stock, true, true) == 0)
return false;
ItemStack[] recipeItems = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
ItemStack[] inventory = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj);
// Check that it doesn't make a different recipe.
// For example:
// Wood Logs are all ore dictionary equivalent with each other,
// but an Oak Log shouldn't be able to make Ebony Wood Planks
// because it makes Oak Wood Planks using the same recipe.
// Strategy:
// Create a fake crafting inventory using items we have in stock
// in place of the ones in the saved crafting inventory.
// Check that the recipe it makes is the same as the currentRecipe.
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
ItemStack[] stockCopy = StackUtils.condenseStacks(stock);
for (int slot = 0; slot < currentCrafting.getSizeInventory(); slot++) {
ItemStack recipeStack = currentCrafting.getStackInSlot(slot);
if (recipeStack == null)
continue;
// Use crafting equivalent (not oredict) items first
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
// Use oredict items if crafting equivalent items aren't available
if (crafting.getStackInSlot(slot) == null) {
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
}
}
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, worldObj);
if (recipeOutput == null)
return false;
return ItemStack.areItemStacksEqual(recipeOutput, currentRecipe.getRecipeOutput());
return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory);
}
private boolean removeResources(EntityPlayer player) {
@@ -519,8 +187,8 @@ public class TileWorktable extends TileBase implements ICrafter {
if (Proxies.common.isSimulating(worldObj))
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
updateCraftResult(currentCrafting);
return currentRecipe.getRecipeOutput().copy();
updateCraftResult();
return currentRecipe.getRecipeOutput(worldObj).copy();
}
@Override
@@ -528,8 +196,8 @@ public class TileWorktable extends TileBase implements ICrafter {
if (currentRecipe == null)
return null;
if (currentRecipe.getRecipeOutput() != null)
return currentRecipe.getRecipeOutput().copy();
if (currentRecipe.getRecipeOutput(worldObj) != null)
return currentRecipe.getRecipeOutput(worldObj).copy();
return null;
}
@@ -20,7 +20,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
private final MachineFabricator tile;
public ContainerFabricator(InventoryPlayer player, MachineFabricator tile) {
public ContainerFabricator(InventoryPlayer playerInventory, MachineFabricator tile) {
super(tile, tile);
this.tile = tile;
@@ -36,7 +36,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
this.addSlot(new Slot(tile, MachineFabricator.SLOT_PLAN, 139, 17));
// Result
this.addSlot(new SlotCrafter(tile, tile, MachineFabricator.SLOT_RESULT, 139, 53));
this.addSlot(new SlotCrafter(playerInventory.player, tile, tile, MachineFabricator.SLOT_RESULT, 139, 53));
// Crafting matrix
for (int l = 0; l < 3; l++)
@@ -46,10 +46,10 @@ public class ContainerFabricator extends ContainerLiquidTanks {
// Player inventory
for (int i = 0; i < 3; i++)
for (int k = 0; k < 9; k++)
addSlot(new Slot(player, k + i * 9 + 9, 8 + k * 18, 129 + i * 18));
addSlot(new Slot(playerInventory, k + i * 9 + 9, 8 + k * 18, 129 + i * 18));
// Player hotbar
for (int j = 0; j < 9; j++)
addSlot(new Slot(player, j, 8 + j * 18, 187));
addSlot(new Slot(playerInventory, j, 8 + j * 18, 187));
}
@@ -60,7 +60,7 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC
}
// CraftResult display
addSlot(new SlotCrafter(craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38));
addSlot(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38));
// Player inventory
for (int i1 = 0; i1 < 3; i1++) {
@@ -22,6 +22,7 @@ import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
@@ -29,14 +30,16 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
private class MemorizedSlot extends Widget {
private final int slotNumber;
private final World world;
public MemorizedSlot(WidgetManager manager, int xPos, int yPos, int slot) {
public MemorizedSlot(World world, WidgetManager manager, int xPos, int yPos, int slot) {
super(manager, xPos, yPos);
this.slotNumber = slot;
this.world = world;
}
private ItemStack getOutputStack() {
return worktable.getMemory().getRecipeOutput(slotNumber);
return worktable.getMemory().getRecipeOutput(world, slotNumber);
}
@Override
@@ -111,7 +114,7 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
int yPos = 20 + (y * spacing);
for (int x = 0; x < 3; x++) {
int xPos = 110 + (x * spacing);
widgetManager.add(new MemorizedSlot(widgetManager, xPos, yPos, slot));
widgetManager.add(new MemorizedSlot(player.getEntityWorld(), widgetManager, xPos, yPos, slot));
slot += 1;
}
}
@@ -0,0 +1,259 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import forestry.api.core.INBTTagable;
import forestry.core.gui.ContainerDummy;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.PlainInventory;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemMap;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class RecipeMemory implements INBTTagable {
public static final class Recipe implements INBTTagable {
private InventoryAdapter matrix;
private long lastUsed;
private boolean locked;
private ItemStack cachedRecipeOutput;
public Recipe(InventoryCrafting crafting) {
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
}
public Recipe(NBTTagCompound nbttagcompound) {
readFromNBT(nbttagcompound);
}
public void updateLastUse(long lastUsed) {
this.lastUsed = lastUsed;
}
public void toggleLock() {
locked = !locked;
}
public InventoryAdapter getMatrix() {
return matrix;
}
public ItemStack getRecipeOutput(World world) {
if (cachedRecipeOutput == null) {
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
for (int i = 0; i < crafting.getSizeInventory(); i++) {
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
cachedRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
}
return cachedRecipeOutput;
}
public long getLastUsed() {
return this.lastUsed;
}
public boolean isLocked() {
return this.locked;
}
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
ItemStack recipeOutput = getRecipeOutput(world);
if (recipeOutput == null)
return false;
ItemStack matchingRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
return ItemStack.areItemStacksEqual(recipeOutput, matchingRecipeOutput);
}
@Override
public final void readFromNBT(NBTTagCompound nbttagcompound) {
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
matrix.readFromNBT(nbttagcompound);
sanitizeMatrix();
lastUsed = nbttagcompound.getLong("LastUsed");
locked = nbttagcompound.getBoolean("Locked");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
sanitizeMatrix();
matrix.writeToNBT(nbttagcompound);
nbttagcompound.setLong("LastUsed", lastUsed);
nbttagcompound.setBoolean("Locked", locked);
}
/**
* This is a nasty hack to hide a bug where the recipe stacks somehow
* get the stackSize set to -1. Which makes the recipe no longer work,
* ever. I've seen the bug, even inspected the NBT data of an afflicted
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
*/
private void sanitizeMatrix() {
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
ItemStack stack = matrix.getStackInSlot(slot);
if (stack != null)
stack.stackSize = 1;
}
}
}
private static final Container DUMMY_CONTAINER = new ContainerDummy();
private static final List<Class<? extends Item>> memoryBlacklist = new ArrayList<Class<? extends Item>>();
static {
memoryBlacklist.add(ItemMap.class); // almost every ItemMap is unique
}
private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
private long lastUpdate;
public final int capacity = 9;
private static boolean isValid(World world, Recipe recipe) {
if (recipe == null)
return false;
ItemStack recipeOutput = recipe.getRecipeOutput(world);
if (recipeOutput == null)
return false;
Item item = recipeOutput.getItem();
return item != null && !memoryBlacklist.contains(item.getClass());
}
public void validate(World world) {
LinkedList<Recipe> validRecipes = new LinkedList<Recipe>();
for (Recipe recipe : recipes) {
if (isValid(world, recipe))
validRecipes.add(recipe);
}
this.recipes = validRecipes;
}
public long getLastUpdate() {
return lastUpdate;
}
public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) {
if (!isValid(world, recipe))
return;
lastUpdate = world.getTotalWorldTime();
recipe.updateLastUse(lastUpdate);
Recipe memory = getMemorized(crafting, world);
if (memory != null) {
int index = recipes.indexOf(memory);
recipes.set(index, recipe);
return;
}
if (recipes.size() < capacity) {
recipes.add(recipe);
return;
}
Recipe oldest = null;
for (Recipe existing : recipes) {
if (oldest != null && oldest.getLastUsed() < existing.getLastUsed())
continue;
if (existing.isLocked())
continue;
oldest = existing;
}
if (oldest != null) {
recipes.remove(oldest);
recipes.add(recipe);
}
}
public Recipe getRecipe(int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex);
return null;
}
public IInventory getRecipeMatrix(int recipeIndex) {
RecipeMemory.Recipe recipe = getRecipe(recipeIndex);
recipe.sanitizeMatrix();
return recipe.getMatrix();
}
public ItemStack getRecipeOutput(World world, int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex).getRecipeOutput(world);
else
return null;
}
public boolean isLocked(int recipeIndex) {
if (recipes.size() > recipeIndex)
return recipes.get(recipeIndex).isLocked();
return false;
}
public void toggleLock(World world, int recipeIndex) {
lastUpdate = world.getTotalWorldTime();
if (recipes.size() > recipeIndex)
recipes.get(recipeIndex).toggleLock();
}
private Recipe getMemorized(InventoryCrafting crafting, World world) {
for (Recipe recipe : recipes) {
if (recipe.hasSameOutput(crafting, world))
return recipe;
}
return null;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
recipes = new LinkedList<Recipe>();
if (!nbttagcompound.hasKey("RecipeMemory"))
return;
NBTTagList nbttaglist = nbttagcompound.getTagList("RecipeMemory", 10);
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
recipes.add(new Recipe(nbttagcompound2));
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
NBTTagList nbttaglist = new NBTTagList();
for (Recipe recipe : recipes) {
if (recipe != null) {
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
recipe.writeToNBT(nbttagcompound2);
nbttaglist.appendTag(nbttagcompound2);
}
}
nbttagcompound.setTag("RecipeMemory", nbttaglist);
}
}