mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
More Inventory rewrite stuff.
This commit is contained in:
1 parent
3326f4db03
commit
792ab77a48
23 files changed
+805
-1346
No files matched your search
@@ -251,6 +251,10 @@ public final class FluidHelper {
|
||||
|
||||
return FluidContainerRegistry.drainFluidContainer(container);
|
||||
}
|
||||
|
||||
public static ItemStack getFullyDrainedContainer(ItemStack container) {
|
||||
return container.getItem().getContainerItem(container);
|
||||
}
|
||||
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
if (fluid == null)
|
||||
|
||||
@@ -33,7 +33,6 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import buildcraft.api.transport.PipeManager;
|
||||
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.core.inventory.filters.ArrayStackFilter;
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
@@ -45,7 +44,6 @@ import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.inventory.wrappers.SidedInventoryMapper;
|
||||
import forestry.core.inventory.wrappers.SpecialInventoryMapper;
|
||||
import forestry.core.utils.PlainInventory;
|
||||
|
||||
public abstract class InvTools {
|
||||
@@ -130,9 +128,7 @@ public abstract class InvTools {
|
||||
public boolean matches(TileEntity tile) {
|
||||
if (type != null && !type.isAssignableFrom(tile.getClass()))
|
||||
return false;
|
||||
if (exclude != null && exclude.isAssignableFrom(tile.getClass()))
|
||||
return false;
|
||||
return true;
|
||||
return !(exclude != null && exclude.isAssignableFrom(tile.getClass()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -161,10 +157,7 @@ public abstract class InvTools {
|
||||
public static IInventory getInventory(IInventory inv, ForgeDirection side) {
|
||||
if (inv == null)
|
||||
return null;
|
||||
|
||||
if (inv instanceof ISpecialInventory)
|
||||
inv = new SpecialInventoryMapper((ISpecialInventory) inv, side);
|
||||
else if (inv instanceof ISidedInventory)
|
||||
if (inv instanceof ISidedInventory)
|
||||
inv = new SidedInventoryMapper((ISidedInventory) inv, side);
|
||||
return inv;
|
||||
}
|
||||
@@ -318,9 +311,8 @@ public abstract class InvTools {
|
||||
return countItems(inv);
|
||||
|
||||
int count = 0;
|
||||
ItemStack stack = null;
|
||||
for (int slot = 0; slot < inv.getSizeInventory(); slot++) {
|
||||
stack = inv.getStackInSlot(slot);
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null)
|
||||
for (ItemStack filter : filters) {
|
||||
if (filter != null && isItemEqual(stack, filter)) {
|
||||
@@ -392,7 +384,7 @@ public abstract class InvTools {
|
||||
*
|
||||
* @param source
|
||||
* @param dest
|
||||
* @param filer an ItemStack[] to match against
|
||||
* @param filters an ItemStack[] to match against
|
||||
* @return null if nothing was moved, the stack moved otherwise
|
||||
*/
|
||||
public static ItemStack moveOneItem(IInventory source, IInventory dest, ItemStack... filters) {
|
||||
@@ -404,7 +396,7 @@ public abstract class InvTools {
|
||||
*
|
||||
* @param source
|
||||
* @param dest
|
||||
* @param filer an IItemType to match against
|
||||
* @param filter an IItemType to match against
|
||||
* @return null if nothing was moved, the stack moved otherwise
|
||||
*/
|
||||
public static ItemStack moveOneItem(IInventory source, IInventory dest, IStackFilter filter) {
|
||||
@@ -434,7 +426,7 @@ public abstract class InvTools {
|
||||
*
|
||||
* @param sources
|
||||
* @param dest
|
||||
* @param filters
|
||||
* @param filter
|
||||
* @return
|
||||
*/
|
||||
public static ItemStack moveOneItem(Collection<IInventory> sources, IInventory dest, IStackFilter filter) {
|
||||
@@ -449,8 +441,8 @@ public abstract class InvTools {
|
||||
/**
|
||||
* Attempts to move one item to a collection of inventories.
|
||||
*
|
||||
* @param sources
|
||||
* @param dest
|
||||
* @param source
|
||||
* @param destinations
|
||||
* @param filters
|
||||
* @return
|
||||
*/
|
||||
@@ -470,7 +462,7 @@ public abstract class InvTools {
|
||||
*
|
||||
* @param source
|
||||
* @param dest
|
||||
* @param filer an ItemStack[] to exclude
|
||||
* @param filters an ItemStack[] to exclude
|
||||
* @return null if nothing was moved, the stack moved otherwise
|
||||
*/
|
||||
public static ItemStack moveOneItemExcept(IInventory source, IInventory dest, ItemStack... filters) {
|
||||
@@ -497,8 +489,8 @@ public abstract class InvTools {
|
||||
/**
|
||||
* Attempts to move one item to a collection of inventories.
|
||||
*
|
||||
* @param sources
|
||||
* @param dest
|
||||
* @param source
|
||||
* @param destinations
|
||||
* @param filters
|
||||
* @return
|
||||
*/
|
||||
@@ -750,7 +742,7 @@ public abstract class InvTools {
|
||||
* Removes and returns a single item from the inventory that matches the
|
||||
* filter.
|
||||
*
|
||||
* @param inv The inventory
|
||||
* @param invs The inventory
|
||||
* @param filter EnumItemType to match against
|
||||
* @return An ItemStack
|
||||
*/
|
||||
|
||||
@@ -30,9 +30,6 @@ public class InventoryManipulator {
|
||||
private final IInventory inv;
|
||||
|
||||
public static InventoryManipulator get(IInventory inv) {
|
||||
if (inv instanceof ISpecialInventory) {
|
||||
return new SpecialManipulator((ISpecialInventory) inv);
|
||||
}
|
||||
return new InventoryManipulator(inv);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.inventory.manipulators;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class SpecialManipulator extends InventoryManipulator {
|
||||
|
||||
private final ISpecialInventory inv;
|
||||
protected ForgeDirection side = ForgeDirection.UNKNOWN;
|
||||
|
||||
protected SpecialManipulator(ISpecialInventory inv) {
|
||||
super(inv);
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public void setSide(ForgeDirection side) {
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack tryAddStack(ItemStack stack) {
|
||||
return addStackInternal(stack, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addStack(ItemStack stack) {
|
||||
return addStackInternal(stack, true);
|
||||
}
|
||||
|
||||
private ItemStack addStackInternal(ItemStack stack, boolean doAdd) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
stack = stack.copy();
|
||||
int used = inv.addItem(stack.copy(), doAdd, side);
|
||||
if (used >= stack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
stack.stackSize -= used;
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveItem(IStackFilter filter) {
|
||||
return tryRemoveItem(filter) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack tryRemoveItem(IStackFilter filter) {
|
||||
return removeStackInternal(filter, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(IStackFilter filter) {
|
||||
return removeStackInternal(filter, true);
|
||||
}
|
||||
|
||||
protected ItemStack removeStackInternal(IStackFilter filter, boolean doRemove) {
|
||||
ItemStack[] extracted = inv.extractItem(false, side, 1);
|
||||
if (extracted != null && extracted.length > 0 && filter.matches(extracted[0])) {
|
||||
if (doRemove) {
|
||||
inv.extractItem(true, side, 1);
|
||||
}
|
||||
return extracted[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack moveItem(IInventory dest, IStackFilter filter) {
|
||||
InventoryManipulator imDest = InventoryManipulator.get(dest);
|
||||
ItemStack stack = tryRemoveItem(filter);
|
||||
if (stack != null) {
|
||||
ItemStack result = imDest.addStack(stack);
|
||||
if (result == null) {
|
||||
return removeItem(filter);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.inventory.wrappers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class SpecialInventoryMapper extends InventoryMapper implements ISpecialInventory
|
||||
{
|
||||
|
||||
private final ISpecialInventory inv;
|
||||
protected final ForgeDirection side;
|
||||
|
||||
public SpecialInventoryMapper(ISpecialInventory inv, ForgeDirection side)
|
||||
{
|
||||
super(inv, side);
|
||||
this.inv = inv;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from)
|
||||
{
|
||||
return inv.addItem(stack, doAdd, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount)
|
||||
{
|
||||
return inv.extractItem(doRemove, side, maxItemCount);
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,9 @@ import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
|
||||
public class StackUtils {
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
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;
|
||||
@@ -42,7 +40,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
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;
|
||||
@@ -439,15 +436,9 @@ 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;
|
||||
|
||||
@@ -338,11 +338,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.factory.gadgets;
|
||||
|
||||
import forestry.api.core.EnumErrorCode;
|
||||
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;
|
||||
@@ -23,18 +22,15 @@ import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.ICraftingPlan;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
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 forestry.core.utils.Utils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -51,11 +47,13 @@ import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
||||
public class MachineFabricator extends TilePowered implements ICrafter, ISpecialInventory, ILiquidTankContainer {
|
||||
public class MachineFabricator extends TilePowered implements ICrafter, ILiquidTankContainer, ISidedInventory {
|
||||
|
||||
/* RECIPE MANAGMENT */
|
||||
public static class Recipe {
|
||||
|
||||
private final ItemStack plan;
|
||||
private final FluidStack molten;
|
||||
private final ShapedRecipeCustom internal;
|
||||
@@ -74,7 +72,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
}
|
||||
|
||||
public boolean hasLiquid(FluidStack resource) {
|
||||
if(resource == null)
|
||||
if (resource == null)
|
||||
return molten == null;
|
||||
|
||||
if (!resource.isFluidEqual(molten))
|
||||
@@ -98,14 +96,15 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
}
|
||||
|
||||
public static class Smelting {
|
||||
|
||||
private final ItemStack resource;
|
||||
private final FluidStack product;
|
||||
private final int meltingPoint;
|
||||
|
||||
public Smelting(ItemStack resource, FluidStack molten, int meltingPoint) {
|
||||
if(resource == null)
|
||||
if (resource == null)
|
||||
throw new IllegalArgumentException("Resource cannot be null");
|
||||
if(molten == null)
|
||||
if (molten == null)
|
||||
throw new IllegalArgumentException("Molten cannot be null");
|
||||
|
||||
this.resource = resource;
|
||||
@@ -131,6 +130,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
}
|
||||
|
||||
public static class RecipeManager implements IFabricatorManager {
|
||||
|
||||
public static final ArrayList<Recipe> recipes = new ArrayList<Recipe>();
|
||||
public static final ArrayList<Smelting> smeltings = new ArrayList<Smelting>();
|
||||
|
||||
@@ -146,22 +146,26 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
public static Recipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
|
||||
ItemStack[][] gridResources = new ItemStack[3][3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
gridResources[j][i] = resources[i * 3 + j];
|
||||
}
|
||||
}
|
||||
|
||||
for (Recipe recipe : recipes)
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.matches(plan, gridResources))
|
||||
if (recipe.hasLiquid(liquid))
|
||||
return recipe;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isResourceLiquid(FluidStack liquid) {
|
||||
for (Recipe recipe : recipes)
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.hasLiquid(liquid))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -170,9 +174,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
if (resource == null)
|
||||
return null;
|
||||
|
||||
for (Smelting smelting : smeltings)
|
||||
for (Smelting smelting : smeltings) {
|
||||
if (StackUtils.isCraftingEquivalent(smelting.resource, resource))
|
||||
return smelting;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -181,9 +186,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
if (product == null)
|
||||
return null;
|
||||
|
||||
for (Smelting smelting : smeltings)
|
||||
for (Smelting smelting : smeltings) {
|
||||
if (smelting.matches(product))
|
||||
return smelting;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -192,8 +198,9 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
public Map<Object[], Object[]> getRecipes() {
|
||||
HashMap<Object[], Object[]> recipeList = new HashMap<Object[], Object[]>();
|
||||
|
||||
for (Recipe recipe : recipes)
|
||||
recipeList.put(recipe.internal.getIngredients(), new Object[] { recipe.internal.getRecipeOutput() });
|
||||
for (Recipe recipe : recipes) {
|
||||
recipeList.put(recipe.internal.getIngredients(), new Object[]{recipe.internal.getRecipeOutput()});
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
}
|
||||
@@ -211,9 +218,9 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
public static final short SLOT_INVENTORY_COUNT = 18;
|
||||
|
||||
/* MEMBER */
|
||||
private final InventoryMapper invCrafting;
|
||||
private final TankManager tankManager;
|
||||
private FilteredTank moltenTank;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(30, "Items");
|
||||
private final FilteredTank moltenTank;
|
||||
private int heat = 0;
|
||||
private int guiMeltingPoint = 0;
|
||||
|
||||
@@ -221,6 +228,8 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
public MachineFabricator() {
|
||||
super(1100, 50, 3300);
|
||||
setInternalInventory(new TileInventoryAdapter(this, 30, "Items"));
|
||||
invCrafting = new InventoryMapper(getInternalInventory(), SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
Fluid liquidGlass = FluidRegistry.getFluid(Defaults.LIQUID_GLASS);
|
||||
moltenTank = new FilteredTank(2 * Defaults.BUCKET_VOLUME, liquidGlass);
|
||||
moltenTank.tankMode = StandardTank.TankMode.INTERNAL;
|
||||
@@ -253,9 +262,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
pendingSmelt.writeToNBT(smelt);
|
||||
nbttagcompound.setTag("PendingSmelt", smelt);
|
||||
}
|
||||
|
||||
// / Inventory
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,14 +279,12 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
pendingSmelt = FluidStack.loadFluidStackFromNBT(smelt);
|
||||
}
|
||||
|
||||
// / Inventory
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Add pending smelt
|
||||
if (pendingSmelt != null) {
|
||||
|
||||
@@ -306,11 +310,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
this.dissipateHeat();
|
||||
|
||||
if (energyManager.getTotalEnergyStored() == 0 && heat == 0) {
|
||||
if (energyManager.getTotalEnergyStored() == 0 && heat == 0)
|
||||
setErrorState(EnumErrorCode.NOPOWER);
|
||||
} else if (getErrorState() == EnumErrorCode.NOPOWER) {
|
||||
else if (getErrorState() == EnumErrorCode.NOPOWER)
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,6 +340,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
}
|
||||
|
||||
private Recipe getRecipe() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack plan = inventory.getStackInSlot(SLOT_PLAN);
|
||||
ItemStack[] crafting = inventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting);
|
||||
@@ -360,7 +364,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
@Override
|
||||
public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) {
|
||||
if(slotIndex != SLOT_RESULT)
|
||||
if (slotIndex != SLOT_RESULT)
|
||||
return null;
|
||||
|
||||
Recipe myRecipe = getRecipe();
|
||||
@@ -369,6 +373,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
FluidStack liquid = myRecipe.molten;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Remove resources
|
||||
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);
|
||||
@@ -392,19 +397,19 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
}
|
||||
|
||||
private void removeFromCraftMatrix(Recipe recipe) {
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (inventory.getStackInSlot(SLOT_CRAFTING_1 + i) == null)
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(invCrafting)) {
|
||||
if (slot.getStackInSlot() == null)
|
||||
continue;
|
||||
inventory.decrStackSize(SLOT_CRAFTING_1 + i, 1);
|
||||
slot.decreaseStackInSlot();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean removeFromInventory(int count, ItemStack[] set, EntityPlayer player, boolean doRemove) {
|
||||
if (doRemove) {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (doRemove)
|
||||
return inventory.removeSets(count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
} else {
|
||||
else {
|
||||
ItemStack[] stock = inventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
return StackUtils.containsSets(set, stock) >= count;
|
||||
}
|
||||
@@ -417,6 +422,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack itemToMelt = inventory.getStackInSlot(SLOT_METAL);
|
||||
Smelting smelting = RecipeManager.findMatchingSmelting(itemToMelt);
|
||||
FluidStack liquid = smelting.getProduct();
|
||||
@@ -476,59 +482,35 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
iCrafting.sendProgressBarUpdate(container, messageId + 1, getMeltingPoint());
|
||||
}
|
||||
|
||||
// / ISPECIALINVENTORY
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
if (from == ForgeDirection.UP && RecipeManager.findMatchingSmelting(stack) != null)
|
||||
return inventory.addStack(stack, SLOT_METAL, 1, false, doAdd);
|
||||
return inventory.addStack(stack, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, false, doAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack taken;
|
||||
if (doRemove) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
taken = this.takenFromSlot(SLOT_RESULT, false, player);
|
||||
} else {
|
||||
taken = this.getResult();
|
||||
}
|
||||
|
||||
if (taken != null)
|
||||
return new ItemStack[] { taken };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
||||
// / IINVENTORY
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return inventory.getStackInSlot(i);
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return inventory.decrStackSize(i, j);
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
inventory.setInventorySlotContents(i, itemstack);
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -539,28 +521,41 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack stack) {
|
||||
if (!getInternalInventory().isItemValidForSlot(slotIndex, stack))
|
||||
return false;
|
||||
if (slotIndex == SLOT_METAL && RecipeManager.findMatchingSmelting(stack) == null)
|
||||
return false;
|
||||
return slotIndex >= SLOT_INVENTORY_1 && slotIndex < SLOT_INVENTORY_1 + SLOT_INVENTORY_COUNT;
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public boolean canInsertItem(int slotIndex, ItemStack stack, int side) {
|
||||
return isItemValidForSlot(slotIndex, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, stack, side))
|
||||
return false;
|
||||
return slotIndex == SLOT_RESULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
|
||||
@@ -50,17 +50,11 @@ 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 buildcraft.api.statements.ITriggerExternal;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
|
||||
public class MachineFermenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -160,11 +154,10 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
Recipe recipe = recipes.get(i);
|
||||
if (recipe.resource.getItemDamage() == Defaults.WILDCARD
|
||||
&& recipe.resource.getItem() == resource.getItem()) {
|
||||
&& recipe.resource.getItem() == resource.getItem())
|
||||
return true;
|
||||
} else if (recipe.resource.isItemEqual(resource)) {
|
||||
else if (recipe.resource.isItemEqual(resource))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -184,7 +177,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
HashMap<Object[], Object[]> recipeList = new HashMap<Object[], Object[]>();
|
||||
|
||||
for (Recipe recipe : recipes) {
|
||||
recipeList.put(new Object[] { recipe.resource, recipe.liquid }, new Object[] { recipe.output });
|
||||
recipeList.put(new Object[]{recipe.resource, recipe.liquid}, new Object[]{recipe.output});
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
@@ -197,7 +190,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(5, "Items");
|
||||
private Recipe currentRecipe;
|
||||
private float currentResourceModifier;
|
||||
public int fermentationTime = 0;
|
||||
@@ -208,6 +200,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
public MachineFermenter() {
|
||||
super(2000, 150, 8000);
|
||||
setInternalInventory(new TileInventoryAdapter(this, 5, "Items"));
|
||||
setHints(Config.hints.get("fermenter"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
|
||||
resourceTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
@@ -237,7 +230,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
nbttagcompound.setInteger("FuelCurrentFerment", fuelCurrentFerment);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
}
|
||||
|
||||
@@ -252,7 +244,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
fuelCurrentFerment = nbttagcompound.getInteger("FuelCurrentFerment");
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,10 +252,10 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0)
|
||||
return;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_INPUT) != null) {
|
||||
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) {
|
||||
@@ -273,12 +264,12 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid());
|
||||
}
|
||||
|
||||
if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null) {
|
||||
if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null)
|
||||
if (resourceTank.getFluidAmount() < fuelCurrentFerment)
|
||||
setErrorState(EnumErrorCode.NORESOURCE);
|
||||
else
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
} else if (inventory.getStackInSlot(SLOT_FUEL) == null && fuelBurnTime <= 0)
|
||||
else if (inventory.getStackInSlot(SLOT_FUEL) == null && fuelBurnTime <= 0)
|
||||
setErrorState(EnumErrorCode.NOFUEL);
|
||||
else if (energyManager.getTotalEnergyStored() == 0)
|
||||
setErrorState(EnumErrorCode.NOPOWER);
|
||||
@@ -293,6 +284,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
checkRecipe();
|
||||
resetRecipe();
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (currentRecipe != null) {
|
||||
currentResourceModifier = determineResourceMod(inventory.getStackInSlot(SLOT_RESOURCE));
|
||||
decrStackSize(SLOT_RESOURCE, 1);
|
||||
@@ -313,9 +305,8 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
// input are checked, add output if possible
|
||||
if (!addProduct(new FluidStack(currentRecipe.output,
|
||||
Math.round(fermented * currentRecipe.modifier * currentResourceModifier)))) {
|
||||
Math.round(fermented * currentRecipe.modifier * currentResourceModifier))))
|
||||
return false; // the output tank is too full, TODO: check/add error code?
|
||||
}
|
||||
|
||||
fuelBurnTime--;
|
||||
resourceTank.drain(fuelCurrentFerment, true);
|
||||
@@ -350,12 +341,12 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
productTank.fill(output, true);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRecipe() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid());
|
||||
|
||||
if (currentRecipe != sameRec)
|
||||
@@ -408,13 +399,14 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
@Override
|
||||
public boolean isWorking() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (currentRecipe == null
|
||||
&& RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null)
|
||||
return false;
|
||||
if (fuelBurnTime > 0)
|
||||
return resourceTank.getFluidAmount() > 0 && productTank.getFluidAmount() < Defaults.PROCESSOR_TANK_CAPACITY;
|
||||
else
|
||||
return determineFuelValue(getFuelStack()) > 0;
|
||||
else
|
||||
return determineFuelValue(getFuelStack()) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -435,6 +427,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (this.getFuelStack() == null && fuelBurnTime <= 0)
|
||||
return false;
|
||||
else if (fuelBurnTime <= 0)
|
||||
@@ -489,14 +482,15 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
public ItemStack getFermentationStack() {
|
||||
return inventory.getStackInSlot(SLOT_RESOURCE);
|
||||
return getInternalInventory().getStackInSlot(SLOT_RESOURCE);
|
||||
}
|
||||
|
||||
public ItemStack getFuelStack() {
|
||||
return inventory.getStackInSlot(SLOT_FUEL);
|
||||
return getInternalInventory().getStackInSlot(SLOT_FUEL);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
|
||||
@@ -506,10 +500,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
fuelTotalTime = j;
|
||||
else if (i == firstMessageId + 2)
|
||||
fermentationTime = j;
|
||||
else if (i == firstMessageId + 3)
|
||||
else if (i == firstMessageId + 3)
|
||||
fermentationTotalTime = j;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
|
||||
@@ -520,75 +515,34 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
/* INVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if (!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if (slotIndex == SLOT_CAN_OUTPUT)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if (!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if (slotIndex == SLOT_RESOURCE && RecipeManager.isResource(itemstack))
|
||||
return true;
|
||||
|
||||
|
||||
if (slotIndex == SLOT_INPUT) {
|
||||
FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemstack);
|
||||
return RecipeManager.isLiquidResource(fluidStack);
|
||||
}
|
||||
|
||||
if (slotIndex == SLOT_CAN_INPUT && FluidHelper.isEmptyContainer(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
if (slotIndex == SLOT_FUEL && FuelManager.fermenterFuel.containsKey(itemstack))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return inventory.getStackInSlot(i);
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return inventory.decrStackSize(i, j);
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
inventory.setInventorySlotContents(i, itemstack);
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -599,52 +553,51 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
if (slotIndex == SLOT_RESOURCE && RecipeManager.isResource(itemstack))
|
||||
return true;
|
||||
|
||||
if (slotIndex == SLOT_INPUT) {
|
||||
FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemstack);
|
||||
return RecipeManager.isLiquidResource(fluidStack);
|
||||
}
|
||||
|
||||
if (slotIndex == SLOT_CAN_INPUT && FluidHelper.isEmptyContainer(itemstack))
|
||||
return true;
|
||||
return slotIndex == SLOT_FUEL && FuelManager.fermenterFuel.containsKey(itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_CAN_OUTPUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ILiquidTankContainer */
|
||||
@@ -678,6 +631,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import static cpw.mods.fml.relauncher.FMLLaunchHandler.side;
|
||||
import forestry.api.core.EnumErrorCode;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.fuels.FuelManager;
|
||||
import forestry.api.fuels.MoistenerFuel;
|
||||
import forestry.api.recipes.IMoistenerManager;
|
||||
@@ -24,15 +24,10 @@ import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
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;
|
||||
@@ -51,7 +46,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineMoistener extends TileBase implements ISpecialInventory, ISidedInventory, ILiquidTankContainer, IRenderableMachine {
|
||||
public class MachineMoistener extends TileBase implements ISidedInventory, ILiquidTankContainer, IRenderableMachine {
|
||||
|
||||
/* CONSTANTS */
|
||||
private static final short SLOT_STASH_1 = 0;
|
||||
@@ -64,16 +59,17 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
|
||||
/* RECIPE MANAGMENT */
|
||||
public static class Recipe {
|
||||
|
||||
public final int timePerItem;
|
||||
public final ItemStack resource;
|
||||
public final ItemStack product;
|
||||
|
||||
|
||||
public Recipe(ItemStack resource, ItemStack product, int timePerItem) {
|
||||
this.timePerItem = timePerItem;
|
||||
this.resource = resource;
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
|
||||
public boolean matches(ItemStack res) {
|
||||
if (res == null && resource == null)
|
||||
return true;
|
||||
@@ -83,27 +79,28 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
return resource.isItemEqual(res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RecipeManager implements IMoistenerManager {
|
||||
|
||||
public static final ArrayList<MachineMoistener.Recipe> recipes = new ArrayList<MachineMoistener.Recipe>();
|
||||
|
||||
|
||||
@Override
|
||||
public void addRecipe(ItemStack resource, ItemStack product, int timePerItem) {
|
||||
recipes.add(new MachineMoistener.Recipe(resource, product, timePerItem));
|
||||
}
|
||||
|
||||
|
||||
public static boolean isResource(ItemStack resource) {
|
||||
if(resource == null)
|
||||
if (resource == null)
|
||||
return false;
|
||||
|
||||
for(Recipe rec : recipes) {
|
||||
if(StackUtils.isIdenticalItem(resource, rec.resource))
|
||||
|
||||
for (Recipe rec : recipes) {
|
||||
if (StackUtils.isIdenticalItem(resource, rec.resource))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static Recipe findMatchingRecipe(ItemStack item) {
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
Recipe recipe = recipes.get(i);
|
||||
@@ -112,43 +109,44 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Object[], Object[]> getRecipes() {
|
||||
HashMap<Object[], Object[]> recipeList = new HashMap<Object[], Object[]>();
|
||||
|
||||
for (Recipe recipe : recipes)
|
||||
recipeList.put(new ItemStack[] { recipe.resource }, new ItemStack[] { recipe.product });
|
||||
|
||||
|
||||
for (Recipe recipe : recipes) {
|
||||
recipeList.put(new ItemStack[]{recipe.resource}, new ItemStack[]{recipe.product});
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EntityNetData
|
||||
public final FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(12, "Items");
|
||||
//private ItemStack[] inventoryStacks = new ItemStack[12];
|
||||
public MachineMoistener.Recipe currentRecipe;
|
||||
|
||||
|
||||
public int burnTime = 0;
|
||||
public int totalTime = 0;
|
||||
public int productionTime = 0;
|
||||
private int timePerItem = 0;
|
||||
private ItemStack currentProduct;
|
||||
private ItemStack pendingProduct;
|
||||
|
||||
|
||||
public MachineMoistener() {
|
||||
setInternalInventory(new TileInventoryAdapter(this, 12, "Items"));
|
||||
setHints(Config.hints.get("moistener"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(resourceTank);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void openGui(EntityPlayer player, TileBase tile) {
|
||||
player.openGui(ForestryAPI.instance, GuiId.MoistenerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord);
|
||||
@@ -158,13 +156,12 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
|
||||
nbttagcompound.setInteger("BurnTime", burnTime);
|
||||
nbttagcompound.setInteger("TotalTime", totalTime);
|
||||
nbttagcompound.setInteger("ProductionTime", productionTime);
|
||||
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
// Write pending product
|
||||
if (pendingProduct != null) {
|
||||
@@ -178,17 +175,16 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
nbttagcompound.setTag("CurrentProduct", nbttagcompoundP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
|
||||
burnTime = nbttagcompound.getInteger("BurnTime");
|
||||
totalTime = nbttagcompound.getInteger("TotalTime");
|
||||
productionTime = nbttagcompound.getInteger("ProductionTime");
|
||||
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
// Load pending product
|
||||
if (nbttagcompound.hasKey("PendingProduct")) {
|
||||
@@ -199,17 +195,17 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
NBTTagCompound nbttagcompoundP = nbttagcompound.getCompoundTag("CurrentProduct");
|
||||
currentProduct = ItemStack.loadItemStackFromNBT(nbttagcompoundP);
|
||||
}
|
||||
|
||||
|
||||
checkRecipe();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Check if we have suitable water container waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_PRODUCT) != null) {
|
||||
if (inventory.getStackInSlot(SLOT_PRODUCT) != null)
|
||||
FluidHelper.drainContainers(tankManager, inventory, SLOT_PRODUCT);
|
||||
}
|
||||
|
||||
// Let's get to work
|
||||
int lightvalue = worldObj.getBlockLightValue(xCoord, yCoord + 1, zCoord);
|
||||
@@ -236,67 +232,68 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
// Not working if there is no water available.
|
||||
if (resourceTank.getFluidAmount() <= 0)
|
||||
return;
|
||||
|
||||
|
||||
checkRecipe();
|
||||
|
||||
|
||||
if (currentRecipe == null)
|
||||
return;
|
||||
|
||||
|
||||
resourceTank.drain(1, true);
|
||||
burnTime -= speed;
|
||||
productionTime -= speed;
|
||||
|
||||
|
||||
if (productionTime <= 0) {
|
||||
pendingProduct = currentProduct;
|
||||
decrStackSize(SLOT_RESOURCE, 1);
|
||||
resetRecipe();
|
||||
tryAddPending();
|
||||
}
|
||||
|
||||
|
||||
} else if (pendingProduct != null)
|
||||
tryAddPending();
|
||||
// Try to start process
|
||||
else // Make sure we have a new item in the working slot.
|
||||
if (rotateWorkingSlot()) {
|
||||
checkRecipe();
|
||||
|
||||
// Let's see if we have a valid resource in the working slot
|
||||
if (inventory.getStackInSlot(SLOT_WORKING) == null)
|
||||
return;
|
||||
|
||||
if (FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(SLOT_WORKING))) {
|
||||
MoistenerFuel res = FuelManager.moistenerResource.get(inventory.getStackInSlot(SLOT_WORKING));
|
||||
burnTime = totalTime = res.moistenerValue;
|
||||
}
|
||||
} else
|
||||
rotateReservoir();
|
||||
if (rotateWorkingSlot()) {
|
||||
checkRecipe();
|
||||
|
||||
// Let's see if we have a valid resource in the working slot
|
||||
if (inventory.getStackInSlot(SLOT_WORKING) == null)
|
||||
return;
|
||||
|
||||
if (FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(SLOT_WORKING))) {
|
||||
MoistenerFuel res = FuelManager.moistenerResource.get(inventory.getStackInSlot(SLOT_WORKING));
|
||||
burnTime = totalTime = res.moistenerValue;
|
||||
}
|
||||
} else
|
||||
rotateReservoir();
|
||||
|
||||
if (currentRecipe != null)
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
else
|
||||
setErrorState(EnumErrorCode.NORECIPE);
|
||||
}
|
||||
|
||||
|
||||
private boolean tryAddPending() {
|
||||
if (pendingProduct == null)
|
||||
return false;
|
||||
|
||||
if(inventory.tryAddStack(pendingProduct, SLOT_PRODUCT, 1, true)) {
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.tryAddStack(pendingProduct, SLOT_PRODUCT, 1, true)) {
|
||||
pendingProduct = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void checkRecipe() {
|
||||
Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE));
|
||||
Recipe sameRec = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE));
|
||||
if (currentRecipe != sameRec) {
|
||||
currentRecipe = sameRec;
|
||||
resetRecipe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resetRecipe() {
|
||||
if (currentRecipe == null) {
|
||||
currentProduct = null;
|
||||
@@ -305,15 +302,16 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
setErrorState(EnumErrorCode.NORECIPE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
currentProduct = currentRecipe.product;
|
||||
productionTime = currentRecipe.timePerItem;
|
||||
timePerItem = currentRecipe.timePerItem;
|
||||
}
|
||||
|
||||
|
||||
private int getFreeSlot(ItemStack deposit, int startSlot, int endSlot, boolean emptyOnly) {
|
||||
int slot = -1;
|
||||
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStackInSlot(i);
|
||||
// Empty slots are okay.
|
||||
@@ -322,53 +320,55 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
slot = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (emptyOnly)
|
||||
continue;
|
||||
|
||||
// Wrong item or full
|
||||
if (!slotStack.isItemEqual(deposit) || slotStack.stackSize >= slotStack.getMaxStackSize())
|
||||
continue;
|
||||
|
||||
|
||||
slot = i;
|
||||
}
|
||||
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
|
||||
private int getFreeStashSlot(ItemStack deposit, boolean emptyOnly) {
|
||||
return getFreeSlot(deposit, 0, SLOT_RESERVOIR_1, emptyOnly);
|
||||
}
|
||||
|
||||
|
||||
private int getFreeReservoirSlot(ItemStack deposit) {
|
||||
return getFreeSlot(deposit, SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOTS_COUNT_RESERVOIR, false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private int getNextResourceSlot(int startSlot, int endSlot) {
|
||||
// Let's look for a new resource to put into the working slot.
|
||||
int stage = -1;
|
||||
int resourceSlot = -1;
|
||||
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStackInSlot(i);
|
||||
if (slotStack == null)
|
||||
continue;
|
||||
|
||||
|
||||
if (!FuelManager.moistenerResource.containsKey(slotStack))
|
||||
continue;
|
||||
|
||||
|
||||
MoistenerFuel res = FuelManager.moistenerResource.get(slotStack);
|
||||
if (stage < 0 || res.stage < stage) {
|
||||
stage = res.stage;
|
||||
resourceSlot = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return resourceSlot;
|
||||
}
|
||||
|
||||
private boolean rotateWorkingSlot() {
|
||||
|
||||
private boolean rotateWorkingSlot() {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Put working slot contents into inventory if space is available
|
||||
if (inventory.getStackInSlot(SLOT_WORKING) != null) {
|
||||
// Get the result of the consumed item in the working slot
|
||||
@@ -378,20 +378,20 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
deposit = res.product.copy();
|
||||
} else
|
||||
deposit = inventory.getStackInSlot(SLOT_WORKING).copy();
|
||||
|
||||
|
||||
int targetSlot = getFreeReservoirSlot(deposit);
|
||||
// We stop the whole thing, if we don't have any room anymore.
|
||||
if (targetSlot < 0)
|
||||
return false;
|
||||
|
||||
|
||||
if (inventory.getStackInSlot(targetSlot) == null)
|
||||
inventory.setInventorySlotContents(targetSlot, deposit);
|
||||
else
|
||||
inventory.getStackInSlot(targetSlot).stackSize++;
|
||||
|
||||
|
||||
decrStackSize(SLOT_WORKING, 1);
|
||||
}
|
||||
|
||||
|
||||
if (inventory.getStackInSlot(SLOT_WORKING) != null)
|
||||
return true;
|
||||
|
||||
@@ -400,18 +400,20 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
// Nothing found, stop.
|
||||
if (resourceSlot < 0)
|
||||
return false;
|
||||
|
||||
|
||||
inventory.setInventorySlotContents(SLOT_WORKING, inventory.decrStackSize(resourceSlot, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void rotateReservoir() {
|
||||
ArrayList<Integer> slotsToShift = new ArrayList<Integer>();
|
||||
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
|
||||
for (int i = SLOT_RESERVOIR_1; i < SLOT_RESERVOIR_1 + SLOTS_COUNT_RESERVOIR; i++) {
|
||||
if (inventory.getStackInSlot(i) == null)
|
||||
continue;
|
||||
|
||||
|
||||
if (!FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(i)))
|
||||
slotsToShift.add(i);
|
||||
}
|
||||
@@ -423,7 +425,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
int targetSlot = getFreeStashSlot(slotStack, true);
|
||||
if (targetSlot < 0)
|
||||
continue;
|
||||
|
||||
|
||||
inventory.setInventorySlotContents(targetSlot, slotStack);
|
||||
inventory.setInventorySlotContents(slot, null);
|
||||
shiftedSlots++;
|
||||
@@ -450,15 +452,16 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isWorking() {
|
||||
return burnTime > 0 && resourceTank.getFluidAmount() > 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasFuelMin(float percentage) {
|
||||
int max = 0;
|
||||
int avail = 0;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
|
||||
for (int i = SLOT_STASH_1; i < SLOT_RESERVOIR_1; i++) {
|
||||
if (inventory.getStackInSlot(i) == null) {
|
||||
max += 64;
|
||||
@@ -472,37 +475,38 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ((float) avail / (float) max) > percentage;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasResourcesMin(float percentage) {
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.getStackInSlot(SLOT_RESOURCE) == null)
|
||||
return false;
|
||||
|
||||
|
||||
return ((float) inventory.getStackInSlot(SLOT_RESOURCE).stackSize / (float) inventory.getStackInSlot(SLOT_RESOURCE).getMaxStackSize()) > percentage;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProducing() {
|
||||
return productionTime > 0;
|
||||
}
|
||||
|
||||
|
||||
public int getProductionProgressScaled(int i) {
|
||||
if (timePerItem == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
return (productionTime * i) / timePerItem;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getConsumptionProgressScaled(int i) {
|
||||
if (totalTime == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
return (burnTime * i) / totalTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getResourceScaled(int i) {
|
||||
return (resourceTank.getFluidAmount() * i) / Defaults.PROCESSOR_TANK_CAPACITY;
|
||||
}
|
||||
@@ -512,153 +516,100 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
public EnumTankLevel getPrimaryLevel() {
|
||||
return Utils.rateTankLevel(getResourceScaled(100));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EnumTankLevel getSecondaryLevel() {
|
||||
return EnumTankLevel.EMPTY;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override public int getSizeInventory() { return inventory.getSizeInventory(); }
|
||||
@Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); }
|
||||
@Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); }
|
||||
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); }
|
||||
@Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); }
|
||||
@Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); }
|
||||
@Override public void openInventory() {}
|
||||
@Override public void closeInventory() {}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
|
||||
if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
if (slotIndex == SLOT_RESOURCE)
|
||||
return RecipeManager.isResource(itemstack);
|
||||
|
||||
if (slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH - 2)
|
||||
return FuelManager.moistenerResource.containsKey(itemstack);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if(slotIndex == SLOT_PRODUCT)
|
||||
|
||||
if (slotIndex == SLOT_PRODUCT)
|
||||
return true;
|
||||
|
||||
if(slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH) {
|
||||
|
||||
if (slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH)
|
||||
return !FuelManager.moistenerResource.containsKey(itemstack);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if(slotIndex == SLOT_RESOURCE)
|
||||
return RecipeManager.isResource(itemstack);
|
||||
|
||||
if(slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH - 2) {
|
||||
return FuelManager.moistenerResource.containsKey(itemstack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
|
||||
Fluid fluid = FluidHelper.getFluidInContainer(stack);
|
||||
if (fluid != null && resourceTank.accepts(fluid)) {
|
||||
return inventory.addStack(stack, SLOT_PRODUCT, 1, false, doAdd);
|
||||
}
|
||||
|
||||
// Try to add to resource slot if input is from top or bottom.
|
||||
if (from == ForgeDirection.UP || from == ForgeDirection.DOWN) {
|
||||
return inventory.addStack(stack, SLOT_RESOURCE, 1, false, doAdd);
|
||||
}
|
||||
|
||||
return inventory.addStack(stack, SLOT_STASH_1, SLOTS_COUNT_STASH - 2, false, doAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack product;
|
||||
|
||||
ItemStack slotStack = inventory.getStackInSlot(SLOT_PRODUCT);
|
||||
if (slotStack != null && slotStack.stackSize > 0) {
|
||||
|
||||
product = new ItemStack(slotStack.getItem(), 1, slotStack.getItemDamage());
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(SLOT_PRODUCT, 1);
|
||||
}
|
||||
return new ItemStack[] { product };
|
||||
} else
|
||||
for (int i = 0; i < SLOT_RESERVOIR_1; i++) {
|
||||
slotStack = inventory.getStackInSlot(i);
|
||||
if (slotStack == null)
|
||||
continue;
|
||||
|
||||
if (!FuelManager.moistenerResource.containsKey(slotStack)) {
|
||||
product = new ItemStack(slotStack.getItem(), 1, slotStack.getItemDamage());
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(i, 1);
|
||||
}
|
||||
return new ItemStack[] { product };
|
||||
}
|
||||
}
|
||||
|
||||
return StackUtils.EMPTY_STACK_ARRAY;
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ILiquidTankContainer */
|
||||
@@ -666,40 +617,42 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return tankManager.drain(from, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return tankManager.canFill(from, fluid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return tankManager.canDrain(from, fluid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
burnTime = j;
|
||||
@@ -715,7 +668,8 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, burnTime);
|
||||
@@ -723,5 +677,5 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi
|
||||
iCrafting.sendProgressBarUpdate(container, i + 2, productionTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 3, timePerItem);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -34,14 +34,10 @@ import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
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;
|
||||
|
||||
@@ -55,12 +51,12 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
/* MEMBER */
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(3, "Items");
|
||||
private boolean isValidBiome = true;
|
||||
private int fillingTime;
|
||||
private ItemStack usedEmpty;
|
||||
|
||||
public MachineRaintank() {
|
||||
setInternalInventory(new TileInventoryAdapter(this, 3, "Items"));
|
||||
setHints(Config.hints.get("raintank"));
|
||||
|
||||
resourceTank = new FilteredTank(Defaults.RAINTANK_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
@@ -98,7 +94,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
nbttagcompound.setBoolean("IsValidBiome", isValidBiome);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,7 +103,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
isValidBiome = nbttagcompound.getBoolean("IsValidBiome");
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,6 +121,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
if (worldObj.getTotalWorldTime() % 16 != 0)
|
||||
return;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (!StackUtils.isIdenticalItem(usedEmpty, inventory.getStackInSlot(SLOT_RESOURCE))) {
|
||||
fillingTime = 0;
|
||||
usedEmpty = null;
|
||||
@@ -150,7 +145,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
|
||||
private void tryToStartFillling() {
|
||||
// Nothing to do if no empty cans are available
|
||||
if (!FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get(), false))
|
||||
if (!FluidHelper.fillContainers(tankManager, getInternalInventory(), SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get(), false))
|
||||
return;
|
||||
|
||||
fillingTime = Defaults.RAINTANK_FILLING_TIME;
|
||||
@@ -163,32 +158,32 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return inventory.getStackInSlot(i);
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return inventory.decrStackSize(i, j);
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
inventory.setInventorySlotContents(i, itemstack);
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,71 +194,19 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_PRODUCT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
if (slotIndex != SLOT_RESOURCE)
|
||||
@@ -272,7 +215,27 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
return FluidHelper.isFillableContainer(itemstack, STACK_WATER);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_PRODUCT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
@@ -282,6 +245,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, fillingTime);
|
||||
@@ -318,6 +282,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ 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.inventory.TileInventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -40,7 +40,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
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;
|
||||
|
||||
@@ -51,7 +50,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class MachineSqueezer extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
public class MachineSqueezer extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
/* CONSTANTS */
|
||||
private static final short SLOT_RESOURCE_1 = 0;
|
||||
@@ -62,6 +61,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
/* RECIPE MANAGMENT */
|
||||
public static class Recipe {
|
||||
|
||||
public final int timePerItem;
|
||||
public final ItemStack[] resources;
|
||||
public final FluidStack liquid;
|
||||
@@ -82,6 +82,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
public static class RecipeManager implements ISqueezerManager {
|
||||
|
||||
public static final ArrayList<MachineSqueezer.Recipe> recipes = new ArrayList<MachineSqueezer.Recipe>();
|
||||
public static final HashSet<Fluid> recipeFluids = new HashSet<Fluid>();
|
||||
public static final HashSet<ItemStack> recipeInputs = new HashSet<ItemStack>();
|
||||
@@ -112,9 +113,10 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
public static boolean canUse(ItemStack itemStack) {
|
||||
if (recipeInputs.contains(itemStack))
|
||||
return true;
|
||||
for (ItemStack recipeInput : recipeInputs)
|
||||
for (ItemStack recipeInput : recipeInputs) {
|
||||
if (StackUtils.isCraftingEquivalent(recipeInput, itemStack))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -122,8 +124,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
public Map<Object[], Object[]> getRecipes() {
|
||||
HashMap<Object[], Object[]> recipeList = new HashMap<Object[], Object[]>();
|
||||
|
||||
for (Recipe recipe : recipes)
|
||||
recipeList.put(recipe.resources, new Object[] { recipe.remnants, recipe.liquid });
|
||||
for (Recipe recipe : recipes) {
|
||||
recipeList.put(recipe.resources, new Object[]{recipe.remnants, recipe.liquid});
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
}
|
||||
@@ -134,7 +137,6 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
@EntityNetData
|
||||
public final FilteredTank productTank;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(12, "Items");
|
||||
private Recipe currentRecipe;
|
||||
|
||||
private final Stack<FluidStack> pendingLiquids = new Stack<FluidStack>();
|
||||
@@ -144,6 +146,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
public MachineSqueezer() {
|
||||
super(1100, 50, 4000);
|
||||
setInternalInventory(new TileInventoryAdapter(this, 12, "Items"));
|
||||
setHints(Config.hints.get("squeezer"));
|
||||
productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids);
|
||||
productTank.tankMode = StandardTank.TankMode.OUTPUT;
|
||||
@@ -168,31 +171,30 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
nbttagcompound.setInteger("ProductionTime", productionTime);
|
||||
nbttagcompound.setInteger("TimePerItem", timePerItem);
|
||||
|
||||
// Inventory
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
// Pending remnants
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
ItemStack[] remnants = pendingRemnants.toArray(new ItemStack[pendingRemnants.size()]);
|
||||
for (int i = 0; i < remnants.length; i++)
|
||||
for (int i = 0; i < remnants.length; i++) {
|
||||
if (remnants[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
remnants[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
nbttagcompound.setTag("PendingRemnants", nbttaglist);
|
||||
|
||||
// Pending liquids
|
||||
nbttaglist = new NBTTagList();
|
||||
FluidStack[] liquids = pendingLiquids.toArray(new FluidStack[pendingLiquids.size()]);
|
||||
for (int i = 0; i < liquids.length; i++)
|
||||
for (int i = 0; i < liquids.length; i++) {
|
||||
if (liquids[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
liquids[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
nbttagcompound.setTag("PendingLiquids", nbttaglist);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
@@ -205,9 +207,6 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
productionTime = nbttagcompound.getInteger("ProductionTime");
|
||||
timePerItem = nbttagcompound.getInteger("TimePerItem");
|
||||
|
||||
// Inventory
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
// Pending remnants
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("PendingRemnants", 10);
|
||||
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
@@ -234,6 +233,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0)
|
||||
return;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Can/capsule input/output needs to be handled here.
|
||||
if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
|
||||
FluidStack fluidStack = productTank.getFluid();
|
||||
@@ -294,7 +294,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
private void checkRecipe() {
|
||||
Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStacks(SLOT_RESOURCE_1, 9));
|
||||
Recipe sameRec = RecipeManager.findMatchingRecipe(getInternalInventory().getStacks(SLOT_RESOURCE_1, 9));
|
||||
|
||||
if (sameRec == null)
|
||||
setErrorState(EnumErrorCode.NORECIPE);
|
||||
@@ -349,12 +349,12 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
private boolean addRemnant(ItemStack stack) {
|
||||
return inventory.tryAddStack(stack, SLOT_REMNANT, 1, true);
|
||||
return getInternalInventory().tryAddStack(stack, SLOT_REMNANT, 1, true);
|
||||
}
|
||||
|
||||
private boolean removeResources(ItemStack[] stacks) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
return inventory.removeSets(1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile());
|
||||
return getInternalInventory().removeSets(1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -384,6 +384,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
@@ -396,6 +397,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, productionTime);
|
||||
@@ -403,39 +405,63 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override public int getSizeInventory() { return inventory.getSizeInventory(); }
|
||||
@Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); }
|
||||
@Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); }
|
||||
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); }
|
||||
@Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); }
|
||||
@Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); }
|
||||
@Override public void openInventory() {}
|
||||
@Override public void closeInventory() {}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
public int getSizeInventory() {
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
if(!getInternalInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
if(slotIndex == SLOT_CAN_INPUT) {
|
||||
if (slotIndex == SLOT_CAN_INPUT)
|
||||
return FluidHelper.isEmptyContainer(itemstack);
|
||||
}
|
||||
|
||||
if(slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) {
|
||||
if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) {
|
||||
if (FluidHelper.isEmptyContainer(itemstack))
|
||||
return false;
|
||||
|
||||
@@ -446,90 +472,23 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_CAN_INPUT || (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT);
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
|
||||
// Try to add to can slot if input is from top or bottom.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack product;
|
||||
|
||||
if (inventory.getStackInSlot(SLOT_CAN_OUTPUT) != null) {
|
||||
|
||||
product = new ItemStack(inventory.getStackInSlot(SLOT_CAN_OUTPUT).getItem(), 1, inventory.getStackInSlot(SLOT_CAN_OUTPUT).getItemDamage());
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(SLOT_CAN_OUTPUT, 1);
|
||||
}
|
||||
return new ItemStack[] { product };
|
||||
} else {
|
||||
|
||||
if (inventory.getStackInSlot(SLOT_REMNANT) == null)
|
||||
return StackUtils.EMPTY_STACK_ARRAY;
|
||||
|
||||
product = new ItemStack(inventory.getStackInSlot(SLOT_REMNANT).getItem(), 1, inventory.getStackInSlot(SLOT_REMNANT).getItemDamage());
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(SLOT_REMNANT, 1);
|
||||
}
|
||||
return new ItemStack[] { product };
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER IMPLEMENTATION */
|
||||
@@ -543,6 +502,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,8 @@ 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.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
@@ -40,19 +38,13 @@ import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
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;
|
||||
|
||||
public class MachineStill extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
public class MachineStill extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final short SLOT_PRODUCT = 0;
|
||||
@@ -60,15 +52,16 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
public static final short SLOT_CAN = 2;
|
||||
|
||||
public static class Recipe {
|
||||
|
||||
public final int timePerUnit;
|
||||
public final FluidStack input;
|
||||
public final FluidStack output;
|
||||
|
||||
public Recipe(int timePerUnit, FluidStack input, FluidStack output) {
|
||||
this.timePerUnit = timePerUnit;
|
||||
if(input == null)
|
||||
if (input == null)
|
||||
throw new IllegalArgumentException("Still recipes need an input. Input was null.");
|
||||
if(output == null)
|
||||
if (output == null)
|
||||
throw new IllegalArgumentException("Still recipes need an output. Output was null.");
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
@@ -85,6 +78,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
}
|
||||
|
||||
public static class RecipeManager implements IStillManager {
|
||||
|
||||
public static final ArrayList<MachineStill.Recipe> recipes = new ArrayList<MachineStill.Recipe>();
|
||||
public static final HashSet<Fluid> recipeFluidInputs = new HashSet<Fluid>();
|
||||
public static final HashSet<Fluid> recipeFluidOutputs = new HashSet<Fluid>();
|
||||
@@ -115,8 +109,9 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
public Map<Object[], Object[]> getRecipes() {
|
||||
HashMap<Object[], Object[]> recipeList = new HashMap<Object[], Object[]>();
|
||||
|
||||
for (Recipe recipe : recipes)
|
||||
recipeList.put(new Object[] { recipe.input }, new Object[] { recipe.output });
|
||||
for (Recipe recipe : recipes) {
|
||||
recipeList.put(new Object[]{recipe.input}, new Object[]{recipe.output});
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
}
|
||||
@@ -129,8 +124,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
public final FilteredTank productTank;
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(3, "Items");
|
||||
|
||||
private Recipe currentRecipe;
|
||||
private FluidStack bufferedLiquid;
|
||||
public int distillationTime = 0;
|
||||
@@ -138,6 +131,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
public MachineStill() {
|
||||
super(1100, 50, 8000);
|
||||
setInternalInventory(new TileInventoryAdapter(this,3, "Items"));
|
||||
setHints(Config.hints.get("still"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
|
||||
resourceTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
@@ -164,7 +158,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
nbttagcompound.setInteger("DistillationTotalTime", distillationTotalTime);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,7 +168,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
distillationTotalTime = nbttagcompound.getInteger("DistillationTotalTime");
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
checkRecipe();
|
||||
}
|
||||
@@ -186,17 +178,16 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
|
||||
return;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null) {
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null)
|
||||
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
|
||||
}
|
||||
|
||||
// Can product liquid if possible
|
||||
if (inventory.getStackInSlot(SLOT_RESOURCE) != null) {
|
||||
FluidStack fluidStack = productTank.getFluid();
|
||||
if (fluidStack != null) {
|
||||
if (fluidStack != null)
|
||||
FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid());
|
||||
}
|
||||
}
|
||||
|
||||
checkRecipe();
|
||||
@@ -326,134 +317,91 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, distillationTotalTime);
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
int inventorySlot;
|
||||
|
||||
Fluid fluid = FluidHelper.getFluidInContainer(stack);
|
||||
if (fluid != null && resourceTank.accepts(fluid))
|
||||
inventorySlot = SLOT_CAN;
|
||||
else if (FluidHelper.isEmptyContainer(stack))
|
||||
inventorySlot = SLOT_RESOURCE;
|
||||
else
|
||||
return 0;
|
||||
|
||||
return inventory.addStack(stack, inventorySlot, 1, false, doAdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transport pipes cannot extract items from the still.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack product = null;
|
||||
|
||||
if (inventory.getStackInSlot(SLOT_PRODUCT) != null) {
|
||||
|
||||
product = new ItemStack(inventory.getStackInSlot(SLOT_PRODUCT).getItem(), 1, inventory.getStackInSlot(SLOT_PRODUCT).getItemDamage());
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(SLOT_PRODUCT, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (product != null)
|
||||
return new ItemStack[] { product };
|
||||
else
|
||||
return StackUtils.EMPTY_STACK_ARRAY;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override public int getSizeInventory() { return inventory.getSizeInventory(); }
|
||||
@Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); }
|
||||
@Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); }
|
||||
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); }
|
||||
@Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); }
|
||||
@Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); }
|
||||
@Override public void openInventory() {}
|
||||
@Override public void closeInventory() {}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return getInternalInventory().getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int value) {
|
||||
return getInternalInventory().decrStackSize(slot, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
getInternalInventory().setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_PRODUCT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if(slotIndex == SLOT_RESOURCE)
|
||||
if (slotIndex == SLOT_RESOURCE)
|
||||
return FluidHelper.isEmptyContainer(itemstack);
|
||||
|
||||
if(slotIndex == SLOT_CAN) {
|
||||
if (slotIndex == SLOT_CAN) {
|
||||
Fluid fluid = FluidHelper.getFluidInContainer(itemstack);
|
||||
return fluid != null && resourceTank.accepts(fluid);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getInternalInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex == SLOT_PRODUCT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return getInternalInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
/* IFluidHandler */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
@@ -484,6 +432,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
@@ -11,19 +11,15 @@
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.fuels.FuelManager;
|
||||
import forestry.api.fuels.RainSubstrate;
|
||||
import forestry.core.gadgets.Mill;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class MillRainmaker extends Mill implements ISpecialInventory {
|
||||
public class MillRainmaker extends Mill {
|
||||
|
||||
private int duration;
|
||||
private boolean reverse;
|
||||
@@ -32,11 +28,6 @@ public class MillRainmaker extends Mill implements ISpecialInventory {
|
||||
speed = 0.01f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGui(EntityPlayer player, TileBase tile) {
|
||||
if (!Proxies.common.isSimulating(player.worldObj))
|
||||
@@ -117,86 +108,78 @@ public class MillRainmaker extends Mill implements ISpecialInventory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
if (charge != 0)
|
||||
return 0;
|
||||
|
||||
if (!FuelManager.rainSubstrate.containsKey(stack))
|
||||
return 0;
|
||||
|
||||
RainSubstrate substrate = FuelManager.rainSubstrate.get(stack);
|
||||
if (!substrate.item.isItemEqual(stack))
|
||||
return 0;
|
||||
|
||||
if (doAdd)
|
||||
addCharge(substrate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
// TODO: Give Rainmaker a real inventory and a GUI with slots
|
||||
// @Override
|
||||
// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
// if (charge != 0)
|
||||
// return 0;
|
||||
//
|
||||
// if (!FuelManager.rainSubstrate.containsKey(stack))
|
||||
// return 0;
|
||||
//
|
||||
// RainSubstrate substrate = FuelManager.rainSubstrate.get(stack);
|
||||
// if (!substrate.item.isItemEqual(stack))
|
||||
// return 0;
|
||||
//
|
||||
// if (doAdd)
|
||||
// addCharge(substrate);
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getSizeInventory() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getStackInSlot(int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack decrStackSize(int var1, int var2) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInventorySlotContents(int var1, ItemStack var2) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getInventoryStackLimit() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void openInventory() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void closeInventory() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
// return Utils.isUseableByPlayer(player, this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasCustomInventoryName() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
@@ -13,21 +13,15 @@ package forestry.factory.gadgets;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.GuiId;
|
||||
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;
|
||||
@@ -35,7 +29,7 @@ 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 {
|
||||
|
||||
@@ -51,11 +45,10 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
private InventoryCrafting currentCrafting;
|
||||
private final RecipeMemory memorized;
|
||||
private final TileInventoryAdapter craftingInventory;
|
||||
private final TileInventoryAdapter accessibleInventory;
|
||||
|
||||
public TileWorktable() {
|
||||
craftingInventory = new TileInventoryAdapter(this, 10, "CraftItems");
|
||||
accessibleInventory = new TileInventoryAdapter(this, 18, "Items");
|
||||
setInternalInventory(new TileInventoryAdapter(this, 18, "Items"));
|
||||
|
||||
memorized = new RecipeMemory();
|
||||
}
|
||||
@@ -71,7 +64,6 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
craftingInventory.writeToNBT(nbttagcompound);
|
||||
accessibleInventory.writeToNBT(nbttagcompound);
|
||||
|
||||
memorized.writeToNBT(nbttagcompound);
|
||||
}
|
||||
@@ -81,7 +73,6 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
craftingInventory.readFromNBT(nbttagcompound);
|
||||
accessibleInventory.readFromNBT(nbttagcompound);
|
||||
|
||||
memorized.readFromNBT(nbttagcompound);
|
||||
}
|
||||
@@ -161,7 +152,7 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
return false;
|
||||
|
||||
ItemStack[] recipeItems = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
ItemStack[] inventory = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
ItemStack[] inventory = getInternalInventory().getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj);
|
||||
|
||||
return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory);
|
||||
@@ -169,7 +160,7 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
|
||||
private boolean removeResources(EntityPlayer player) {
|
||||
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
|
||||
return accessibleInventory.removeSets(1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
return getInternalInventory().removeSets(1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,12 +192,6 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* INVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return accessibleInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Inaccessible crafting inventory for the craft grid.
|
||||
*/
|
||||
|
||||
@@ -144,9 +144,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
if (isMaster)
|
||||
makeMaster();
|
||||
|
||||
if (inventory != null)
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
structureLogic.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -161,9 +158,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
|
||||
farmBlock.saveToCompound(nbttagcompound);
|
||||
|
||||
if (inventory != null)
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
structureLogic.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -225,9 +219,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* INVENTORY MANAGMENT */
|
||||
protected TileInventoryAdapter inventory;
|
||||
|
||||
/* TILEFORESTRY */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
@@ -329,7 +320,7 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
|
||||
@Override
|
||||
public IInventory getInventory() {
|
||||
return inventory;
|
||||
return getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -166,8 +166,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return;
|
||||
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
|
||||
if (getInternalInventory().getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidHelper.drainContainers(tankManager, getInternalInventory(), SLOT_CAN);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -350,7 +350,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
|
||||
protected void createInventory() {
|
||||
inventory = new TileInventoryAdapter(this, SLOT_COUNT, "Items");
|
||||
setInternalInventory(new TileInventoryAdapter(this, SLOT_COUNT, "Items"));
|
||||
FilteredTank liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(liquidTank);
|
||||
}
|
||||
@@ -364,7 +364,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
} else if (checkTimer.delayPassed(worldObj, 400))
|
||||
setExtents();
|
||||
|
||||
if (inventory == null)
|
||||
if (getInternalInventory() == null)
|
||||
createInventory();
|
||||
|
||||
// System.out.println("Targets set");
|
||||
@@ -526,7 +526,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
|
||||
private void addProduceToInventory(ItemStack produce) {
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
for (IFarmLogic logic : getFarmLogics()) {
|
||||
// Germlings try to go into germling slots first.
|
||||
if (logic.isAcceptedGermling(produce))
|
||||
@@ -576,6 +576,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : eventHandlers)
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
|
||||
// Stow harvest.
|
||||
for (ItemStack harvest : harvested) {
|
||||
@@ -606,7 +608,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return false;
|
||||
|
||||
ItemStack next = pendingProduce.peek();
|
||||
if (inventory.tryAddStack(next, SLOT_PRODUCTION_1, SLOT_COUNT_PRODUCTION, true, true)) {
|
||||
if (getInternalInventory().tryAddStack(next, SLOT_PRODUCTION_1, SLOT_COUNT_PRODUCTION, true, true)) {
|
||||
pendingProduce.pop();
|
||||
return true;
|
||||
}
|
||||
@@ -622,6 +624,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return;
|
||||
}
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack fertilizer = inventory.getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizer == null || fertilizer.stackSize <= 0)
|
||||
return;
|
||||
@@ -741,25 +744,25 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
return inventory.contains(resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS);
|
||||
return getInternalInventory().contains(resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS);
|
||||
}
|
||||
|
||||
public boolean hasResourcesAmount(int amount) {
|
||||
return inventory.containsAmount(amount, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS);
|
||||
return getInternalInventory().containsAmount(amount, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS);
|
||||
}
|
||||
|
||||
public boolean hasGermlingsPercent(float percent) {
|
||||
return inventory.containsPercent(percent, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS);
|
||||
return getInternalInventory().containsPercent(percent, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS);
|
||||
}
|
||||
|
||||
public boolean hasFertilizerPercent(float percent) {
|
||||
return inventory.containsPercent(percent, SLOT_FERTILIZER, 1);
|
||||
return getInternalInventory().containsPercent(percent, SLOT_FERTILIZER, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile());
|
||||
inventory.removeSets(1, resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS, player, false, true, true);
|
||||
getInternalInventory().removeSets(1, resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS, player, false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -773,12 +776,12 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
|
||||
public boolean hasGermlings(ItemStack[] germlings) {
|
||||
return inventory.contains(germlings, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS);
|
||||
return getInternalInventory().contains(germlings, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, int x, int y, int z) {
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
for (int i = SLOT_GERMLINGS_1; i < SLOT_GERMLINGS_1 + SLOT_COUNT_RESERVOIRS; i++) {
|
||||
if (inventory.getStackInSlot(i) == null)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,6 @@ import buildcraft.api.statements.ITriggerExternal;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.farming.triggers.FarmingTriggers;
|
||||
@@ -69,9 +68,11 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
private void dumpToPipe(ArrayList<ForgeDirection> pipes) {
|
||||
|
||||
ItemStack[] products = extractItem(true, ForgeDirection.DOWN, 1);
|
||||
for (ItemStack product : products)
|
||||
while (product.stackSize > 0)
|
||||
for (ItemStack product : products) {
|
||||
while (product.stackSize > 0) {
|
||||
BlockUtil.putFromStackIntoPipe(this, pipes, product);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,17 +119,11 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public InventoryAdapter getInternalInventory() {
|
||||
return (InventoryAdapter)getStructureInventory();
|
||||
}
|
||||
|
||||
private IInventory getStructureInventory() {
|
||||
|
||||
private ISidedInventory getStructureInventory() {
|
||||
if (hasMaster()) {
|
||||
ITileStructure central = getCentralTE();
|
||||
if (central != null)
|
||||
return central.getInventory();
|
||||
return (ISidedInventory) central.getInventory();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -186,46 +181,6 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if(!super.canTakeStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
if(slotIndex >= TileFarmPlain.SLOT_PRODUCTION_1 && slotIndex < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
|
||||
if (!hasMaster())
|
||||
return false;
|
||||
|
||||
ITileStructure struct = getCentralTE();
|
||||
if (!(struct instanceof TileFarmPlain))
|
||||
return false;
|
||||
|
||||
if(!super.canPutStackFromSide(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
TileFarmPlain housing = (TileFarmPlain) struct;
|
||||
if (slotIndex == TileFarmPlain.SLOT_FERTILIZER && housing.acceptsAsFertilizer(itemstack))
|
||||
return true;
|
||||
if (slotIndex >= TileFarmPlain.SLOT_RESOURCES_1 && slotIndex < TileFarmPlain.SLOT_RESOURCES_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS
|
||||
&& housing.acceptsAsResource(itemstack))
|
||||
return true;
|
||||
if (slotIndex >= TileFarmPlain.SLOT_GERMLINGS_1 && slotIndex < TileFarmPlain.SLOT_GERMLINGS_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS
|
||||
&& housing.acceptsAsGermling(itemstack))
|
||||
return true;
|
||||
if(slotIndex == TileFarmPlain.SLOT_CAN)
|
||||
return FluidContainerRegistry.isFilledContainer(itemstack);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
@@ -239,52 +194,59 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
if (!hasMaster())
|
||||
return false;
|
||||
|
||||
ITileStructure struct = getCentralTE();
|
||||
if (!(struct instanceof TileFarmPlain))
|
||||
return false;
|
||||
|
||||
if (!getStructureInventory().isItemValidForSlot(slotIndex, itemstack))
|
||||
return false;
|
||||
|
||||
TileFarmPlain housing = (TileFarmPlain) struct;
|
||||
if (slotIndex == TileFarmPlain.SLOT_FERTILIZER && housing.acceptsAsFertilizer(itemstack))
|
||||
return true;
|
||||
if (slotIndex >= TileFarmPlain.SLOT_RESOURCES_1 && slotIndex < TileFarmPlain.SLOT_RESOURCES_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS
|
||||
&& housing.acceptsAsResource(itemstack))
|
||||
return true;
|
||||
if (slotIndex >= TileFarmPlain.SLOT_GERMLINGS_1 && slotIndex < TileFarmPlain.SLOT_GERMLINGS_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS
|
||||
&& housing.acceptsAsGermling(itemstack))
|
||||
return true;
|
||||
if (slotIndex == TileFarmPlain.SLOT_CAN)
|
||||
return FluidContainerRegistry.isFilledContainer(itemstack);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
return isItemValidForSlot(xCoord, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
||||
if (!getStructureInventory().canExtractItem(slotIndex, itemstack, side))
|
||||
return false;
|
||||
|
||||
return slotIndex >= TileFarmPlain.SLOT_PRODUCTION_1 && slotIndex < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
return getStructureInventory().getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
@@ -316,7 +278,7 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
}
|
||||
|
||||
if (product != null)
|
||||
return new ItemStack[] { product };
|
||||
return new ItemStack[]{product};
|
||||
else
|
||||
return StackUtils.EMPTY_STACK_ARRAY;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import buildcraft.api.statements.ITriggerExternal;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IPostalState;
|
||||
@@ -31,7 +30,6 @@ import forestry.mail.PostRegistry;
|
||||
import forestry.plugins.PluginMail;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
@@ -41,7 +39,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MachineMailbox extends TileBase implements IMailContainer, ISpecialInventory, ISidedInventory {
|
||||
public class MachineMailbox extends TileBase implements IMailContainer {
|
||||
|
||||
private boolean isLinked = false;
|
||||
|
||||
@@ -49,11 +47,6 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
setHints(Config.hints.get("mailbox"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
/* GUI */
|
||||
@Override
|
||||
public void openGui(EntityPlayer player, TileBase tile) {
|
||||
@@ -84,7 +77,6 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
}
|
||||
|
||||
/* MAIL HANDLING */
|
||||
|
||||
public IInventory getOrCreateMailInventory(World world, GameProfile playerProfile) {
|
||||
if (!Proxies.common.isSimulating(world))
|
||||
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
|
||||
@@ -110,9 +102,10 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
public boolean hasMail() {
|
||||
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile());
|
||||
for (int i = 0; i < mailInventory.getSizeInventory(); i++)
|
||||
for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
|
||||
if (mailInventory.getStackInSlot(i) != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -127,124 +120,107 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
@Override
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
if (!PostManager.postRegistry.isLetter(stack))
|
||||
return 0;
|
||||
// @Override
|
||||
// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
// if (!PostManager.postRegistry.isLetter(stack))
|
||||
// return 0;
|
||||
//
|
||||
// IPostalState result = tryDispatchLetter(stack, doAdd);
|
||||
//
|
||||
// if (!result.isOk())
|
||||
// return 0;
|
||||
// else
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
//
|
||||
// ItemStack product = null;
|
||||
// IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile());
|
||||
//
|
||||
// for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
|
||||
// ItemStack slotStack = mailInventory.getStackInSlot(i);
|
||||
// if (slotStack == null)
|
||||
// continue;
|
||||
//
|
||||
// product = slotStack;
|
||||
// if (doRemove)
|
||||
// mailInventory.setInventorySlotContents(i, null);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (product != null)
|
||||
// return new ItemStack[]{product};
|
||||
// else
|
||||
// return new ItemStack[0];
|
||||
// }
|
||||
|
||||
IPostalState result = tryDispatchLetter(stack, doAdd);
|
||||
|
||||
if (!result.isOk())
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
|
||||
ItemStack product = null;
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile());
|
||||
|
||||
for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
|
||||
ItemStack slotStack = mailInventory.getStackInSlot(i);
|
||||
if (slotStack == null)
|
||||
continue;
|
||||
|
||||
product = slotStack;
|
||||
if (doRemove)
|
||||
mailInventory.setInventorySlotContents(i, null);
|
||||
break;
|
||||
}
|
||||
|
||||
if (product != null)
|
||||
return new ItemStack[] { product };
|
||||
else
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
// @Override
|
||||
// public int getSizeInventory() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getStackInSlot(int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack decrStackSize(int var1, int var2) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInventorySlotContents(int var1, ItemStack var2) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getInventoryStackLimit() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
// return Utils.isUseableByPlayer(player, this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasCustomInventoryName() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // TODO: This is broken mezz, I don't know how to fix -CovertJaguar
|
||||
// @Override
|
||||
// public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
// return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
// return super.canInsertItem(i, itemstack, j);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean canExtractItem(int i, ItemStack itemstack, int j) {
|
||||
// return super.canExtractItem(i, itemstack, j);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int[] getAccessibleSlotsFromSide(int side) {
|
||||
// return super.getAccessibleSlotsFromSide(side);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void openInventory() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void closeInventory() {
|
||||
// }
|
||||
}
|
||||
@@ -13,15 +13,15 @@ package forestry.mail.gadgets;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
|
||||
@@ -30,9 +30,8 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
public static final short SLOT_BUFFER_1 = 1;
|
||||
public static final short SLOT_BUFFER_COUNT = 27;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(28, "INV");
|
||||
|
||||
public MachinePhilatelist() {
|
||||
setInternalInventory(new TileInventoryAdapter(this, 28, "INV"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,21 +44,6 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
player.openGui(ForestryAPI.instance, GuiId.PhilatelistGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
// / UPDATING
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
@@ -68,6 +52,7 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
|
||||
ItemStack stamp = null;
|
||||
|
||||
TileInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.getStackInSlot(SLOT_FILTER) == null)
|
||||
stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(1);
|
||||
else {
|
||||
@@ -86,37 +71,32 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return inventory.getStackInSlot(i);
|
||||
return getInternalInventory().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
return inventory.decrStackSize(i, j);
|
||||
return getInternalInventory().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
inventory.setInventorySlotContents(i, itemstack);
|
||||
getInternalInventory().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
inventory.markDirty();
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
return getInternalInventory().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,28 +107,19 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return super.isUseableByPlayer(player);
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return super.hasCustomInventoryName();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
return getInternalInventory().isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.core.EnumErrorCode;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
@@ -24,6 +25,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.mail.MailAddress;
|
||||
import forestry.mail.TradeStation;
|
||||
import forestry.plugins.PluginMail;
|
||||
@@ -63,9 +65,8 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
|
||||
@Override
|
||||
public void onRemoval() {
|
||||
if (isLinked()) {
|
||||
if (isLinked())
|
||||
PostManager.postRegistry.deleteTradeStation(worldObj, address);
|
||||
}
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@@ -84,13 +85,11 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
if (nbttagcompound.hasKey("address")) {
|
||||
if (nbttagcompound.hasKey("address"))
|
||||
address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address"));
|
||||
}
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
|
||||
/**
|
||||
* The trade station should show errors for missing stamps and paper first.
|
||||
* Once it is able to send letters, it should display other error states.
|
||||
@@ -106,12 +105,11 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
if (!hasPostageMin(3))
|
||||
errorCode = EnumErrorCode.NOSTAMPS;
|
||||
|
||||
if (!hasPaperMin(2)) {
|
||||
if (!hasPaperMin(2))
|
||||
if (errorCode == EnumErrorCode.NOSTAMPS)
|
||||
errorCode = EnumErrorCode.NOSTAMPSNOPAPER;
|
||||
else
|
||||
errorCode = EnumErrorCode.NOPAPER;
|
||||
}
|
||||
|
||||
if (errorCode != EnumErrorCode.OK) {
|
||||
setErrorState(errorCode);
|
||||
@@ -133,23 +131,21 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
}
|
||||
|
||||
boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.stackSize);
|
||||
if(!hasSupplies) {
|
||||
if (!hasSupplies) {
|
||||
setErrorState(EnumErrorCode.NOSUPPLIES);
|
||||
return;
|
||||
}
|
||||
|
||||
if (inventory instanceof TradeStation) {
|
||||
if (!((TradeStation)inventory).canReceivePayment()) {
|
||||
if (inventory instanceof TradeStation)
|
||||
if (!((TradeStation) inventory).canReceivePayment()) {
|
||||
setErrorState(EnumErrorCode.NOSPACE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
|
||||
public boolean isLinked() {
|
||||
return address.isValid();
|
||||
}
|
||||
@@ -186,16 +182,16 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
IInventory tradeInventory = this.getOrCreateTradeInventory();
|
||||
for (int i = startSlot; i < startSlot + countSlots; i++) {
|
||||
ItemStack itemInSlot = tradeInventory.getStackInSlot(i);
|
||||
if (itemInSlot == null) {
|
||||
if (itemInSlot == null)
|
||||
total += 64;
|
||||
} else {
|
||||
else {
|
||||
total += itemInSlot.getMaxStackSize();
|
||||
if (item == null || StackUtils.isIdenticalItem(itemInSlot, item))
|
||||
count += itemInSlot.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return ((float)count / (float)total);
|
||||
return ((float) count / (float) total);
|
||||
}
|
||||
|
||||
public boolean hasPaperMin(int count) {
|
||||
@@ -277,23 +273,6 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
return super.canTakeStackFromSide(slotIndex, itemstack, side);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: just a specialsource workaround
|
||||
*/
|
||||
@Override
|
||||
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
|
||||
return super.canPutStackFromSide(slotIndex, itemstack, side);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
@@ -349,12 +328,18 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
return getOrCreateTradeInventory().isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return Utils.isUseableByPlayer(player, this);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
|
||||
IInventory inventory = getOrCreateTradeInventory();
|
||||
if (inventory instanceof TradeStation)
|
||||
return ((TradeStation)getOrCreateTradeInventory()).canInsertItem(i, itemstack, j);
|
||||
return super.canInsertItem(i, itemstack, j);
|
||||
return ((TradeStation) inventory).canInsertItem(i, itemstack, j);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -362,9 +347,9 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
IInventory inventory = getOrCreateTradeInventory();
|
||||
if (inventory instanceof TradeStation) {
|
||||
boolean permission = (getAccess() == EnumAccess.SHARED);
|
||||
return ((TradeStation) getOrCreateTradeInventory()).canExtractItem(i, itemstack, j, permission);
|
||||
return ((TradeStation) inventory).canExtractItem(i, itemstack, j, permission);
|
||||
}
|
||||
return super.canExtractItem(i, itemstack, j);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -372,9 +357,9 @@ public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
IInventory inventory = getOrCreateTradeInventory();
|
||||
if (inventory instanceof TradeStation) {
|
||||
boolean permission = (getAccess() == EnumAccess.SHARED);
|
||||
return ((TradeStation) getOrCreateTradeInventory()).getAccessibleSlotsFromSide(side, permission);
|
||||
return ((TradeStation) inventory).getAccessibleSlotsFromSide(side, permission);
|
||||
}
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
return Defaults.FACINGS_NONE;
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.mail.gadgets.MachineMailbox;
|
||||
import forestry.plugins.PluginMail;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -33,20 +32,19 @@ public class ContainerMailbox extends ContainerForestry {
|
||||
private final POBox mailInventory;
|
||||
|
||||
public ContainerMailbox(InventoryPlayer player, MachineMailbox tile) {
|
||||
super(tile);
|
||||
super(tile.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile()));
|
||||
|
||||
// Mailbox contents
|
||||
this.mailbox = tile;
|
||||
|
||||
IInventory inv = mailbox.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile());
|
||||
if (inv instanceof POBox)
|
||||
this.mailInventory = (POBox) inv;
|
||||
if (inventory instanceof POBox)
|
||||
this.mailInventory = (POBox) inventory;
|
||||
else
|
||||
this.mailInventory = null;
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
for (int j = 0; j < 12; j++)
|
||||
addSlot(new SlotClosed(inv, j + i * 9, 8 + j * 18, 8 + i * 18));
|
||||
addSlot(new SlotClosed(inventory, j + i * 9, 8 + j * 18, 8 + i * 18));
|
||||
|
||||
// Player inventory
|
||||
for (int i = 0; i < 3; i++)
|
||||
|
||||
Reference in new issue
Block a user