Attempt to allow imprinters to steal items
This commit is contained in:
parent
0019108b57
commit
3388b3cbdc
5 changed files with 225 additions and 74 deletions
|
@ -113,6 +113,7 @@ public class BlockCrate extends BlockMachine
|
|||
else
|
||||
{
|
||||
ItemStack stack = tileEntity.getStackInSlot(0);
|
||||
|
||||
if (stack != null)
|
||||
{
|
||||
this.ejectItems(tileEntity, player, stack.getMaxStackSize());
|
||||
|
@ -183,6 +184,7 @@ public class BlockCrate extends BlockMachine
|
|||
if (requestStack.isItemEqual(currentStack))
|
||||
{
|
||||
player.inventory.setInventorySlotContents(i, this.putIn(tileEntity, currentStack));
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
|
||||
|
|
|
@ -182,19 +182,6 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public ArrayList getPacketData() { ArrayList list = super.getPacketData();
|
||||
* list.add(this.isOutput); list.add(this.wattsReceived); return list; }
|
||||
*
|
||||
* @Override public void handlePacketData(INetworkManager network, int packetType,
|
||||
* Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { if
|
||||
* (worldObj.isRemote) { ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
|
||||
* DataInputStream dis = new DataInputStream(bis); int id, x, y, z; try { id = dis.readInt(); x
|
||||
* = dis.readInt(); y = dis.readInt(); z = dis.readInt(); NBTTagCompound tag =
|
||||
* Packet.readNBTTagCompound(dis); readFromNBT(tag); this.wattsReceived = dis.readDouble();
|
||||
* this.isOutput = dis.readBoolean(); } catch (IOException e) { e.printStackTrace(); } } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Throws the items from the manipulator into the world.
|
||||
*
|
||||
|
|
|
@ -19,7 +19,7 @@ public class BlockCraneController extends BlockMachine
|
|||
super("cranecontroller", id, UniversalElectricity.machine);
|
||||
this.setResistance(5.0f);
|
||||
this.setHardness(5.0f);
|
||||
this.setCreativeTab(TabAssemblyLine.INSTANCE);
|
||||
//this.setCreativeTab(TabAssemblyLine.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,8 +10,8 @@ public class BlockCraneParts extends BlockMachine
|
|||
|
||||
public BlockCraneParts(int id)
|
||||
{
|
||||
super("CraneParts", id, Material.iron, TabAssemblyLine.INSTANCE);
|
||||
|
||||
super("CraneParts", id, Material.iron);
|
||||
// this.setCreativeTab(TabAssemblyLine.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
|
@ -12,13 +13,17 @@ import net.minecraft.item.crafting.ShapedRecipes;
|
|||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.ISidedInventory;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.TranslationHelper;
|
||||
import universalelectricity.prefab.multiblock.TileEntityMulti;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
import assemblyline.api.IArmbot;
|
||||
import assemblyline.api.IArmbotUseable;
|
||||
|
@ -252,7 +257,6 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
@Override
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
|
||||
/**
|
||||
* Makes the stamping recipe for filters
|
||||
*/
|
||||
|
@ -371,6 +375,24 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
{
|
||||
if (searchStack != null)
|
||||
{
|
||||
inventories:
|
||||
for (IInventory inventory : getAvaliableInventories())
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack checkStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (checkStack != null)
|
||||
{
|
||||
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
|
||||
{
|
||||
inventory.decrStackSize(i, 1);
|
||||
break inventories;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.containingItems.length; i++)
|
||||
{
|
||||
ItemStack checkStack = this.containingItems[i];
|
||||
|
@ -481,7 +503,6 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
if (hasResources != null)
|
||||
{
|
||||
|
||||
return new Pair<ItemStack, ItemStack[]>(((IRecipe) object).getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
|
||||
}
|
||||
}
|
||||
|
@ -511,6 +532,8 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
* @param recipeItems - The items to be checked for the recipes.
|
||||
*/
|
||||
public ArrayList<ItemStack> hasResource(Object[] recipeItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
/**
|
||||
* Simulate an imprinter.
|
||||
|
@ -535,29 +558,20 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
if (recipeItem != null)
|
||||
{
|
||||
for (int i = 0; i < this.containingItems.length; i++)
|
||||
if (this.doesItemExist(recipeItem, dummyImprinter))
|
||||
{
|
||||
ItemStack checkStack = this.containingItems[i];
|
||||
|
||||
if (checkStack != null)
|
||||
{
|
||||
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
|
||||
{
|
||||
// TODO Do NBT Checking
|
||||
dummyImprinter.decrStackSize(i + INVENTORY_START, 1);
|
||||
itemMatch++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (obj instanceof ArrayList)
|
||||
{
|
||||
/**
|
||||
* Look for various possible ingredients of the same item and try to match it.
|
||||
*/
|
||||
ArrayList ingredientsList = (ArrayList) obj;
|
||||
Object[] ingredientsArray = ingredientsList.toArray();
|
||||
|
||||
optionsLoop:
|
||||
for (int x = 0; x < ingredientsArray.length; x++)
|
||||
{
|
||||
if (ingredientsArray[x] != null && ingredientsArray[x] instanceof ItemStack)
|
||||
|
@ -567,20 +581,10 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
if (recipeItem != null)
|
||||
{
|
||||
for (int i = 0; i < this.containingItems.length; i++)
|
||||
if (this.doesItemExist(recipeItem, dummyImprinter))
|
||||
{
|
||||
ItemStack checkStack = this.containingItems[i];
|
||||
|
||||
if (checkStack != null)
|
||||
{
|
||||
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
|
||||
{
|
||||
// TODO Do NBT CHecking
|
||||
dummyImprinter.decrStackSize(i + INVENTORY_START, 1);
|
||||
itemMatch++;
|
||||
break optionsLoop;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -590,6 +594,164 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
return itemMatch >= actualResources.size() ? actualResources : null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to find recipes in the imprinter.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean doesItemExist(ItemStack recipeItem, TileEntityImprinter dummyImprinter)
|
||||
{
|
||||
for (int i = 0; i < dummyImprinter.containingItems.length; i++)
|
||||
{
|
||||
ItemStack checkStack = dummyImprinter.containingItems[i];
|
||||
|
||||
if (checkStack != null)
|
||||
{
|
||||
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
|
||||
{
|
||||
// TODO Do NBT Checking
|
||||
dummyImprinter.decrStackSize(i + INVENTORY_START, 1);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (IInventory inventory : getSimulatedAvaliableInventories())
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack checkStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (checkStack != null)
|
||||
{
|
||||
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
|
||||
{
|
||||
// TODO Do NBT Checking
|
||||
inventory.decrStackSize(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<IInventory> getAvaliableInventories()
|
||||
{
|
||||
List<IInventory> inventories = new ArrayList<IInventory>();
|
||||
|
||||
if (this.searchInventories)
|
||||
{
|
||||
for (int side = 0; side < 6; side++)
|
||||
{
|
||||
Vector3 position = new Vector3(this);
|
||||
position.modifyPositionFromSide(ForgeDirection.getOrientation(side));
|
||||
TileEntity tileEntity = position.getTileEntity(this.worldObj);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
/**
|
||||
* Try to put items into a chest.
|
||||
*/
|
||||
if (tileEntity instanceof TileEntityMulti)
|
||||
{
|
||||
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition;
|
||||
|
||||
if (mainBlockPosition != null)
|
||||
{
|
||||
if (mainBlockPosition.getTileEntity(this.worldObj) instanceof IInventory)
|
||||
{
|
||||
inventories.add((IInventory) mainBlockPosition.getTileEntity(this.worldObj));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof TileEntityChest)
|
||||
{
|
||||
inventories.add((TileEntityChest) tileEntity);
|
||||
|
||||
/**
|
||||
* Try to find a double chest.
|
||||
*/
|
||||
for (int i = 2; i < 6; i++)
|
||||
{
|
||||
ForgeDirection searchDirection = ForgeDirection.getOrientation(i);
|
||||
Vector3 searchPosition = position.clone();
|
||||
searchPosition.modifyPositionFromSide(searchDirection);
|
||||
|
||||
if (searchPosition.getTileEntity(this.worldObj) != null)
|
||||
{
|
||||
if (searchPosition.getTileEntity(this.worldObj).getClass() == tileEntity.getClass())
|
||||
{
|
||||
inventories.add((TileEntityChest) searchPosition.getTileEntity(this.worldObj));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (tileEntity instanceof IInventory && !(tileEntity instanceof TileEntityImprinter))
|
||||
{
|
||||
inventories.add((IInventory) tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return inventories;
|
||||
}
|
||||
|
||||
private List<IInventory> getSimulatedAvaliableInventories()
|
||||
{
|
||||
List<IInventory> simulatedInventories = new ArrayList<IInventory>();
|
||||
|
||||
/**
|
||||
* Create a simulated version of all TileEntities.
|
||||
*/
|
||||
for (IInventory inventory : this.getAvaliableInventories())
|
||||
{
|
||||
if (inventory instanceof TileEntity)
|
||||
{
|
||||
TileEntity tileEntity = (TileEntity) inventory;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: Get Client Side Working.
|
||||
TileEntity simulatedTileEntity = tileEntity.getClass().newInstance();
|
||||
simulatedTileEntity.worldObj = tileEntity.worldObj;
|
||||
|
||||
NBTTagCompound cloneData = new NBTTagCompound();
|
||||
tileEntity.writeToNBT(cloneData);
|
||||
tileEntity.readFromNBT(cloneData);
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (itemStack != null)
|
||||
{
|
||||
itemStack = itemStack.copy();
|
||||
}
|
||||
|
||||
((IInventory) simulatedTileEntity).setInventorySlotContents(i, itemStack);
|
||||
}
|
||||
|
||||
simulatedInventories.add((IInventory) simulatedTileEntity);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return simulatedInventories;
|
||||
}
|
||||
|
||||
/**
|
||||
* NBT Data
|
||||
|
|
Loading…
Reference in a new issue