Make Analyzer Machine require power and accept Honey Drops

This commit is contained in:
CovertJaguar committed 2014-09-26 23:17:07 -07:00
1 parent 95fc960b50
commit c1b29f5c20
12 files changed
+448 -445

No files matched your search

@@ -20,7 +20,7 @@ import net.minecraft.entity.player.InventoryPlayer;
public class ContainerBeealyzer extends ContainerAlyzer {
public ContainerBeealyzer(InventoryPlayer inventoryplayer, BeealyzerInventory inventory) {
super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, new Object[] { ItemBeeGE.class });
super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, ItemBeeGE.class);
}
}
@@ -31,6 +31,7 @@ public class Defaults {
public static final String DEFAULT_POWER_FRAMEWORK = "forestry.energy.BioPowerFramework";
public static final int BUCKET_VOLUME = 1000;
public static final int FLUID_PER_HONEY_DROP = 100;
public static final int[] FACINGS = { 0, 1, 2, 3, 4, 5 };
public static final int FACING_UP = 1;
@@ -33,254 +33,262 @@ import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
*/
public final class FluidHelper {
public static final int BUCKET_FILL_TIME = 8;
public static final int NETWORK_UPDATE_INTERVAL = 128;
public static final int BUCKET_VOLUME = 1000;
public static final int BUCKET_FILL_TIME = 8;
public static final int NETWORK_UPDATE_INTERVAL = 128;
public static final int BUCKET_VOLUME = 1000;
private FluidHelper() {
}
private FluidHelper() {
}
public static boolean handleRightClick(IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) {
if (player == null)
return false;
ItemStack current = player.inventory.getCurrentItem();
if (current != null) {
public static boolean handleRightClick(IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) {
if (player == null)
return false;
ItemStack current = player.inventory.getCurrentItem();
if (current != null) {
FluidStack liquid = getFluidStackInContainer(current);
FluidStack liquid = getFluidStackInContainer(current);
if (fill && liquid != null) {
int used = tank.fill(side, liquid, true);
if (fill && liquid != null) {
int used = tank.fill(side, liquid, true);
if (used > 0) {
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.markDirty();
}
return true;
}
if (used > 0) {
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.markDirty();
}
return true;
}
} else if (drain) {
} else if (drain) {
FluidStack available = tank.drain(side, Integer.MAX_VALUE, false);
if (available != null) {
ItemStack filled = fillContainer(available, current);
FluidStack available = tank.drain(side, Integer.MAX_VALUE, false);
if (available != null) {
ItemStack filled = fillContainer(available, current);
liquid = getFluidStackInContainer(filled);
if (liquid != null) {
liquid = getFluidStackInContainer(filled);
if (liquid != null) {
if (current.stackSize > 1) {
if (!player.inventory.addItemStackToInventory(filled))
return false;
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.markDirty();
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
player.inventory.markDirty();
}
if (current.stackSize > 1) {
if (!player.inventory.addItemStackToInventory(filled))
return false;
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.markDirty();
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current));
player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
player.inventory.markDirty();
}
tank.drain(side, liquid.amount, true);
return true;
}
}
}
}
return false;
}
tank.drain(side, liquid.amount, true);
return true;
}
}
}
}
return false;
}
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot) {
processContainers(tank, inv, inputSlot, outputSlot, tank.getFluidType(), true, true);
}
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot) {
processContainers(tank, inv, inputSlot, outputSlot, tank.getFluidType(), true, true);
}
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
TankManager tankManger = new TankManager();
tankManger.add(tank);
processContainers(tankManger, inv, inputSlot, outputSlot, fluidToFill, processFilled, processEmpty);
}
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
TankManager tankManger = new TankManager();
tankManger.add(tank);
processContainers(tankManger, inv, inputSlot, outputSlot, fluidToFill, processFilled, processEmpty);
}
public static void processContainers(TankManager tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
processContainers(tank, inv, inputSlot, outputSlot, fluidToFill, true, true);
}
public static void processContainers(TankManager tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
processContainers(tank, inv, inputSlot, outputSlot, fluidToFill, true, true);
}
public static void processContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
ItemStack input = inv.getStackInSlot(inputSlot);
public static void processContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
ItemStack input = inv.getStackInSlot(inputSlot);
if (input == null)
return;
if (input == null)
return;
if (processFilled && drainContainers(fluidHandler, inv, inputSlot, outputSlot))
return;
if (processFilled && drainContainers(fluidHandler, inv, inputSlot, outputSlot))
return;
if (processEmpty && fluidToFill != null)
fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill);
}
if (processEmpty && fluidToFill != null)
fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill);
}
public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
ItemStack filled = getFilledContainer(fluidToFill, input);
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && InvTools.isItemEqual(filled, output)))) {
FluidStack fluidInContainer = getFluidStackInContainer(filled);
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (drain != null && drain.amount == fluidInContainer.amount) {
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (output == null)
inv.setInventorySlotContents(outputSlot, filled);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
return false;
}
public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
ItemStack filled = getFilledContainer(fluidToFill, input);
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && InvTools.isItemEqual(filled, output)))) {
FluidStack fluidInContainer = getFluidStackInContainer(filled);
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (drain != null && drain.amount == fluidInContainer.amount) {
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (output == null)
inv.setInventorySlotContents(outputSlot, filled);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
return false;
}
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int slot) {
return drainContainers(fluidHandler, inv, slot, slot);
}
if (input != null) {
FluidStack fluidInContainer = getFluidStackInContainer(input);
ItemStack emptyItem = input.getItem().getContainerItem(input);
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && InvTools.isItemEqual(output, emptyItem)))) {
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (used >= fluidInContainer.amount) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (emptyItem != null)
if (output == null)
inv.setInventorySlotContents(outputSlot, emptyItem);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
}
return false;
}
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
public static boolean isBucket(ItemStack stack) {
return FluidContainerRegistry.isBucket(stack);
}
if (input != null) {
FluidStack fluidInContainer = getFluidStackInContainer(input);
ItemStack emptyItem = input.getItem().getContainerItem(input);
if (fluidInContainer != null && (emptyItem == null || output == null
|| (inputSlot == outputSlot && input.stackSize == 1)
|| (output.stackSize < output.getMaxStackSize() && InvTools.isItemEqual(output, emptyItem)))) {
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (used >= fluidInContainer.amount) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (emptyItem != null)
if (output == null)
inv.setInventorySlotContents(outputSlot, emptyItem);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
}
return false;
}
public static boolean isContainer(ItemStack stack) {
if (stack != null && stack.getItem() instanceof IFluidContainerItem)
return true;
return FluidContainerRegistry.isContainer(stack);
}
public static boolean isBucket(ItemStack stack) {
return FluidContainerRegistry.isBucket(stack);
}
public static boolean isFilledContainer(ItemStack stack) {
return FluidContainerRegistry.isFilledContainer(stack);
}
public static boolean isContainer(ItemStack stack) {
if (stack != null && stack.getItem() instanceof IFluidContainerItem)
return true;
return FluidContainerRegistry.isContainer(stack);
}
public static boolean isEmptyContainer(ItemStack stack) {
return FluidContainerRegistry.isEmptyContainer(stack);
}
public static boolean isFilledContainer(ItemStack stack) {
return FluidContainerRegistry.isFilledContainer(stack);
}
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
if (fluid == null || empty == null) return null;
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
}
public static boolean isEmptyContainer(ItemStack stack) {
return FluidContainerRegistry.isEmptyContainer(stack);
}
public static ItemStack getFilledContainer(FluidStack fluid, ItemStack empty) {
if (fluid == null || empty == null) return null;
fluid = fluid.copy();
fluid.amount = Integer.MAX_VALUE;
return FluidContainerRegistry.fillFluidContainer(fluid, empty);
}
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
if (fluid == null || empty == null)
return null;
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
}
public static ItemStack fillContainer(FluidStack liquid, ItemStack empty) {
if (liquid == null || empty == null) return null;
return FluidContainerRegistry.fillFluidContainer(liquid, empty);
}
public static ItemStack getFilledContainer(FluidStack fluid, ItemStack empty) {
if (fluid == null || empty == null)
return null;
fluid = fluid.copy();
fluid.amount = Integer.MAX_VALUE;
return FluidContainerRegistry.fillFluidContainer(fluid, empty);
}
public static FluidStack getFluidStackInContainer(ItemStack stack) {
return FluidContainerRegistry.getFluidForFilledItem(stack);
}
public static ItemStack fillContainer(FluidStack liquid, ItemStack empty) {
if (liquid == null || empty == null)
return null;
return FluidContainerRegistry.fillFluidContainer(liquid, empty);
}
public static Fluid getFluidInContianer(ItemStack stack) {
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
return fluidStack != null ? fluidStack.getFluid() : null;
}
public static FluidStack getFluidStackInContainer(ItemStack stack) {
return FluidContainerRegistry.getFluidForFilledItem(stack);
}
public static boolean containsFluidStack(ItemStack stack, FluidStack fluidStack) {
return FluidContainerRegistry.containsFluid(stack, fluidStack);
}
public static Fluid getFluidInContianer(ItemStack stack) {
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
return fluidStack != null ? fluidStack.getFluid() : null;
}
public static boolean containsFluid(ItemStack stack, Fluid fluid) {
return FluidContainerRegistry.containsFluid(stack, new FluidStack(fluid, 1));
}
public static boolean containsFluidStack(ItemStack stack, FluidStack fluidStack) {
return FluidContainerRegistry.containsFluid(stack, fluidStack);
}
public static boolean isFluidEqual(FluidStack L1, FluidStack L2) {
if (L1 == null || L2 == null)
return false;
return L1.isFluidEqual(L2);
}
public static boolean containsFluid(ItemStack stack, Fluid fluid) {
return FluidContainerRegistry.containsFluid(stack, new FluidStack(fluid, 1));
}
public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
List<ItemStack> containers = new ArrayList<ItemStack>();
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
FluidStack inContainer = getFluidStackInContainer(data.filledContainer);
if (inContainer != null && inContainer.containsFluid(fluidStack))
containers.add(data.filledContainer.copy());
}
return containers;
}
public static boolean isFluidEqual(FluidStack L1, FluidStack L2) {
if (L1 == null || L2 == null)
return false;
return L1.isFluidEqual(L2);
}
public static void nerfWaterBottle() {
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
if (data.filledContainer.getItem() == Items.potionitem && data.emptyContainer.getItem() == Items.glass_bottle && Fluids.WATER.is(data.fluid)) {
data.fluid.amount = 333;
return;
}
}
}
public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
List<ItemStack> containers = new ArrayList<ItemStack>();
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
FluidStack inContainer = getFluidStackInContainer(data.filledContainer);
if (inContainer != null && inContainer.containsFluid(fluidStack))
containers.add(data.filledContainer.copy());
}
return containers;
}
public static FluidStack drainBlock(World world, int x, int y, int z, boolean doDrain) {
return drainBlock(world.getBlock(x, y, z), world, x, y, z, doDrain);
}
public static void nerfWaterBottle() {
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData())
if (data.filledContainer.getItem() == Items.potionitem && data.emptyContainer.getItem() == Items.glass_bottle && Fluids.WATER.is(data.fluid)) {
data.fluid.amount = 333;
return;
}
}
public static FluidStack drainBlock(Block block, World world, int x, int y, int z, boolean doDrain) {
if (block instanceof IFluidBlock) {
IFluidBlock fluidBlock = (IFluidBlock)block;
if (fluidBlock.canDrain(world, x, y, z))
return fluidBlock.drain(world, x, y, z, doDrain);
} else if (block == Blocks.water || block == Blocks.flowing_water) {
int meta = world.getBlockMetadata(x, y, z);
if (meta != 0)
return null;
if (doDrain)
world.setBlockToAir(x, y, z);
return new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME);
} else if (block == Blocks.lava || block == Blocks.flowing_lava) {
int meta = world.getBlockMetadata(x, y, z);
if (meta != 0)
return null;
if (doDrain)
world.setBlockToAir(x, y, z);
return new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME);
}
return null;
}
public static FluidStack drainBlock(World world, int x, int y, int z, boolean doDrain) {
return drainBlock(world.getBlock(x, y, z), world, x, y, z, doDrain);
}
public static boolean isFullFluidBlock(World world, int x, int y, int z) {
return isFullFluidBlock(world.getBlock(x, y, z), world, x, y, z);
}
public static FluidStack drainBlock(Block block, World world, int x, int y, int z, boolean doDrain) {
if (block instanceof IFluidBlock) {
IFluidBlock fluidBlock = (IFluidBlock) block;
if (fluidBlock.canDrain(world, x, y, z))
return fluidBlock.drain(world, x, y, z, doDrain);
} else if (block == Blocks.water || block == Blocks.flowing_water) {
int meta = world.getBlockMetadata(x, y, z);
if (meta != 0)
return null;
if (doDrain)
world.setBlockToAir(x, y, z);
return new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME);
} else if (block == Blocks.lava || block == Blocks.flowing_lava) {
int meta = world.getBlockMetadata(x, y, z);
if (meta != 0)
return null;
if (doDrain)
world.setBlockToAir(x, y, z);
return new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME);
}
return null;
}
public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) {
if (block instanceof BlockLiquid || block instanceof IFluidBlock)
return world.getBlockMetadata(x, y, z) == 0;
return false;
}
public static boolean isFullFluidBlock(World world, int x, int y, int z) {
return isFullFluidBlock(world.getBlock(x, y, z), world, x, y, z);
}
public static Fluid getFluid(Block block) {
if (block instanceof IFluidBlock)
return ((IFluidBlock) block).getFluid();
else if (block == Blocks.water || block == Blocks.flowing_water)
return FluidRegistry.WATER;
else if (block == Blocks.lava || block == Blocks.flowing_lava)
return FluidRegistry.LAVA;
return null;
}
public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) {
if (block instanceof BlockLiquid || block instanceof IFluidBlock)
return world.getBlockMetadata(x, y, z) == 0;
return false;
}
public static Fluid getFluid(Block block) {
if (block instanceof IFluidBlock)
return ((IFluidBlock) block).getFluid();
else if (block == Blocks.water || block == Blocks.flowing_water)
return FluidRegistry.WATER;
else if (block == Blocks.lava || block == Blocks.flowing_lava)
return FluidRegistry.LAVA;
return null;
}
}
+49 -43
View File
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.fluids;
import forestry.core.config.Defaults;
import java.util.Locale;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
@@ -23,57 +24,62 @@ import net.minecraftforge.fluids.FluidStack;
*/
public enum Fluids {
WATER, LAVA, FUEL, BIOFUEL, CREOSOTE, STEAM, BIOETHANOL, COAL, PYROTHEUM;
private final String tag;
WATER, LAVA, FUEL, BIOMASS, BIOFUEL, CREOSOTE, STEAM, BIOETHANOL,
COAL, PYROTHEUM, HONEY, MILK, JUICE, ICE, GLASS, OIL, SEEDOIL, SHORT_MEAD(Defaults.LIQUID_MEAD);
private final String tag;
private Fluids() {
tag = name().toLowerCase(Locale.ENGLISH);
}
private Fluids() {
tag = name().toLowerCase(Locale.ENGLISH);
}
public String getTag() {
return tag;
}
private Fluids(String tag) {
this.tag = tag;
}
public Fluid get() {
return FluidRegistry.getFluid(tag);
}
public String getTag() {
return tag;
}
/**
* Gets a FluidStack filled with qty milliBuckets worth of Fluid.
*
* @param qty
* @return
*/
public FluidStack get(int qty) {
return FluidRegistry.getFluidStack(tag, qty);
}
public Fluid get() {
return FluidRegistry.getFluid(tag);
}
/**
* Gets a FluidStack filled with n buckets worth of Fluid.
*
* @param n
* @return
*/
public FluidStack getB(int n) {
return FluidRegistry.getFluidStack(tag, n * FluidContainerRegistry.BUCKET_VOLUME);
}
/**
* Gets a FluidStack filled with qty milliBuckets worth of Fluid.
*
* @param qty
* @return
*/
public FluidStack get(int qty) {
return FluidRegistry.getFluidStack(tag, qty);
}
public boolean is(Fluid fluid) {
return get() == fluid;
}
/**
* Gets a FluidStack filled with n buckets worth of Fluid.
*
* @param n
* @return
*/
public FluidStack getB(int n) {
return FluidRegistry.getFluidStack(tag, n * FluidContainerRegistry.BUCKET_VOLUME);
}
public boolean is(FluidStack fluidStack) {
return fluidStack != null && get() == fluidStack.getFluid();
}
public boolean is(Fluid fluid) {
return get() == fluid;
}
public boolean isContained(ItemStack containerStack) {
return containerStack != null && FluidHelper.containsFluid(containerStack, get());
}
public boolean is(FluidStack fluidStack) {
return fluidStack != null && get() == fluidStack.getFluid();
}
public static boolean areEqual(Fluid fluid, FluidStack fluidStack) {
if (fluidStack != null && fluid == fluidStack.getFluid())
return true;
return fluid == null && fluidStack == null;
}
public boolean isContained(ItemStack containerStack) {
return containerStack != null && FluidHelper.containsFluid(containerStack, get());
}
public static boolean areEqual(Fluid fluid, FluidStack fluidStack) {
if (fluidStack != null && fluid == fluidStack.getFluid())
return true;
return fluid == null && fluidStack == null;
}
}
@@ -23,18 +23,18 @@ import net.minecraft.network.Packet;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.core.EnumErrorCode;
import forestry.core.fluids.TankManager;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.Fluids;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.EntityNetData;
import forestry.core.network.GuiId;
@@ -42,14 +42,17 @@ import forestry.core.network.PacketIds;
import forestry.core.network.PacketInventoryStack;
import forestry.core.proxy.Proxies;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.wrappers.IInvSlot;
import forestry.core.inventory.wrappers.InventoryIterator;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
import net.minecraft.inventory.IInventory;
public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer {
/* CONSTANTS */
public static final int TIME_TO_ANALYZE = 500;
public static final int TIME_TO_ANALYZE = 125;
public static final int HONEY_REQUIRED = 100;
public static final short SLOT_ANALYZE = 0;
@@ -62,11 +65,6 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
private int analyzeTime;
private final short analyzeSlot = 0;
private final short canSlot = 1;
private final short inputSlot1 = 2;
private final short outputSlot1 = 8;
@EntityNetData
public FilteredTank resourceTank;
@@ -74,9 +72,12 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
private final Stack<ItemStack> pendingProducts = new Stack<ItemStack>();
private final IInventory invInput = new InventoryMapper(inventory, SLOT_INPUT_1, 6);
/* CONSTRUCTOR */
public TileAnalyzer() {
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.getFluid(Defaults.LIQUID_HONEY));
super(400, 800, 40, Defaults.MACHINE_MAX_ENERGY);
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.get());
tankManager = new TankManager(resourceTank);
}
@@ -137,90 +138,90 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
/* WORKING */
@Override
public void updateServerSide() {
public boolean workCycle() {
// If we add pending products, we skip to the next work cycle.
if (tryAddPending())
return;
return false;
if (!pendingProducts.isEmpty()) {
setErrorState(EnumErrorCode.NOSPACE);
return;
return false;
}
// Check if we have suitable items waiting in the can slot
if (getStackInSlot(canSlot) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(getStackInSlot(canSlot));
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
setInventorySlotContents(canSlot, StackUtils.replenishByContainer(this, getStackInSlot(canSlot), container, resourceTank));
if (getStackInSlot(canSlot).stackSize <= 0)
setInventorySlotContents(canSlot, null);
}
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
ItemStack can = getStackInSlot(SLOT_CAN);
if (ForestryItem.honeyDrop.isItemEqual(can) && resourceTank.fill(Fluids.HONEY.get(Defaults.FLUID_PER_HONEY_DROP), false) == Defaults.FLUID_PER_HONEY_DROP) {
setInventorySlotContents(SLOT_CAN, InvTools.depleteItem(can));
resourceTank.fill(Fluids.HONEY.get(Defaults.FLUID_PER_HONEY_DROP), true);
}
if (analyzeTime > 0 && getStackInSlot(analyzeSlot) != null && AlleleManager.alleleRegistry.isIndividual(getStackInSlot(analyzeSlot))) {
ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE);
if (analyzeTime > 0 && stackToAnalyze != null && AlleleManager.alleleRegistry.isIndividual(stackToAnalyze)) {
analyzeTime--;
// Still not done
if (analyzeTime > 0) {
setErrorState(EnumErrorCode.OK);
return;
return true;
}
// Analyzation is done.
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(getStackInSlot(analyzeSlot));
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(stackToAnalyze);
// No bee, abort
if (individual == null)
return;
return false;
individual.analyze();
NBTTagCompound nbttagcompound = new NBTTagCompound();
individual.writeToNBT(nbttagcompound);
getStackInSlot(analyzeSlot).setTagCompound(nbttagcompound);
stackToAnalyze.setTagCompound(nbttagcompound);
pendingProducts.push(getStackInSlot(analyzeSlot));
setInventorySlotContents(analyzeSlot, null);
pendingProducts.push(stackToAnalyze);
setInventorySlotContents(SLOT_ANALYZE, null);
sendNetworkUpdate();
} else {
analyzeTime = 0;
// Don't start if analyze slot already occupied
if (getStackInSlot(analyzeSlot) != null)
return;
// We need our liquid honey
if (resourceTank.getFluidAmount() < HONEY_REQUIRED) {
setErrorState(EnumErrorCode.NORESOURCE);
return;
}
// Look for bees in input slots.
for (int i = inputSlot1; i < outputSlot1; i++) {
if (getStackInSlot(i) == null || !AlleleManager.alleleRegistry.isIndividual(getStackInSlot(i)))
continue;
// Analyzed bees in the input buffer are added to the output
// queue at once.
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(getStackInSlot(i));
if (individual.isAnalyzed()) {
pendingProducts.push(getStackInSlot(i));
setInventorySlotContents(i, null);
continue;
}
setInventorySlotContents(analyzeSlot, getStackInSlot(i));
setInventorySlotContents(i, null);
resourceTank.drain(HONEY_REQUIRED, true);
analyzeTime = TIME_TO_ANALYZE;
sendNetworkUpdate();
return;
}
// Nothing to analyze
setErrorState(EnumErrorCode.NOTHINGANALYZE);
return true;
}
analyzeTime = 0;
// Don't start if analyze slot already occupied
if (stackToAnalyze != null)
return false;
// We need our liquid honey
if (resourceTank.getFluidAmount() < HONEY_REQUIRED) {
setErrorState(EnumErrorCode.NORESOURCE);
return false;
}
// Look for bees in input slots.
for (IInvSlot slot : InventoryIterator.getIterable(invInput)) {
ItemStack inputStack = slot.getStackInSlot();
if (inputStack == null || !AlleleManager.alleleRegistry.isIndividual(inputStack))
continue;
// Analyzed bees in the input buffer are added to the output
// queue at once.
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inputStack);
if (individual.isAnalyzed()) {
pendingProducts.push(inputStack);
slot.setStackInSlot(null);
continue;
}
setInventorySlotContents(SLOT_ANALYZE, inputStack);
slot.setStackInSlot(null);
resourceTank.drain(HONEY_REQUIRED, true);
analyzeTime = TIME_TO_ANALYZE;
sendNetworkUpdate();
return true;
}
// Nothing to analyze
setErrorState(EnumErrorCode.NOTHINGANALYZE);
return false;
}
private boolean tryAddPending() {
@@ -228,7 +229,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
return false;
ItemStack next = pendingProducts.peek();
if (inventory.tryAddStack(next, outputSlot1, inventory.getSizeInventory() - outputSlot1, true)) {
if (inventory.tryAddStack(next, SLOT_OUTPUT_1, inventory.getSizeInventory() - SLOT_OUTPUT_1, true)) {
pendingProducts.pop();
return true;
}
@@ -237,6 +238,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
/* STATE INFORMATION */
// @Override
@Override
public boolean isWorking() {
return analyzeTime > 0;
}
@@ -250,10 +252,11 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
}
public ItemStack getIndividualOnDisplay() {
return getStackInSlot(analyzeSlot);
return getStackInSlot(SLOT_ANALYZE);
}
/* SMP */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
@@ -263,6 +266,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, analyzeTime);
@@ -288,37 +292,64 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
@Override
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
if(!super.canTakeStackFromSide(slotIndex, itemstack, side))
if (!super.canTakeStackFromSide(slotIndex, itemstack, side))
return false;
return slotIndex >= SLOT_OUTPUT_1 && slotIndex < SLOT_OUTPUT_1 + 4;
}
@Override
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
protected boolean canPutStackFromSide(int slotIndex, ItemStack stack, int side) {
if(!super.canPutStackFromSide(slotIndex, itemstack, side))
if (!super.canPutStackFromSide(slotIndex, stack, side))
return false;
if(slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + 6)
return AlleleManager.alleleRegistry.isIndividual(itemstack);
if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + 6)
return AlleleManager.alleleRegistry.isIndividual(stack);
if(slotIndex == SLOT_CAN) {
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
return container != null && LiquidHelper.isLiquid(Defaults.LIQUID_HONEY, container.fluid);
}
if (slotIndex == SLOT_CAN)
return Fluids.HONEY.isContained(stack);
return false;
}
@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 int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); }
@Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); }
@Override public void openInventory() {}
@Override public void closeInventory() {}
@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 int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
/**
* TODO: just a specialsource workaround
@@ -368,66 +399,6 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
return super.getAccessibleSlotsFromSide(side);
}
/* ISPECIALINVENTORY */
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
ItemStack product = null;
for (int i = outputSlot1; i < inventory.getSizeInventory(); i++) {
if (inventory.getStackInSlot(i) == null)
continue;
product = getStackInSlot(i).copy();
if (doRemove) {
getStackInSlot(i).stackSize = 0;
setInventorySlotContents(i, null);
}
break;
}
return new ItemStack[] { product };
}
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
if (!AlleleManager.alleleRegistry.isIndividual(stack)) {
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
if (container == null || !resourceTank.accepts(container.fluid.getFluid()))
return 0;
if (getStackInSlot(canSlot) == null) {
if (doAdd)
setInventorySlotContents(canSlot, stack.copy());
return stack.stackSize;
}
int space = getStackInSlot(canSlot).getMaxStackSize() - getStackInSlot(canSlot).stackSize;
if (space <= 0)
return 0;
if (doAdd) {
getStackInSlot(canSlot).stackSize += stack.stackSize;
if (getStackInSlot(canSlot).stackSize > getStackInSlot(canSlot).getMaxStackSize())
getStackInSlot(canSlot).stackSize = getStackInSlot(canSlot).getMaxStackSize();
}
return space;
}
for (int i = inputSlot1; i < outputSlot1; i++)
if (getStackInSlot(i) == null) {
if (doAdd)
setInventorySlotContents(i, stack.copy());
return stack.stackSize;
}
return 0;
}
/* ILIQUIDCONTAINER */
@Override
public TankManager getTankManager() {
@@ -14,7 +14,6 @@ import forestry.core.fluids.tanks.StandardTank;
import forestry.core.interfaces.IPowerHandler;
import forestry.core.interfaces.IRenderableMachine;
import forestry.core.network.ClassMap;
import forestry.core.network.EntityNetData;
import forestry.core.network.IndexInPayload;
import forestry.core.network.PacketPayload;
import forestry.core.proxy.Proxies;
@@ -119,6 +118,10 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine
}
/* LIQUID CONTAINER HANDLING */
/**
@deprecated Use FluidHelper
*/
@Deprecated
protected ItemStack bottleIntoContainer(ItemStack canStack, ItemStack outputStack, FluidContainerData container, StandardTank tank) {
if (tank.getFluidAmount() < container.fluid.amount)
return outputStack;
@@ -10,9 +10,9 @@ import net.minecraft.item.ItemStack;
public class ContainerAlyzer extends ContainerItemInventory {
private AlyzerInventory inventory;
private final AlyzerInventory inventory;
protected ContainerAlyzer(InventoryPlayer inventoryplayer, AlyzerInventory inventory, Object[] acceptedEnergy, Object[] acceptedSpecimens) {
protected ContainerAlyzer(InventoryPlayer inventoryplayer, AlyzerInventory inventory, Object[] acceptedEnergy, Object... acceptedSpecimens) {
super(inventory, inventoryplayer.player);
this.inventory = inventory;
@@ -20,17 +20,17 @@ public class ContainerAlyzer extends ContainerItemInventory {
final int xPosLeftSlots = 223;
// Energy
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ENERGY, xPosLeftSlots, 8, acceptedEnergy));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ENERGY, xPosLeftSlots, 8, acceptedEnergy));
// Bee to analyze
this.addSlot(new SlotCustom(inventory, inventory.SLOT_SPECIMEN, xPosLeftSlots, 26, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_SPECIMEN, xPosLeftSlots, 26, acceptedSpecimens));
// Analyzed bee
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_1, xPosLeftSlots, 57, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_2, xPosLeftSlots, 75, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_3, xPosLeftSlots, 93, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_4, xPosLeftSlots, 111, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_5, xPosLeftSlots, 129, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_1, xPosLeftSlots, 57, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_2, xPosLeftSlots, 75, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_3, xPosLeftSlots, 93, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_4, xPosLeftSlots, 111, acceptedSpecimens));
this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_5, xPosLeftSlots, 129, acceptedSpecimens));
final int xPosPlayerInv = 43;
final int xSpacePlayerInv = 18;
@@ -62,7 +62,7 @@ public class ContainerAlyzer extends ContainerItemInventory {
// Last slot is the energy slot, so we don't save that one.
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (i == inventory.SLOT_ENERGY)
if (i == AlyzerInventory.SLOT_ENERGY)
continue;
ItemStack stack = inventory.getStackInSlot(i);
if (stack == null)
@@ -10,18 +10,21 @@
******************************************************************************/
package forestry.core.gui;
import forestry.core.config.ForestryItem;
import forestry.core.fluids.Fluids;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import forestry.core.gadgets.TileAnalyzer;
import forestry.core.genetics.ItemGE;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.gui.slots.SlotLiquidContainer;
import forestry.core.gui.slots.SlotOutput;
import net.minecraft.item.ItemStack;
public class ContainerAnalyzer extends ContainerLiquidTanks {
private TileAnalyzer tile;
private final TileAnalyzer tile;
public ContainerAnalyzer(InventoryPlayer player, TileAnalyzer tile) {
super(tile, tile);
@@ -31,18 +34,27 @@ public class ContainerAnalyzer extends ContainerLiquidTanks {
// Input buffer
for (int i = 0; i < 3; i++)
for (int k = 0; k < 2; k++)
addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18, new Object[] { ItemGE.class }));
addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18, ItemGE.class));
// Analyze slot
addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59, new Object[] {}));
addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59, new Object[]{}));
// Can slot
addSlot(new SlotLiquidContainer(tile, TileAnalyzer.SLOT_CAN, 143, 24));
addSlot(new SlotLiquidContainer(tile, TileAnalyzer.SLOT_CAN, 143, 24, false, Fluids.HONEY.get()) {
@Override
public boolean isItemValid(ItemStack stack) {
if (ForestryItem.honeyDrop.isItemEqual(stack))
return true;
return super.isItemValid(stack);
}
});
// Output buffer
for (int i = 0; i < 2; i++)
for (int k = 0; k < 2; k++)
addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18, new Object[] { ItemGE.class }));
addSlot(new SlotOutput(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18));
// Player inventory
for (int i1 = 0; i1 < 3; i1++)
@@ -10,48 +10,50 @@
******************************************************************************/
package forestry.core.gui.slots;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import forestry.core.fluids.FluidHelper;
import forestry.core.render.TextureManager;
import net.minecraftforge.fluids.Fluid;
public class SlotLiquidContainer extends SlotCustom {
public class SlotLiquidContainer extends SlotForestry {
private final boolean isEmpty;
private final boolean allowEmpty;
private final Fluid[] fluids;
public SlotLiquidContainer(IInventory iinventory, int i, int j, int k) {
this(iinventory, i, j, k, false);
public SlotLiquidContainer(IInventory iinventory, int x, int y, int z) {
this(iinventory, x, y, z, false);
}
public SlotLiquidContainer(IInventory iinventory, int i, int j, int k, boolean isEmpty) {
super(iinventory, i, j, k, false);
public SlotLiquidContainer(IInventory iinventory, int x, int y, int z, boolean allowEmpty, Fluid... fluids) {
super(iinventory, x, y, z);
this.isEmpty = isEmpty;
List<ItemStack> container = new ArrayList<ItemStack>();
this.allowEmpty = allowEmpty;
this.fluids = fluids;
}
for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData())
if (isEmpty)
container.add(cont.emptyContainer);
else
container.add(cont.filledContainer);
this.items = container.toArray();
@Override
public boolean isItemValid(ItemStack stack) {
if (allowEmpty)
return FluidHelper.isEmptyContainer(stack);
if (fluids.length > 0) {
for (Fluid fluid : fluids)
if (FluidHelper.containsFluid(stack, fluid))
return true;
return false;
}
return FluidHelper.isFilledContainer(stack);
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getBackgroundIconIndex() {
if(isEmpty)
if (allowEmpty)
return TextureManager.getInstance().getDefault("slots/container");
else
return TextureManager.getInstance().getDefault("slots/liquid");
@@ -618,9 +618,9 @@ public class PluginApiculture extends ForestryPlugin {
'W', ForestryItem.craftingMaterial.getItemStack(1, 3));
// / SQUEEZER
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeyDrop.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 100),
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeyDrop.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, Defaults.FLUID_PER_HONEY_DROP),
ForestryItem.propolis.getItemStack(), 5);
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeydew.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 100));
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeydew.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, Defaults.FLUID_PER_HONEY_DROP));
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.sand)}, LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 2000));
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.dirt)}, LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 1600));