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