Merge branches 'development' and 'development' of https://github.com/aidancbrady/Mekanism into development

This commit is contained in:
aidancbrady committed 2015-07-18 23:57:58 -07:00
commit 2c88357477
9 files changed
+198 -23

No files matched your search

@@ -110,7 +110,7 @@ public class TransmitterNetworkRegistry
{
if(MekanismAPI.debug && !invalidTransmitters.isEmpty())
{
logger.debug("Dealing with " + invalidTransmitters.size() + " invalid Transmitters");
logger.info("Dealing with " + invalidTransmitters.size() + " invalid Transmitters");
}
for(IGridTransmitter invalid : invalidTransmitters)
@@ -133,7 +133,7 @@ public class TransmitterNetworkRegistry
{
if(MekanismAPI.debug && !orphanTransmitters.isEmpty())
{
logger.debug("Dealing with " + orphanTransmitters.size() + " orphan Transmitters");
logger.info("Dealing with " + orphanTransmitters.size() + " orphan Transmitters");
}
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
@@ -163,7 +163,7 @@ public class TransmitterNetworkRegistry
case 0:
if(MekanismAPI.debug)
{
logger.debug("No networks found. Creating new network");
logger.info("No networks found. Creating new network");
}
network = startOrphan.createEmptyNetwork();
@@ -172,7 +172,7 @@ public class TransmitterNetworkRegistry
case 1:
if(MekanismAPI.debug)
{
logger.debug("Using single found network");
logger.info("Using single found network");
}
network = finder.networksFound.iterator().next();
@@ -181,7 +181,7 @@ public class TransmitterNetworkRegistry
default:
if(MekanismAPI.debug)
{
logger.debug("Merging " + finder.networksFound.size() + " networks");
logger.info("Merging " + finder.networksFound.size() + " networks");
}
network = startOrphan.mergeNetworks(finder.networksFound);
@@ -0,0 +1,155 @@
package mekanism.common.content.transporter;
import mekanism.api.util.StackUtils;
import mekanism.common.util.InventoryUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
public class StackSearcher
{
public int i;
public int[] slots;
public IInventory theInventory;
public ForgeDirection side;
public StackSearcher(IInventory inventory, ForgeDirection direction)
{
theInventory = InventoryUtils.checkChestInv(inventory);
if(!(theInventory instanceof ISidedInventory))
{
i = inventory.getSizeInventory();
}
else
{
slots = ((ISidedInventory)theInventory).getAccessibleSlotsFromSide(side.getOpposite().ordinal());
if(slots != null)
{
i = slots.length;
}
}
side = direction;
}
public InvStack takeTopStack(Finder id)
{
if(!(theInventory instanceof ISidedInventory))
{
for(i = i - 1; i >= 0; i--)
{
if(theInventory.getStackInSlot(i) != null && id.modifies(theInventory.getStackInSlot(i)))
{
ItemStack toSend = theInventory.getStackInSlot(i).copy();
return new InvStack(theInventory, i, toSend);
}
}
}
else {
if(slots != null && slots.length != 0)
{
for(i = i - 1; i >= 0; i--)
{
int slotID = slots[i];
if(theInventory.getStackInSlot(slotID) != null && id.modifies(theInventory.getStackInSlot(slotID)))
{
ItemStack toSend = theInventory.getStackInSlot(slotID);
if(((ISidedInventory)theInventory).canExtractItem(slotID, toSend, side.getOpposite().ordinal()))
{
return new InvStack(theInventory, slotID, toSend);
}
}
}
}
}
return null;
}
public InvStack takeDefinedItem(ItemStack type, int min, int max)
{
InvStack ret = new InvStack(theInventory);
if(!(theInventory instanceof ISidedInventory))
{
for(i = i - 1; i >= 0; i--)
{
if(theInventory.getStackInSlot(i) != null && StackUtils.equalsWildcard(theInventory.getStackInSlot(i), type))
{
ItemStack stack = theInventory.getStackInSlot(i);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ret.appendStack(i, stack.copy());
}
else {
ItemStack copy = stack.copy();
copy.stackSize = max-current;
ret.appendStack(i, copy);
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)theInventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side.getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
for(i = i - 1; i >= 0; i--)
{
int slotID = slots[i];
if(sidedInventory.getStackInSlot(slotID) != null && StackUtils.equalsWildcard(theInventory.getStackInSlot(slotID), type))
{
ItemStack stack = sidedInventory.getStackInSlot(slotID);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, side.getOpposite().ordinal()))
{
ret.appendStack(slotID, copy);
}
}
else {
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, side.getOpposite().ordinal()))
{
copy.stackSize = max-current;
ret.appendStack(slotID, copy);
}
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
}
if(ret != null && ret.getStack() != null && ret.getStack().stackSize >= min)
{
return ret;
}
return null;
}
}
@@ -40,17 +40,22 @@ public class TItemStackFilter extends TransporterFilter
}
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
public InvStack getStackFromInventory(StackSearcher searcher)
{
if(sizeMode)
{
return InventoryUtils.takeDefinedItem(inv, side.ordinal(), itemType, min, max);
return searcher.takeDefinedItem(itemType, min, max);
}
else {
return InventoryUtils.takeTopStack(inv, side.ordinal(), new ItemStackFinder(itemType));
return super.getStackFromInventory(searcher);
}
}
public Finder getFinder()
{
return new ItemStackFinder(itemType);
}
@Override
public void write(NBTTagCompound nbtTags)
{
@@ -38,9 +38,9 @@ public class TMaterialFilter extends TransporterFilter
}
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
public Finder getFinder()
{
return InventoryUtils.takeTopStack(inv, side.ordinal(), new MaterialFinder(getMaterial()));
return new MaterialFinder(getMaterial());
}
@Override
@@ -29,9 +29,9 @@ public class TModIDFilter extends TransporterFilter
}
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
public Finder getFinder()
{
return InventoryUtils.takeTopStack(inv, side.ordinal(), new ModIDFinder(modID));
return new ModIDFinder(modID);
}
@Override
@@ -29,9 +29,9 @@ public class TOreDictFilter extends TransporterFilter
}
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
public Finder getFinder()
{
return InventoryUtils.takeTopStack(inv, side.ordinal(), new OreDictFinder(oreDictName));
return new OreDictFinder(oreDictName);
}
@Override
@@ -7,6 +7,7 @@ import java.util.Arrays;
import java.util.List;
import mekanism.api.EnumColor;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -23,7 +24,12 @@ public abstract class TransporterFilter
public abstract boolean canFilter(ItemStack itemStack);
public abstract InvStack getStackFromInventory(IInventory inv, ForgeDirection side);
public abstract Finder getFinder();
public InvStack getStackFromInventory(StackSearcher searcher)
{
return searcher.takeTopStack(getFinder());
}
public void write(NBTTagCompound nbtTags)
{
@@ -19,6 +19,7 @@ import mekanism.common.base.ITransporterTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.content.transporter.Finder.FirstFinder;
import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.StackSearcher;
import mekanism.common.content.transporter.TItemStackFilter;
import mekanism.common.content.transporter.TransporterFilter;
import mekanism.common.content.transporter.TransporterManager;
@@ -93,12 +94,19 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
boolean sentItems = false;
int min = 0;
outer:
for(TransporterFilter filter : filters)
{
InvStack invStack = filter.getStackFromInventory(inventory, ForgeDirection.getOrientation(facing).getOpposite());
if(invStack != null && invStack.getStack() != null)
inner:
for(StackSearcher search = new StackSearcher(inventory, ForgeDirection.getOrientation(facing)); search.i >= 0;)
{
InvStack invStack = filter.getStackFromInventory(search);
if(invStack == null || invStack.getStack() == null)
{
break inner;
}
if(filter.canFilter(invStack.getStack()))
{
if(filter instanceof TItemStackFilter)
@@ -110,19 +118,20 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
min = itemFilter.min;
}
}
ItemStack used = emitItemToTransporter(front, invStack, filter.color, min);
if(used != null)
{
invStack.use(used.stackSize);
inventory.markDirty();
setActive(true);
sentItems = true;
break;
break outer;
}
}
}
}
@@ -81,7 +81,7 @@ public final class CableUtils
return true;
}
return isOutputter(tile, side);
return isOutputter(tile, side) || (MekanismUtils.useRF() && tile instanceof IEnergyConnection && ((IEnergyConnection)tile).canConnectEnergy(side.getOpposite()));
}
/**