diff --git a/common/cofh/api/block/IBlockDebug.java b/common/cofh/api/block/IBlockDebug.java new file mode 100644 index 000000000..45004142b --- /dev/null +++ b/common/cofh/api/block/IBlockDebug.java @@ -0,0 +1,33 @@ +package cofh.api.block; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.ForgeDirection; + +/** + * Implement this interface on blocks which have some debug method which can be activated via a tool or other means. + * + * @author King Lemming + * + */ +public interface IBlockDebug { + + /** + * This function debugs a block. + * + * @param world + * Reference to the world. + * @param x + * X coordinate of the block. + * @param y + * Y coordinate of the block. + * @param z + * Z coordinate of the block. + * @param side + * The side of the block. + * @param player + * Player doing the debugging. + */ + public void debugBlock(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player); + +} diff --git a/common/cofh/api/block/IBlockInfo.java b/common/cofh/api/block/IBlockInfo.java new file mode 100644 index 000000000..43892b8b8 --- /dev/null +++ b/common/cofh/api/block/IBlockInfo.java @@ -0,0 +1,39 @@ +package cofh.api.block; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.ForgeDirection; + +/** + * Implement this interface on blocks which can provide information about themselves. + * + * @author King Lemming + * + */ +public interface IBlockInfo { + + /** + * This function appends information to a list provided to it. + * + * @param world + * Reference to the world. + * @param x + * X coordinate of the block. + * @param y + * Y coordinate of the block. + * @param z + * Z coordinate of the block. + * @param side + * The side of the block that is being queried. + * @param player + * Player doing the querying - this can be NULL. + * @param info + * The list that the information should be appended to. + * @param debug + * If true, the Block should return "debug" information. + */ + public void getBlockInfo(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player, List info, boolean debug); + +} diff --git a/common/cofh/api/energy/IEnergyContainerItem.java b/common/cofh/api/energy/IEnergyContainerItem.java index e01be6e4a..0bcfda600 100644 --- a/common/cofh/api/energy/IEnergyContainerItem.java +++ b/common/cofh/api/energy/IEnergyContainerItem.java @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; public interface IEnergyContainerItem { /** - * Adds energy to an item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. + * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. * * @param container * ItemStack to be charged. @@ -26,7 +26,8 @@ public interface IEnergyContainerItem { int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); /** - * Removes energy from an item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally discharged. + * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally + * discharged. * * @param container * ItemStack to be discharged. @@ -39,12 +40,12 @@ public interface IEnergyContainerItem { int extractEnergy(ItemStack container, int maxExtract, boolean simulate); /** - * Get the amount of energy currently stored in the item. + * Get the amount of energy currently stored in the container item. */ int getEnergyStored(ItemStack container); /** - * Get the max amount of energy that can be stored in the item. + * Get the max amount of energy that can be stored in the container item. */ int getMaxEnergyStored(ItemStack container); diff --git a/common/cofh/api/transport/IItemConduit.java b/common/cofh/api/transport/IItemConduit.java index 367854939..56714cc91 100644 --- a/common/cofh/api/transport/IItemConduit.java +++ b/common/cofh/api/transport/IItemConduit.java @@ -13,7 +13,9 @@ public interface IItemConduit { /** * Insert items into the conduit. Returns the ItemStack left (null if fully routed). Will only accept items if they have an valid destination. + * + * Pass the conduit the side *opposite* the one you are ejecting from! */ - public ItemStack sendItems(ItemStack item, ForgeDirection side); + public ItemStack sendItems(ItemStack item, ForgeDirection from); } diff --git a/common/cofh/api/transport/IItemConduitConnection.java b/common/cofh/api/transport/IItemConduitConnection.java index 150598b68..e8cad7f58 100644 --- a/common/cofh/api/transport/IItemConduitConnection.java +++ b/common/cofh/api/transport/IItemConduitConnection.java @@ -10,6 +10,6 @@ import net.minecraftforge.common.ForgeDirection; */ public interface IItemConduitConnection { - public boolean canConduitConnect(ForgeDirection side); + public boolean canConduitConnect(ForgeDirection from); } diff --git a/common/mekanism/common/item/ItemBlockEnergyCube.java b/common/mekanism/common/item/ItemBlockEnergyCube.java index f78a8b3c8..b33ed392a 100644 --- a/common/mekanism/common/item/ItemBlockEnergyCube.java +++ b/common/mekanism/common/item/ItemBlockEnergyCube.java @@ -254,15 +254,41 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II } @Override - public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive) + public int receiveEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE); + if(canReceive(theItem)) + { + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_TE, energyNeeded); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (int)Math.round(toReceive*Mekanism.TO_TE); + } + + return 0; } @Override - public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer) + public int extractEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE); + if(canSend(theItem)) + { + double energyRemaining = getEnergy(theItem); + double toSend = Math.min((energy*Mekanism.FROM_TE), energyRemaining); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (int)Math.round(toSend*Mekanism.TO_TE); + } + + return 0; } @Override diff --git a/common/mekanism/common/item/ItemBlockMachine.java b/common/mekanism/common/item/ItemBlockMachine.java index 5b988e31f..c3a6f670b 100644 --- a/common/mekanism/common/item/ItemBlockMachine.java +++ b/common/mekanism/common/item/ItemBlockMachine.java @@ -818,15 +818,41 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem } @Override - public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive) + public int receiveEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE); + if(canReceive(theItem)) + { + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_TE, energyNeeded); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (int)Math.round(toReceive*Mekanism.TO_TE); + } + + return 0; } @Override - public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer) + public int extractEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE); + if(canSend(theItem)) + { + double energyRemaining = getEnergy(theItem); + double toSend = Math.min((energy*Mekanism.FROM_TE), energyRemaining); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (int)Math.round(toSend*Mekanism.TO_TE); + } + + return 0; } @Override diff --git a/common/mekanism/common/item/ItemEnergized.java b/common/mekanism/common/item/ItemEnergized.java index 251730a90..234ab0be5 100644 --- a/common/mekanism/common/item/ItemEnergized.java +++ b/common/mekanism/common/item/ItemEnergized.java @@ -162,27 +162,53 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem } @Override - public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive) + public int receiveEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE); + if(canReceive(theItem)) + { + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_TE, energyNeeded); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (int)Math.round(toReceive*Mekanism.TO_TE); + } + + return 0; } @Override - public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer) + public int extractEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE); + if(canSend(theItem)) + { + double energyRemaining = getEnergy(theItem); + double toSend = Math.min((energy*Mekanism.FROM_TE), energyRemaining); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (int)Math.round(toSend*Mekanism.TO_TE); + } + + return 0; } @Override public int getEnergyStored(ItemStack theItem) { - return (int)(getEnergy(theItem)*Mekanism.TO_TE); + return (int)Math.round(getEnergy(theItem)*Mekanism.TO_TE); } @Override public int getMaxEnergyStored(ItemStack theItem) { - return (int)(getMaxEnergy(theItem)*Mekanism.TO_TE); + return (int)Math.round(getMaxEnergy(theItem)*Mekanism.TO_TE); } @Override diff --git a/common/mekanism/generators/common/item/ItemBlockGenerator.java b/common/mekanism/generators/common/item/ItemBlockGenerator.java index dfed1a84d..ad774bd55 100644 --- a/common/mekanism/generators/common/item/ItemBlockGenerator.java +++ b/common/mekanism/generators/common/item/ItemBlockGenerator.java @@ -323,15 +323,41 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt } @Override - public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive) + public int receiveEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE); + if(canReceive(theItem)) + { + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_TE, energyNeeded); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (int)Math.round(toReceive*Mekanism.TO_TE); + } + + return 0; } @Override - public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer) + public int extractEnergy(ItemStack theItem, int energy, boolean simulate) { - return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE); + if(canSend(theItem)) + { + double energyRemaining = getEnergy(theItem); + double toSend = Math.min((energy*Mekanism.FROM_TE), energyRemaining); + + if(!simulate) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (int)Math.round(toSend*Mekanism.TO_TE); + } + + return 0; } @Override