Simplified code
This commit is contained in:
parent
8c5d407ca1
commit
0d553f03ed
4 changed files with 78 additions and 72 deletions
|
@ -123,24 +123,29 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
* Try top first, then bottom, then the sides to see if it is possible to insert the
|
||||
* item into a inventory.
|
||||
*/
|
||||
ItemStack remainingStack = this.tryPlaceInPosition(entity.func_92014_d().copy(), outputUp, ForgeDirection.DOWN);
|
||||
ItemStack remainingStack = entity.func_92014_d().copy();
|
||||
|
||||
if (remainingStack != null)
|
||||
if (!this.isFiltering(remainingStack))
|
||||
{
|
||||
remainingStack = this.tryPlaceInPosition(remainingStack, outputDown, ForgeDirection.UP);
|
||||
}
|
||||
remainingStack = this.tryPlaceInPosition(remainingStack, outputUp, ForgeDirection.DOWN);
|
||||
|
||||
if (remainingStack != null)
|
||||
{
|
||||
remainingStack = this.tryPlaceInPosition(remainingStack, outputPosition, this.getBeltDirection().getOpposite());
|
||||
}
|
||||
if (remainingStack != null)
|
||||
{
|
||||
remainingStack = this.tryPlaceInPosition(remainingStack, outputDown, ForgeDirection.UP);
|
||||
}
|
||||
|
||||
if (remainingStack != null && remainingStack.stackSize > 0)
|
||||
{
|
||||
this.throwItem(outputPosition, remainingStack);
|
||||
}
|
||||
if (remainingStack != null)
|
||||
{
|
||||
remainingStack = this.tryPlaceInPosition(remainingStack, outputPosition, this.getBeltDirection().getOpposite());
|
||||
}
|
||||
|
||||
entity.setDead();
|
||||
if (remainingStack != null && remainingStack.stackSize > 0)
|
||||
{
|
||||
this.throwItem(outputPosition, remainingStack);
|
||||
}
|
||||
|
||||
entity.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,6 +332,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
*/
|
||||
private ItemStack tryGrabFromPosition(Vector3 position, ForgeDirection direction)
|
||||
{
|
||||
ItemStack returnStack = null;
|
||||
TileEntity tileEntity = position.getTileEntity(this.worldObj);
|
||||
|
||||
if (tileEntity != null)
|
||||
|
@ -357,6 +363,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
}
|
||||
}
|
||||
|
||||
chestSearch:
|
||||
for (TileEntityChest chest : chests)
|
||||
{
|
||||
if (chest != null)
|
||||
|
@ -364,8 +371,12 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
for (int i = 0; i < chest.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack itemStack = this.removeStackFromInventory(i, chest);
|
||||
|
||||
if (itemStack != null)
|
||||
return itemStack;
|
||||
{
|
||||
returnStack = itemStack;
|
||||
break chestSearch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -380,7 +391,10 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
{
|
||||
ItemStack itemStack = this.removeStackFromInventory(i, inventory);
|
||||
if (itemStack != null)
|
||||
return itemStack;
|
||||
{
|
||||
returnStack = itemStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IInventory)
|
||||
|
@ -391,11 +405,15 @@ public class TileEntityManipulator extends TileEntityFilterable implements IReds
|
|||
{
|
||||
ItemStack itemStack = this.removeStackFromInventory(i, inventory);
|
||||
if (itemStack != null)
|
||||
return itemStack;
|
||||
{
|
||||
returnStack = itemStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.isFiltering(returnStack)) { return returnStack; }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,19 +110,7 @@ public class TileEntityRejector extends TileEntityFilterable
|
|||
EntityItem entityItem = (EntityItem) entity;
|
||||
ItemStack itemStack = entityItem.func_92014_d();
|
||||
|
||||
if (getFilter() != null)
|
||||
{
|
||||
ArrayList<ItemStack> checkStacks = ItemFilter.getFilters(getFilter());
|
||||
|
||||
// Reject matching items
|
||||
for (int i = 0; i < checkStacks.size(); i++)
|
||||
{
|
||||
if (checkStacks.get(i) != null)
|
||||
{
|
||||
if (checkStacks.get(i).isItemEqual(itemStack)) { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.isFiltering(itemStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -16,7 +16,7 @@ import assemblyline.common.machine.filter.TileEntityFilterable;
|
|||
public class TileEntityDetector extends TileEntityFilterable
|
||||
{
|
||||
private boolean powering = false;
|
||||
private boolean inverted = false;
|
||||
private boolean isInverted = false;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
|
@ -38,50 +38,25 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
for (int i = 0; i < entities.size(); i++)
|
||||
{
|
||||
EntityItem e = (EntityItem) entities.get(i);
|
||||
ItemStack item = e.func_92014_d();
|
||||
boolean found = false;
|
||||
ItemStack itemStack = e.func_92014_d();
|
||||
|
||||
ArrayList<ItemStack> checkStacks = ItemFilter.getFilters(getFilter());
|
||||
boolean found = this.isFiltering(itemStack);
|
||||
|
||||
for (int ii = 0; ii < checkStacks.size(); ii++)
|
||||
{
|
||||
ItemStack compare = checkStacks.get(ii);
|
||||
|
||||
if (compare != null)
|
||||
{
|
||||
if (item.itemID == compare.itemID)
|
||||
{
|
||||
if (item.getItemDamage() == compare.getItemDamage())
|
||||
{
|
||||
if (item.hasTagCompound())
|
||||
{
|
||||
if (item.getTagCompound().equals(compare.getTagCompound()))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.inverted)
|
||||
if (this.isInverted)
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
powerCheck = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
powerCheck = false;
|
||||
}
|
||||
}
|
||||
else if (found)
|
||||
{
|
||||
powerCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +82,7 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
this.worldObj.notifyBlocksOfNeighborChange(x, this.yCoord + 1, z, AssemblyLine.blockDetector.blockID);
|
||||
}
|
||||
}
|
||||
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket());
|
||||
}
|
||||
}
|
||||
|
@ -115,18 +91,19 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, AssemblyLine.blockDetector.blockID);
|
||||
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector.blockID);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
public boolean isInverted()
|
||||
{
|
||||
return inverted;
|
||||
return this.isInverted;
|
||||
}
|
||||
|
||||
public void setInversion(boolean inverted)
|
||||
{
|
||||
this.inverted = inverted;
|
||||
this.isInverted = inverted;
|
||||
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
|
@ -136,7 +113,7 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
|
||||
public void toggleInversion()
|
||||
{
|
||||
this.setInversion(!this.inverted);
|
||||
this.setInversion(!this.isInverted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,7 +121,7 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
{
|
||||
super.readFromNBT(tag);
|
||||
|
||||
this.inverted = tag.getBoolean("isInverted");
|
||||
this.isInverted = tag.getBoolean("isInverted");
|
||||
this.powering = tag.getBoolean("powering");
|
||||
}
|
||||
|
||||
|
@ -153,7 +130,7 @@ public class TileEntityDetector extends TileEntityFilterable
|
|||
{
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setBoolean("isInverted", this.inverted);
|
||||
tag.setBoolean("isInverted", this.isInverted);
|
||||
tag.setBoolean("powering", this.powering);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,32 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp
|
|||
{
|
||||
private ItemStack filterItem;
|
||||
|
||||
/**
|
||||
* Looks through the things in the filter and finds out which item is being filtered.
|
||||
*
|
||||
* @return Is this filterable block filtering this specific ItemStack?
|
||||
*/
|
||||
public boolean isFiltering(ItemStack itemStack)
|
||||
{
|
||||
if (this.getFilter() != null && itemStack != null)
|
||||
{
|
||||
ArrayList<ItemStack> checkStacks = ItemFilter.getFilters(getFilter());
|
||||
|
||||
if (checkStacks != null)
|
||||
{
|
||||
for (int i = 0; i < checkStacks.size(); i++)
|
||||
{
|
||||
if (checkStacks.get(i) != null)
|
||||
{
|
||||
if (checkStacks.get(i).isItemEqual(itemStack)) { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
|
@ -121,7 +147,7 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp
|
|||
public void setFilter(ItemStack filter)
|
||||
{
|
||||
this.setInventorySlotContents(0, filter);
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket());
|
||||
PacketManager.sendPacketToClients(this.getDescriptionPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,9 +168,6 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp
|
|||
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getInvName();
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue