Worked on drone picking up item

This commit is contained in:
DarkGuardsman 2013-08-31 12:22:19 -04:00
parent c638fdcfeb
commit f1c4f209ef
3 changed files with 18 additions and 6 deletions

View file

@ -1,5 +1,8 @@
package dark.farmtech.machines.farmer; package dark.farmtech.machines.farmer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
public class DroneTask public class DroneTask

View file

@ -1,5 +1,6 @@
package dark.farmtech.machines.farmer; package dark.farmtech.machines.farmer;
import dark.core.helpers.ItemWorldHelper;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -85,9 +86,15 @@ public class EntityFarmDrone extends EntityLiving implements IElectricalStorage
/** Adds an item to the drones inventory or drops it on the ground if the drone is full /** Adds an item to the drones inventory or drops it on the ground if the drone is full
* *
* @param stack */ * @param location - location were the item was so to drop it there if the drone can't pick it
public void pickUpItem(ItemStack stack) * up
* @param stack - stack to store or drop */
public ItemStack pickUpItem(Vector3 location, ItemStack stack, boolean drop)
{ {
if (location == null)
{
location = this.location.clone();
}
ItemStack itemStack = stack.copy(); ItemStack itemStack = stack.copy();
if (stack != null) if (stack != null)
{ {
@ -114,14 +121,15 @@ public class EntityFarmDrone extends EntityLiving implements IElectricalStorage
} }
if (itemStack == null || itemStack.stackSize <= 0) if (itemStack == null || itemStack.stackSize <= 0)
{ {
break; return null;
} }
} }
if (itemStack != null) if (drop && itemStack != null && itemStack.stackSize > 0)
{ {
//TODO drop item on the ground for later pickup return ItemWorldHelper.dropItemStack(this.worldObj, location, itemStack, true);
} }
} }
return itemStack;
} }
/** Check if the inventory has items in all slots rather than if its actually 100% full */ /** Check if the inventory has items in all slots rather than if its actually 100% full */

View file

@ -47,9 +47,10 @@ public class HarvestTask extends DroneTask
ArrayList<ItemStack> items = block.getBlockDropped(drone.worldObj, location.intX(), location.intY(), location.intZ(), metaData, 1); ArrayList<ItemStack> items = block.getBlockDropped(drone.worldObj, location.intX(), location.intY(), location.intZ(), metaData, 1);
for (ItemStack stack : items) for (ItemStack stack : items)
{ {
drone.pickUpItem(stack); drone.pickUpItem(location, stack, true);
} }
} }
drone.worldObj.playAuxSFX(2001, location.intX(), location.intY(), location.intZ(), blockID + (metaData << 12));
//TODO do a few checks and method calls to simulate player like block harvesting as much as possible //TODO do a few checks and method calls to simulate player like block harvesting as much as possible
location.setBlock(drone.worldObj, 0); location.setBlock(drone.worldObj, 0);
} }