diff --git a/common/cofh/api/core/IInitializer.java b/common/cofh/api/core/IInitializer.java deleted file mode 100644 index b507e6bc1..000000000 --- a/common/cofh/api/core/IInitializer.java +++ /dev/null @@ -1,17 +0,0 @@ -package cofh.api.core; - -/** - * Interface which can be put on just about anything to allow for iteration during initialization. - * - * @author King Lemming - * - */ -public interface IInitializer { - - public boolean preInit(); - - public boolean initialize(); - - public boolean postInit(); - -} diff --git a/common/cofh/api/core/ISimpleRegistry.java b/common/cofh/api/core/ISimpleRegistry.java deleted file mode 100644 index 1ffe2cb7a..000000000 --- a/common/cofh/api/core/ISimpleRegistry.java +++ /dev/null @@ -1,22 +0,0 @@ -package cofh.api.core; - -/** - * Basic interface for the Cape and Skin Registries. - * - * @author Zeldo Kavira - * - */ -public interface ISimpleRegistry { - - /** - * Register a new entry. - * - * @param playerName - * The player to register. - * @param URL - * Location of the cape/skin. - * @return True if registration was successful. - */ - public boolean register(String playerName, String URL); - -} diff --git a/common/cofh/api/core/NullSimpleRegistry.java b/common/cofh/api/core/NullSimpleRegistry.java deleted file mode 100644 index df95dae5c..000000000 --- a/common/cofh/api/core/NullSimpleRegistry.java +++ /dev/null @@ -1,17 +0,0 @@ -package cofh.api.core; - -/** - * Dummy class used to initialize Cape and Skin Registries to prevent accidental NPEs. - * - * @author Zeldo Kavira - * - */ -public class NullSimpleRegistry implements ISimpleRegistry { - - @Override - public boolean register(String playerName, String URL) { - - return false; - } - -} diff --git a/common/cofh/api/core/RegistryAccess.java b/common/cofh/api/core/RegistryAccess.java deleted file mode 100644 index c1c049571..000000000 --- a/common/cofh/api/core/RegistryAccess.java +++ /dev/null @@ -1,14 +0,0 @@ -package cofh.api.core; - -/** - * Access to the Cape and Skin Registries of CoFH Core. - * - * @author Zeldo Kavira - * - */ -public class RegistryAccess { - - public static ISimpleRegistry capeRegistry = new NullSimpleRegistry(); - public static ISimpleRegistry skinRegistry = new NullSimpleRegistry(); - -} diff --git a/common/cofh/api/item/IInventoryContainerItem.java b/common/cofh/api/item/IInventoryContainerItem.java deleted file mode 100644 index b1f515969..000000000 --- a/common/cofh/api/item/IInventoryContainerItem.java +++ /dev/null @@ -1,20 +0,0 @@ -package cofh.api.item; - -import net.minecraft.item.ItemStack; - -/** - * Implement this interface on Item classes that are themselves inventories. - * - * There's no real interaction here - the point of this is to correctly identify these items and prevent nesting. - * - * @author King Lemming - * - */ -public interface IInventoryContainerItem { - - /** - * Get the size of this inventory. - */ - int getSizeInventory(ItemStack container); - -} diff --git a/common/cofh/api/tileentity/IEnergyInfo.java b/common/cofh/api/tileentity/IEnergyInfo.java deleted file mode 100644 index afa6774a3..000000000 --- a/common/cofh/api/tileentity/IEnergyInfo.java +++ /dev/null @@ -1,21 +0,0 @@ -package cofh.api.tileentity; - -/** - * Implement this interface on Tile Entities which can report information about their energy usage. - * - * This is used for reporting purposes - Energy transactions should be handled through IEnergyHandler! - * - * @author King Lemming - * - */ -public interface IEnergyInfo { - - public int getEnergyPerTick(); - - public int getMaxEnergyPerTick(); - - public int getEnergy(); - - public int getMaxEnergy(); - -} diff --git a/common/cofh/api/tileentity/IReconfigurableFacing.java b/common/cofh/api/tileentity/IReconfigurableFacing.java deleted file mode 100644 index df9810963..000000000 --- a/common/cofh/api/tileentity/IReconfigurableFacing.java +++ /dev/null @@ -1,39 +0,0 @@ -package cofh.api.tileentity; - -/** - * Implement this interface on Tile Entities which allow for reconfiguration of their facing. - * - * Coordination with the containing block is required. - * - * @author King Lemming - * - */ -public interface IReconfigurableFacing { - - /** - * Returns the current facing of the block. - */ - public int getFacing(); - - /** - * Returns whether or not the block's face can be aligned with the Y Axis. - */ - public boolean allowYAxisFacing(); - - /** - * Attempt to rotate the block. Arbitrary based on implementation. - * - * @return True if rotation was successful, false otherwise. - */ - public boolean rotateBlock(); - - /** - * Set the facing of the block. - * - * @param side - * The side to set the facing to. - * @return True if the facing was set, false otherwise. - */ - public boolean setFacing(int side); - -} diff --git a/common/cofh/api/tileentity/IReconfigurableSides.java b/common/cofh/api/tileentity/IReconfigurableSides.java deleted file mode 100644 index 354d58dbe..000000000 --- a/common/cofh/api/tileentity/IReconfigurableSides.java +++ /dev/null @@ -1,54 +0,0 @@ -package cofh.api.tileentity; - -/** - * Implement this interface on Tile Entities which allow for reconfiguration of their sides. - * - * Coordination with the containing block is required. - * - * @author King Lemming - * - */ -public interface IReconfigurableSides { - - /** - * Decrement the config for a given side. - * - * @param side - * The side to decrement. - * @return True if config was changed, false otherwise. - */ - public boolean decrSide(int side); - - /** - * Increment the config for a given side. - * - * @param side - * The side to decrement. - * @return True if config was changed, false otherwise. - */ - public boolean incrSide(int side); - - /** - * Set the config for a given side. - * - * @param side - * The side to set. - * @param config - * The config value to use. - * @return True of config was set, false otherwise. - */ - public boolean setSide(int side, int config); - - /** - * Reset configs on all sides to their base values. - * - * @return True if reset was successful, false otherwise. - */ - public boolean resetSides(); - - /** - * Returns the number of possible config settings for a given side. - */ - public int getNumConfig(int side); - -} diff --git a/common/cofh/api/tileentity/IRedstoneControl.java b/common/cofh/api/tileentity/IRedstoneControl.java deleted file mode 100644 index 0fd0014fc..000000000 --- a/common/cofh/api/tileentity/IRedstoneControl.java +++ /dev/null @@ -1,21 +0,0 @@ -package cofh.api.tileentity; - -/** - * Implement this interface on Tile Entities which have redstone control functionality. - * - * @author King Lemming - * - */ -public interface IRedstoneControl { - - public boolean getControlDisable(); - - public boolean getControlSetting(); - - public boolean setControlDisable(boolean disable); - - public boolean setControlSetting(boolean state); - - public boolean setRedstoneConfig(boolean disable, boolean state); - -} diff --git a/common/cofh/api/tileentity/ISecureTile.java b/common/cofh/api/tileentity/ISecureTile.java deleted file mode 100644 index e5659ecca..000000000 --- a/common/cofh/api/tileentity/ISecureTile.java +++ /dev/null @@ -1,44 +0,0 @@ -package cofh.api.tileentity; - -public interface ISecureTile { - - public static enum AccessMode { - PUBLIC, RESTRICTED, PRIVATE; - - public boolean isPublic() { - - return this == PUBLIC; - } - - public boolean isRestricted() { - - return this == RESTRICTED; - } - - public boolean isPrivate() { - - return this == PRIVATE; - } - - public static AccessMode stepForward(AccessMode curAccess) { - - return curAccess == AccessMode.PUBLIC ? AccessMode.RESTRICTED : curAccess == AccessMode.PRIVATE ? AccessMode.PUBLIC : AccessMode.PRIVATE; - } - - public static AccessMode stepBackward(AccessMode curAccess) { - - return curAccess == AccessMode.PUBLIC ? AccessMode.PRIVATE : curAccess == AccessMode.PRIVATE ? AccessMode.RESTRICTED : AccessMode.PUBLIC; - } - } - - public boolean setAccess(AccessMode access); - - public AccessMode getAccess(); - - public boolean setOwnerName(String name); - - public String getOwnerName(); - - public boolean canPlayerAccess(String name); - -} diff --git a/common/cofh/api/tileentity/ISidedBlockTexture.java b/common/cofh/api/tileentity/ISidedBlockTexture.java deleted file mode 100644 index 7f5d4d977..000000000 --- a/common/cofh/api/tileentity/ISidedBlockTexture.java +++ /dev/null @@ -1,16 +0,0 @@ -package cofh.api.tileentity; - -import net.minecraft.util.Icon; - -/** - * Implement this interface on Tile Entities which can change their block's texture based on the current render pass. The block must defer the call to its Tile - * Entity. - * - * @author Zeldo Kavira - * - */ -public interface ISidedBlockTexture { - - public Icon getBlockTexture(int side, int pass); - -} diff --git a/common/cofh/api/tileentity/ITileInfo.java b/common/cofh/api/tileentity/ITileInfo.java deleted file mode 100644 index 379b8fd79..000000000 --- a/common/cofh/api/tileentity/ITileInfo.java +++ /dev/null @@ -1,19 +0,0 @@ -package cofh.api.tileentity; - -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; - -/** - * Implement this interface on Tile Entities which can send state information through chat. - * - * @author Zeldo Kavira - * - */ -public interface ITileInfo { - - public List getTileInfo(); - - public void sendTileInfoToPlayer(EntityPlayer player); - -} diff --git a/common/cofh/api/world/IFeatureGenerator.java b/common/cofh/api/world/IFeatureGenerator.java deleted file mode 100644 index f0d732f33..000000000 --- a/common/cofh/api/world/IFeatureGenerator.java +++ /dev/null @@ -1,39 +0,0 @@ -package cofh.api.world; - -import java.util.Random; - -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.WorldGenerator; - -/** - * This interface should be implemented on classes which define a world feature to be generated in a {@link IFeatureHandler}. It is essentially a more robust - * version of {@link WorldGenerator}, and may include one or more WorldGenerators should you wish. - * - * @author King Lemming - * - */ -public interface IFeatureGenerator { - - /** - * Returns the name of the feature, used for displaying in the World.cfg file. - */ - public String getFeatureName(); - - /** - * Generates the world feature. - * - * @param random - * Random derived from the world seed. - * @param chunkX - * Minimum X chunk-coordinate of the chunk. (x16 for block coordinate) - * @param chunkZ - * Minimum Z chunk-coordinate of the chunk. (x16 for block coordinate) - * @param world - * The world to generate in. - * @param newGen - * True on initial generation, false on retrogen. - * @return True if generation happened, false otherwise. - */ - public boolean generateFeature(Random random, int chunkX, int chunkZ, World world, boolean newGen); - -} diff --git a/common/cofh/api/world/IFeatureHandler.java b/common/cofh/api/world/IFeatureHandler.java deleted file mode 100644 index eea078ce8..000000000 --- a/common/cofh/api/world/IFeatureHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -package cofh.api.world; - -/** - * Provides an interface to allow for the addition of Features to world generation. - * - * See {@link IFeatureGenerator}. - * - * @author King Lemming - * - */ -public interface IFeatureHandler { - - /** - * Register a feature with an IFeatureHandler. - * - * @param feature - * The feature to register. - * @return True if the registration was successful, false if a feature with that name existed. - */ - public boolean registerFeature(IFeatureGenerator feature); - -} diff --git a/common/cofh/api/world/WeightedRandomBlock.java b/common/cofh/api/world/WeightedRandomBlock.java deleted file mode 100644 index b841494e6..000000000 --- a/common/cofh/api/world/WeightedRandomBlock.java +++ /dev/null @@ -1,31 +0,0 @@ -package cofh.api.world; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.WeightedRandomItem; - -/** - * This class essentially allows for ores to be generated in clusters, with Features randomly choosing one or more blocks from a weighted list. - * - * @author King Lemming - * - */ -public final class WeightedRandomBlock extends WeightedRandomItem { - - public final int blockId; - public final int metadata; - - public WeightedRandomBlock(ItemStack ore) { - - super(100); - this.blockId = ore.itemID; - this.metadata = ore.getItemDamage(); - } - - public WeightedRandomBlock(ItemStack ore, int weight) { - - super(weight); - this.blockId = ore.itemID; - this.metadata = ore.getItemDamage(); - } - -} diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index 00260d900..1999f96eb 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -19,7 +19,6 @@ import mekanism.api.infuse.InfuseObject; import mekanism.api.infuse.InfuseRegistry; import mekanism.api.infuse.InfuseType; import mekanism.api.infuse.InfusionInput; -import mekanism.api.transmitters.ITransmitter; import mekanism.api.transmitters.TransmitterNetworkRegistry; import mekanism.common.EnergyNetwork.EnergyTransferEvent; import mekanism.common.FluidNetwork.FluidTransferEvent; @@ -81,6 +80,7 @@ import mekanism.common.tileentity.TileEntityAdvancedBoundingBlock; import mekanism.common.tileentity.TileEntityBoundingBlock; import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityTeleporter; +import mekanism.common.transporter.TransporterManager; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.voice.VoiceServerManager; @@ -99,7 +99,6 @@ import net.minecraftforge.oredict.ShapelessOreRecipe; import rebelkeithy.mods.metallurgy.api.IOreInfo; import rebelkeithy.mods.metallurgy.api.MetallurgyAPI; import thermalexpansion.api.crafting.CraftingManagers; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -1044,6 +1043,7 @@ public class Mekanism teleporters.clear(); dynamicInventories.clear(); ic2Registered.clear(); + TransporterManager.flowingStacks.clear(); } @EventHandler diff --git a/common/mekanism/common/TileComponentEjector.java b/common/mekanism/common/TileComponentEjector.java index b1c3d35f5..397eac09c 100644 --- a/common/mekanism/common/TileComponentEjector.java +++ b/common/mekanism/common/TileComponentEjector.java @@ -10,6 +10,7 @@ import mekanism.api.Object3D; import mekanism.api.SideData; import mekanism.common.tileentity.TileEntityContainerBlock; import mekanism.common.tileentity.TileEntityLogisticalTransporter; +import mekanism.common.transporter.TransporterManager; import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.TransporterUtils; @@ -121,9 +122,11 @@ public class TileComponentEjector implements ITileComponent, IEjector } else if(tile instanceof TileEntityLogisticalTransporter) { - if(TransporterUtils.insert(tileEntity, (TileEntityLogisticalTransporter)tile, stack, outputColor)) + ItemStack rejects = TransporterUtils.insert(tileEntity, (TileEntityLogisticalTransporter)tile, stack, outputColor, true); + + if(TransporterManager.didEmit(stack, rejects)) { - stack = null; + stack = rejects; } } diff --git a/common/mekanism/common/item/ItemBlockMachine.java b/common/mekanism/common/item/ItemBlockMachine.java index d08b79896..ba1691c04 100644 --- a/common/mekanism/common/item/ItemBlockMachine.java +++ b/common/mekanism/common/item/ItemBlockMachine.java @@ -128,8 +128,11 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem list.add(EnumColor.INDIGO + "Locked: " + EnumColor.GREY + getLocked(itemstack)); } - list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergyStored(itemstack))); - list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); + if(itemstack.getItemDamage() != MachineType.LOGISTICAL_SORTER.meta) + { + list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergyStored(itemstack))); + list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); + } if(hasTank(itemstack)) { diff --git a/common/mekanism/common/tileentity/TileEntityBin.java b/common/mekanism/common/tileentity/TileEntityBin.java index cdf5aeeb2..ac88e641e 100644 --- a/common/mekanism/common/tileentity/TileEntityBin.java +++ b/common/mekanism/common/tileentity/TileEntityBin.java @@ -8,6 +8,7 @@ import mekanism.common.PacketHandler; import mekanism.common.PacketHandler.Transmission; import mekanism.common.item.ItemBlockBasic; import mekanism.common.network.PacketTileEntity; +import mekanism.common.transporter.TransporterManager; import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.TransporterUtils; @@ -171,9 +172,11 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento { TileEntityLogisticalTransporter transporter = (TileEntityLogisticalTransporter)tile; - if(TransporterUtils.insert(this, transporter, getStack(), null)) + ItemStack rejects = TransporterUtils.insert(this, transporter, getStack(), null, true); + + if(TransporterManager.didEmit(getStack(), rejects)) { - setInventorySlotContents(0, null); + setInventorySlotContents(0, rejects); } } else if(tile instanceof IInventory) diff --git a/common/mekanism/common/tileentity/TileEntityDigitalMiner.java b/common/mekanism/common/tileentity/TileEntityDigitalMiner.java index 03f8c6585..ed6f49337 100644 --- a/common/mekanism/common/tileentity/TileEntityDigitalMiner.java +++ b/common/mekanism/common/tileentity/TileEntityDigitalMiner.java @@ -29,6 +29,7 @@ import mekanism.common.miner.ThreadMinerSearch; import mekanism.common.miner.ThreadMinerSearch.State; import mekanism.common.network.PacketTileEntity; import mekanism.common.transporter.InvStack; +import mekanism.common.transporter.TransporterManager; import mekanism.common.util.ChargeUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; @@ -199,9 +200,11 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } else if(getEjectInv() instanceof TileEntityLogisticalTransporter) { - if(TransporterUtils.insert(getEjectTile(), (TileEntityLogisticalTransporter)getEjectInv(), getTopEject(false, null), null)) + ItemStack rejected = TransporterUtils.insert(getEjectTile(), (TileEntityLogisticalTransporter)getEjectInv(), getTopEject(false, null), null, true); + + if(TransporterManager.didEmit(getTopEject(false, null), rejected)) { - getTopEject(true, null); + getTopEject(true, rejected); } } } diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java index 60d8319a5..e0a660a50 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java @@ -13,7 +13,9 @@ import mekanism.common.PacketHandler.Transmission; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.network.PacketTileEntity; import mekanism.common.transporter.InvStack; +import mekanism.common.transporter.TItemStackFilter; import mekanism.common.transporter.TransporterFilter; +import mekanism.common.transporter.TransporterManager; import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.TransporterUtils; @@ -85,6 +87,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen InvStack inInventory = null; boolean hasFilter = false; EnumColor filterColor = color; + TItemStackFilter itemFilter = null; for(TransporterFilter filter : filters) { @@ -97,6 +100,12 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen filterColor = filter.color; hasFilter = true; inInventory = invStack; + + if(filter instanceof TItemStackFilter) + { + itemFilter = (TItemStackFilter)filter; + } + break; } } @@ -109,23 +118,33 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen if(inInventory != null && inInventory.getStack() != null) { - boolean inserted = false; + ItemStack used = null; if(!roundRobin) { - if(TransporterUtils.insert(this, transporter, inInventory.getStack(), filterColor)) + ItemStack rejects = TransporterUtils.insert(this, transporter, inInventory.getStack(), filterColor, false); + + if(TransporterManager.didEmit(inInventory.getStack(), rejects)) { - inserted = true; + if(itemFilter == null || itemFilter.canFilter(TransporterManager.getToUse(inInventory.getStack(), rejects))) + { + used = TransporterManager.getToUse(inInventory.getStack(), rejects); + } } } else { - if(TransporterUtils.insertRR(this, transporter, inInventory.getStack(), filterColor)) + ItemStack rejects = TransporterUtils.insertRR(this, transporter, inInventory.getStack(), filterColor, false); + + if(TransporterManager.didEmit(inInventory.getStack(), rejects)) { - inserted = true; + if(itemFilter == null || itemFilter.canFilter(TransporterManager.getToUse(inInventory.getStack(), rejects))) + { + used = TransporterManager.getToUse(inInventory.getStack(), rejects); + } } } - if(inserted) + if(used != null) { inInventory.use(); inventory.onInventoryChanged(); diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java index 68ef6f72b..5f844820c 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java @@ -12,6 +12,7 @@ import mekanism.common.PacketHandler; import mekanism.common.PacketHandler.Transmission; import mekanism.common.network.PacketDataRequest; import mekanism.common.network.PacketTileEntity; +import mekanism.common.transporter.TransporterManager; import mekanism.common.transporter.TransporterStack; import mekanism.common.transporter.TransporterStack.Path; import mekanism.common.util.InventoryUtils; @@ -112,6 +113,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile if(rejected == null) { + TransporterManager.remove(stack); remove.add(stack); continue; } @@ -207,7 +209,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile { needsSync.add(stack); - if(!stack.recalculatePath(this)) + if(!TransporterManager.didEmit(stack.itemStack, stack.recalculatePath(this))) { if(!stack.calculateIdle(this)) { @@ -224,7 +226,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile return true; } - public boolean insert(Object3D original, ItemStack itemStack, EnumColor color) + public ItemStack insert(Object3D original, ItemStack itemStack, EnumColor color, boolean doEmit) { TransporterStack stack = new TransporterStack(); stack.itemStack = itemStack; @@ -234,21 +236,26 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile if(!stack.canInsertToTransporter(this)) { - return false; + return itemStack; } - if(stack.recalculatePath(this)) + ItemStack rejected = stack.recalculatePath(this); + + if(TransporterManager.didEmit(stack.itemStack, rejected)) { + stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected); + transit.add(stack); + TransporterManager.add(stack); PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getSyncPacket(stack, false)), Object3D.get(this), 50D); MekanismUtils.saveChunk(this); - return true; + return rejected; } - return false; + return itemStack; } - public boolean insertRR(TileEntityLogisticalSorter outputter, ItemStack itemStack, EnumColor color) + public ItemStack insertRR(TileEntityLogisticalSorter outputter, ItemStack itemStack, EnumColor color, boolean doEmit) { TransporterStack stack = new TransporterStack(); stack.itemStack = itemStack; @@ -258,17 +265,23 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile if(!stack.canInsertToTransporter(this)) { - return false; + return itemStack; } - if(stack.recalculateRRPath(outputter, this)) + ItemStack rejected = stack.recalculateRRPath(outputter, this); + + if(TransporterManager.didEmit(stack.itemStack, rejected)) { + stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected); + transit.add(stack); + TransporterManager.add(stack); PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getSyncPacket(stack, false)), Object3D.get(this), 50D); - return true; + MekanismUtils.saveChunk(this); + return rejected; } - return false; + return itemStack; } public void entityEntering(TransporterStack stack) @@ -393,7 +406,10 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile for(int i = 0; i < tagList.tagCount(); i++) { - transit.add(TransporterStack.readFromNBT((NBTTagCompound)tagList.tagAt(i))); + TransporterStack stack = TransporterStack.readFromNBT((NBTTagCompound)tagList.tagAt(i)); + + transit.add(stack); + TransporterManager.add(stack); } } } @@ -491,13 +507,8 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile { TileEntity tile = Object3D.get(this).getFromSide(from).getTileEntity(worldObj); - if(TransporterUtils.insert(tile, this, stack, null)) - { - return stack.stackSize; - } - else { - return 0; - } + ItemStack rejects = TransporterUtils.insert(tile, this, stack, null, true); + return TransporterManager.getToUse(stack, rejects).stackSize; } return 0; diff --git a/common/mekanism/common/transporter/InvStack.java b/common/mekanism/common/transporter/InvStack.java index 91cc68cb1..3bf24710c 100644 --- a/common/mekanism/common/transporter/InvStack.java +++ b/common/mekanism/common/transporter/InvStack.java @@ -53,6 +53,24 @@ public final class InvStack itemStacks.add(stack); } + public void use(int amount) + { + for(int i = 0; i < slotIDs.size(); i++) + { + ItemStack stack = itemStacks.get(i); + + if(inventory.getStackInSlot(slotIDs.get(i)).stackSize == stack.stackSize) + { + inventory.setInventorySlotContents(slotIDs.get(i), null); + } + else { + ItemStack ret = stack.copy(); + ret.stackSize = inventory.getStackInSlot(slotIDs.get(i)).stackSize - stack.stackSize; + inventory.setInventorySlotContents(slotIDs.get(i), ret); + } + } + } + public void use() { for(int i = 0; i < slotIDs.size(); i++) diff --git a/common/mekanism/common/transporter/TransporterManager.java b/common/mekanism/common/transporter/TransporterManager.java new file mode 100644 index 000000000..659b0bad2 --- /dev/null +++ b/common/mekanism/common/transporter/TransporterManager.java @@ -0,0 +1,333 @@ +package mekanism.common.transporter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import mekanism.api.EnumColor; +import mekanism.api.IConfigurable; +import mekanism.api.Object3D; +import mekanism.common.tileentity.TileEntityBin; +import mekanism.common.transporter.TransporterStack.Path; +import mekanism.common.util.InventoryUtils; +import mekanism.common.util.MekanismUtils; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +public class TransporterManager +{ + public static Set flowingStacks = new HashSet(); + + public static void add(TransporterStack stack) + { + flowingStacks.add(stack); + + System.out.println("Added " + flowingStacks.size()); + } + + public static void remove(TransporterStack stack) + { + flowingStacks.remove(stack); + + System.out.println("Removed " + flowingStacks.size()); + } + + public static List getStacksToDest(Object3D dest) + { + List ret = new ArrayList(); + + for(TransporterStack stack : flowingStacks) + { + if(stack != null && stack.pathType != Path.NONE) + { + if(stack.getDest().equals(dest)) + { + ret.add(stack); + } + } + } + + return ret; + } + + public static ItemStack[] copyInvFromSide(IInventory inv, int side) + { + inv = InventoryUtils.checkChestInv(inv); + + ItemStack[] ret = new ItemStack[inv.getSizeInventory()]; + + if(!(inv instanceof ISidedInventory)) + { + for(int i = 0; i <= inv.getSizeInventory() - 1; i++) + { + ret[i] = inv.getStackInSlot(i).copy(); + } + } + else { + ISidedInventory sidedInventory = (ISidedInventory)inv; + int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal()); + + for(int get = 0; get <= slots.length - 1; get++) + { + int slotID = slots[get]; + + ret[slotID] = sidedInventory.getStackInSlot(slotID).copy(); + } + } + + return ret; + } + + public static void testInsert(IInventory inv, ItemStack[] testInv, int side, TransporterStack stack) + { + ItemStack toInsert = stack.itemStack.copy(); + + if(stack.pathType != Path.HOME && inv instanceof IConfigurable) + { + IConfigurable config = (IConfigurable)inv; + int tileSide = config.getOrientation(); + EnumColor configColor = config.getEjector().getInputColor(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(side, tileSide)).getOpposite()); + + if(config.getEjector().hasStrictInput() && configColor != null && configColor != stack.color) + { + return; + } + } + + if(!(inv instanceof ISidedInventory)) + { + for(int i = 0; i <= inv.getSizeInventory() - 1; i++) + { + if(stack.pathType != Path.HOME) + { + if(!inv.isItemValidForSlot(i, toInsert)) + { + continue; + } + } + + ItemStack inSlot = inv.getStackInSlot(i); + + if(inSlot == null) + { + testInv[i] = toInsert; + return; + } + else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize()) + { + if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize()) + { + ItemStack toSet = toInsert.copy(); + toSet.stackSize += inSlot.stackSize; + + testInv[i] = toSet; + return; + } + else { + int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize(); + + ItemStack toSet = toInsert.copy(); + toSet.stackSize = inSlot.getMaxStackSize(); + + ItemStack remains = toInsert.copy(); + remains.stackSize = rejects; + + testInv[i] = toSet; + + toInsert = remains; + } + } + } + } + else { + ISidedInventory sidedInventory = (ISidedInventory)inv; + int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal()); + + if(slots != null && slots.length != 0) + { + if(stack.pathType != Path.HOME && sidedInventory instanceof TileEntityBin && ForgeDirection.getOrientation(side).getOpposite().ordinal() == 0) + { + slots = sidedInventory.getAccessibleSlotsFromSide(1); + } + + for(int get = 0; get <= slots.length - 1; get++) + { + int slotID = slots[get]; + + if(stack.pathType != Path.HOME) + { + if(!sidedInventory.isItemValidForSlot(slotID, toInsert) && !sidedInventory.canInsertItem(slotID, toInsert, ForgeDirection.getOrientation(side).getOpposite().ordinal())) + { + continue; + } + } + + ItemStack inSlot = inv.getStackInSlot(slotID); + + if(inSlot == null) + { + testInv[slotID] = toInsert; + return; + } + else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize()) + { + if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize()) + { + ItemStack toSet = toInsert.copy(); + toSet.stackSize += inSlot.stackSize; + + testInv[slotID] = toSet; + return; + } + else { + int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize(); + + ItemStack toSet = toInsert.copy(); + toSet.stackSize = inSlot.getMaxStackSize(); + + ItemStack remains = toInsert.copy(); + remains.stackSize = rejects; + + testInv[slotID] = toSet; + + toInsert = remains; + } + } + } + } + } + } + + public static boolean didEmit(ItemStack stack, ItemStack returned) + { + return returned == null || returned.stackSize < stack.stackSize; + } + + public static ItemStack getToUse(ItemStack stack, ItemStack returned) + { + if(returned == null || returned.stackSize == 0) + { + return stack; + } + + return MekanismUtils.size(stack, stack.stackSize-returned.stackSize); + } + + /** + * @return rejects + */ + public static ItemStack getPredictedInsert(TileEntity tileEntity, EnumColor color, ItemStack itemStack, int side) + { + if(!(tileEntity instanceof IInventory)) + { + return itemStack; + } + + if(tileEntity instanceof IConfigurable) + { + IConfigurable config = (IConfigurable)tileEntity; + int tileSide = config.getOrientation(); + EnumColor configColor = config.getEjector().getInputColor(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(side, tileSide)).getOpposite()); + + if(config.getEjector().hasStrictInput() && configColor != null && configColor != color) + { + return itemStack; + } + } + + IInventory inventory = (IInventory)tileEntity; + ItemStack[] testInv = copyInvFromSide(inventory, side); + + List insertQueue = getStacksToDest(Object3D.get(tileEntity)); + + for(TransporterStack tStack : insertQueue) + { + testInsert(inventory, testInv, side, tStack); + } + + if(!(inventory instanceof ISidedInventory)) + { + inventory = InventoryUtils.checkChestInv(inventory); + + for(int i = 0; i <= inventory.getSizeInventory() - 1; i++) + { + if(!inventory.isItemValidForSlot(i, itemStack)) + { + continue; + } + + ItemStack inSlot = testInv[i]; + + if(inSlot == null) + { + return null; + } + else if(inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) + { + if(inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + { + return null; + } + else { + int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + + if(rejects < itemStack.stackSize) + { + return MekanismUtils.size(itemStack, rejects); + } + } + } + } + } + else { + ISidedInventory sidedInventory = (ISidedInventory)inventory; + int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal()); + + if(slots != null && slots.length != 0) + { + if(sidedInventory instanceof TileEntityBin && ForgeDirection.getOrientation(side).getOpposite().ordinal() == 0) + { + slots = sidedInventory.getAccessibleSlotsFromSide(1); + } + + for(int get = 0; get <= slots.length - 1; get++) + { + int slotID = slots[get]; + + if(!sidedInventory.isItemValidForSlot(slotID, itemStack) || !sidedInventory.canInsertItem(slotID, itemStack, ForgeDirection.getOrientation(side).getOpposite().ordinal())) + { + continue; + } + + ItemStack inSlot = testInv[slotID]; + + if(inSlot == null) + { + return null; + } + else if(inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) + { + if(inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + { + return null; + } + else { + int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + + if(rejects < itemStack.stackSize) + { + return MekanismUtils.size(itemStack, rejects); + } + } + } + } + } + } + + return itemStack; + } +} diff --git a/common/mekanism/common/transporter/TransporterPathfinder.java b/common/mekanism/common/transporter/TransporterPathfinder.java index 150a25260..9efd15a17 100644 --- a/common/mekanism/common/transporter/TransporterPathfinder.java +++ b/common/mekanism/common/transporter/TransporterPathfinder.java @@ -15,6 +15,8 @@ import mekanism.common.tileentity.TileEntityLogisticalTransporter; import mekanism.common.transporter.TransporterPathfinder.Pathfinder.DestChecker; import mekanism.common.transporter.TransporterStack.Path; import mekanism.common.util.InventoryUtils; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; @@ -70,7 +72,7 @@ public final class TransporterPathfinder if(!found) { - destinations.add(new Destination(currentPath, dist, true)); + destinations.add(new Destination(currentPath, dist, true, null)); } } @@ -104,8 +106,9 @@ public final class TransporterPathfinder { public List path = new ArrayList(); public double score; + public ItemStack rejected; - public Destination(ArrayList list, double d, boolean inv) + public Destination(ArrayList list, double d, boolean inv, ItemStack rejects) { path = (List)list.clone(); @@ -115,6 +118,7 @@ public final class TransporterPathfinder } score = d; + rejected = rejects; } @Override @@ -157,6 +161,8 @@ public final class TransporterPathfinder public Set destsFound = new HashSet(); + public Map rejects = new HashMap(); + public Object3D start; public TransporterStack transportStack; @@ -212,9 +218,15 @@ public final class TransporterPathfinder continue; } - if(InventoryUtils.canInsert(tile, transportStack.color, transportStack.itemStack, side.ordinal(), false)) + if(tile instanceof IInventory) { - destsFound.add(Object3D.get(tile)); + ItemStack stack = TransporterManager.getPredictedInsert(tile, transportStack.color, transportStack.itemStack, side.ordinal()); + + if(TransporterManager.didEmit(transportStack.itemStack, stack)) + { + destsFound.add(Object3D.get(tile)); + rejects.put(Object3D.get(tile), stack); + } } else if(transportStack.canInsertToTransporter(tile) && !iterated.contains(Object3D.get(tile))) { @@ -224,13 +236,13 @@ public final class TransporterPathfinder } } - public Set find() - { - loop(start); - - return destsFound; + public Set find() + { + loop(start); + + return destsFound; + } } -} public static List getPaths(TileEntityLogisticalTransporter start, TransporterStack stack) { @@ -253,7 +265,7 @@ public final class TransporterPathfinder if(p.getPath().size() >= 2) { - paths.add(new Destination(p.getPath(), p.finalScore, false)); + paths.add(new Destination(p.getPath(), p.finalScore, false, d.rejects.get(obj))); } } @@ -262,7 +274,7 @@ public final class TransporterPathfinder return paths; } - public static List getNewBasePath(TileEntityLogisticalTransporter start, TransporterStack stack) + public static Destination getNewBasePath(TileEntityLogisticalTransporter start, TransporterStack stack) { List paths = getPaths(start, stack); @@ -271,10 +283,10 @@ public final class TransporterPathfinder return null; } - return paths.get(0).path; + return paths.get(0); } - public static List getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, TileEntityLogisticalSorter outputter) + public static Destination getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, TileEntityLogisticalSorter outputter) { List paths = getPaths(start, stack); @@ -321,7 +333,7 @@ public final class TransporterPathfinder return null; } - return closest.path; + return closest; } public static class Pathfinder diff --git a/common/mekanism/common/transporter/TransporterStack.java b/common/mekanism/common/transporter/TransporterStack.java index 9008c054f..48e039410 100644 --- a/common/mekanism/common/transporter/TransporterStack.java +++ b/common/mekanism/common/transporter/TransporterStack.java @@ -7,6 +7,7 @@ import mekanism.api.EnumColor; import mekanism.api.Object3D; import mekanism.common.tileentity.TileEntityLogisticalSorter; import mekanism.common.tileentity.TileEntityLogisticalTransporter; +import mekanism.common.transporter.TransporterPathfinder.Destination; import mekanism.common.util.TransporterUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -147,38 +148,38 @@ public class TransporterStack return pathToTarget != null; } - public boolean recalculatePath(TileEntityLogisticalTransporter tileEntity) + public ItemStack recalculatePath(TileEntityLogisticalTransporter tileEntity) { - List newPath = TransporterPathfinder.getNewBasePath(tileEntity, this); + Destination newPath = TransporterPathfinder.getNewBasePath(tileEntity, this); if(newPath == null) { - return false; + return itemStack; } - pathToTarget = newPath; + pathToTarget = newPath.path; pathType = Path.DEST; initiatedPath = true; - return true; + return newPath.rejected; } - public boolean recalculateRRPath(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity) + public ItemStack recalculateRRPath(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity) { - List newPath = TransporterPathfinder.getNewRRPath(tileEntity, this, outputter); + Destination newPath = TransporterPathfinder.getNewRRPath(tileEntity, this, outputter); if(newPath == null) { - return false; + return itemStack; } - pathToTarget = newPath; + pathToTarget = newPath.path; pathType = Path.DEST; initiatedPath = true; - return true; + return newPath.rejected; } public boolean calculateIdle(TileEntityLogisticalTransporter tileEntity) diff --git a/common/mekanism/common/util/TransporterUtils.java b/common/mekanism/common/util/TransporterUtils.java index 7bc86088c..3e8ce72bc 100644 --- a/common/mekanism/common/util/TransporterUtils.java +++ b/common/mekanism/common/util/TransporterUtils.java @@ -4,17 +4,17 @@ import java.util.ArrayList; import java.util.Arrays; import mekanism.api.EnumColor; -import mekanism.api.IConfigurable; import mekanism.api.Object3D; import mekanism.api.transmitters.ITransmitter; -import mekanism.common.tileentity.TileEntityBin; import mekanism.common.tileentity.TileEntityDiversionTransporter; import mekanism.common.tileentity.TileEntityLogisticalSorter; import mekanism.common.tileentity.TileEntityLogisticalTransporter; +import mekanism.common.transporter.TransporterManager; import mekanism.common.transporter.TransporterStack; import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; @@ -190,14 +190,14 @@ public final class TransporterUtils return inventories; } - public static boolean insert(TileEntity outputter, TileEntityLogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color) + public static ItemStack insert(TileEntity outputter, TileEntityLogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color, boolean doEmit) { - return tileEntity.insert(Object3D.get(outputter), itemStack.copy(), color); + return tileEntity.insert(Object3D.get(outputter), itemStack.copy(), color, doEmit); } - public static boolean insertRR(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color) + public static ItemStack insertRR(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color, boolean doEmit) { - return tileEntity.insertRR(outputter, itemStack.copy(), color); + return tileEntity.insertRR(outputter, itemStack.copy(), color, doEmit); } public static EnumColor increment(EnumColor color) @@ -226,6 +226,8 @@ public final class TransporterUtils pos = new float[] {0, 0, 0}; } + TransporterManager.remove(stack); + EntityItem entityItem = new EntityItem(tileEntity.worldObj, tileEntity.xCoord + pos[0], tileEntity.yCoord + pos[1], tileEntity.zCoord + pos[2], stack.itemStack); entityItem.motionX = 0; @@ -242,7 +244,7 @@ public final class TransporterUtils float itemFix = 0; - if(stack.itemStack.itemID >= 256) + if(!(stack.itemStack.getItem() instanceof ItemBlock)) { itemFix = 0.1F; } diff --git a/common/mekanism/generators/common/item/ItemBlockGenerator.java b/common/mekanism/generators/common/item/ItemBlockGenerator.java index 4188b054b..320d63423 100644 --- a/common/mekanism/generators/common/item/ItemBlockGenerator.java +++ b/common/mekanism/generators/common/item/ItemBlockGenerator.java @@ -84,7 +84,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt } else { list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack))); - list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); + list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + (getVoltage(itemstack)*Mekanism.FROM_UE) + "v"); if(hasTank(itemstack)) {