From 9aceb50fd63bcc0960aafbc303625d7590f74847 Mon Sep 17 00:00:00 2001 From: Rseifert Date: Fri, 8 Feb 2013 00:32:52 -0500 Subject: [PATCH] minor changes Changed: drop command to drop the item at the exact location instead of dropping it with velocity in a random direction Moved: ArmHelper and DebugToPlayer back to my folder since i'm using similar files in other repos Moved: drop methods from the break command to my helper Cleaned: my helper class up and finished the find all item methods to wrok better Added: powerTo command though it doesn't do anything for the moment --- .gitignore | 1 + .../common/machine/armbot/ArmHelper.java | 53 ----------- .../machine/armbot/TileEntityArmbot.java | 5 +- .../common/machine/command/Command.java | 1 + .../common/machine/command/CommandBreak.java | 46 +-------- .../machine/command/CommandPowerTo.java | 74 +++++++++++++++ .../common/machine/command/CommandUse.java | 7 +- .../minecraft/helpers}/DebugToPlayer.java | 2 +- .../minecraft/helpers/ItemWorldHelper.java | 93 +++++++++++++++++++ 9 files changed, 176 insertions(+), 106 deletions(-) delete mode 100644 src/minecraft/assemblyline/common/machine/armbot/ArmHelper.java create mode 100644 src/minecraft/assemblyline/common/machine/command/CommandPowerTo.java rename src/minecraft/{assemblyline/common => dark/minecraft/helpers}/DebugToPlayer.java (97%) create mode 100644 src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java diff --git a/.gitignore b/.gitignore index a986b02ab..a28e48d19 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ CHANGELOG !/src/ /src/minecraft/* !/src/minecraft/assemblyline/ +!/src/minecraft/dark/ !/src/minecraft/universalelectricity/ !/src/minecraft/dan200 !/src/minecraft/ic2 diff --git a/src/minecraft/assemblyline/common/machine/armbot/ArmHelper.java b/src/minecraft/assemblyline/common/machine/armbot/ArmHelper.java deleted file mode 100644 index 03133d682..000000000 --- a/src/minecraft/assemblyline/common/machine/armbot/ArmHelper.java +++ /dev/null @@ -1,53 +0,0 @@ -package assemblyline.common.machine.armbot; - -import java.util.List; - -import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; - -public class ArmHelper -{ - - /** - * Used to locate items in an area - * - * @param start - start xyz - * @param End - end xyz - * @return list of items - */ - public static List findItems(World world, Vector3 start, Vector3 end) - { - AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(start.x, start.y, start.z, end.x, end.x, end.x); - // EntityItem list - List itemsList = world.getEntitiesWithinAABB(EntityItem.class, bounds); - return itemsList; - } - - /** - * Used to locate an item type in an area - * - * @param world - * @param start - * @param end - * @param item - * @return list of matching items - */ - public static List findItems(World world, Vector3 start, Vector3 end, ItemStack stack) - { - AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(start.x, start.y, start.z, end.x, end.x, end.x); - // EntityItem list - List itemsList = world.getEntitiesWithinAABB(EntityItem.class, bounds); - for (EntityItem item : itemsList) - { - ItemStack stackItem = item.getEntityItem(); - if (stackItem.itemID != stack.itemID || stackItem.getItemDamage() != stack.getItemDamage()) - { - itemsList.remove(item); - } - } - return itemsList; - } -} diff --git a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java index ab884ffd7..e1e50a103 100644 --- a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java +++ b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java @@ -8,7 +8,6 @@ import java.util.EnumSet; import java.util.Iterator; import java.util.List; -import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.item.EntityItem; @@ -31,7 +30,6 @@ import universalelectricity.prefab.multiblock.IMultiBlock; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; import assemblyline.api.IArmbot; -import assemblyline.api.IArmbotUseable; import assemblyline.common.AssemblyLine; import assemblyline.common.machine.TileEntityAssemblyNetwork; import assemblyline.common.machine.command.Command; @@ -52,6 +50,7 @@ import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.relauncher.Side; import dan200.computer.api.IComputerAccess; import dan200.computer.api.IPeripheral; +import dark.minecraft.helpers.ItemWorldHelper; public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage, IArmbot, IPeripheral { @@ -929,7 +928,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult while (it.hasNext()) { - this.worldObj.spawnEntityInWorld(new EntityItem(worldObj, handPosition.x, handPosition.y, handPosition.z, it.next())); + ItemWorldHelper.dropItemStackExact(worldObj, handPosition.x, handPosition.y, handPosition.z, it.next()); } this.grabbedEntities.clear(); diff --git a/src/minecraft/assemblyline/common/machine/command/Command.java b/src/minecraft/assemblyline/common/machine/command/Command.java index cec42edd2..726961114 100644 --- a/src/minecraft/assemblyline/common/machine/command/Command.java +++ b/src/minecraft/assemblyline/common/machine/command/Command.java @@ -32,6 +32,7 @@ public abstract class Command registerCommand("return", CommandReturn.class); registerCommand("repeat", CommandRepeat.class); registerCommand("use", CommandUse.class); + registerCommand("powerto", CommandPowerTo.class); registerCommand("fire", CommandFire.class); registerCommand("break", CommandBreak.class); registerCommand("place", CommandPlace.class); diff --git a/src/minecraft/assemblyline/common/machine/command/CommandBreak.java b/src/minecraft/assemblyline/common/machine/command/CommandBreak.java index eb004f7b4..cbbd0c02a 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandBreak.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandBreak.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import universalelectricity.core.vector.Vector3; +import dark.minecraft.helpers.ItemWorldHelper; /** * Used by arms to break a specific block in a position. @@ -35,7 +35,7 @@ public class CommandBreak extends Command if (!this.keep || items.size() > 1) { - this.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); + ItemWorldHelper.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); } else { @@ -52,47 +52,7 @@ public class CommandBreak extends Command return true; } - /** - * Drops an item stack at the exact center of the coords given - * - * @param world - * @param x - * @param y - * @param z - * @param stack - */ - protected void dropBlockAsItem_do(World world, int x, int y, int z, ItemStack stack) - { - if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) - { - EntityItem entity = new EntityItem(world, (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, stack); - entity.delayBeforeCanPickup = 10; - world.spawnEntityInWorld(entity); - } - } - - /** - * grabs all the items that the block can drop then pass them onto dropBlockAsItem_do - * - * @param world - * @param x - * @param y - * @param z - */ - public void dropBlockAsItem(World world, int x, int y, int z) - { - if (!world.isRemote) - { - int meta = world.getBlockMetadata(x, y, z); - int id = world.getBlockId(x, y, z); - ArrayList items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0); - - for (ItemStack item : items) - { - this.dropBlockAsItem_do(world, x, y, z, item); - } - } - } + @Override public String toString() diff --git a/src/minecraft/assemblyline/common/machine/command/CommandPowerTo.java b/src/minecraft/assemblyline/common/machine/command/CommandPowerTo.java new file mode 100644 index 000000000..e34ecccc9 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/command/CommandPowerTo.java @@ -0,0 +1,74 @@ +package assemblyline.common.machine.command; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import dark.minecraft.helpers.DebugToPlayer; + +public class CommandPowerTo extends Command +{ + private int times; + private int curTimes; + + @Override + public void onTaskStart() + { + this.times = 0; + this.curTimes = 0; + + if (this.getArgs().length > 0) + { + this.times = this.getIntArg(0); + } + + if (this.times <= 0) + this.times = 1; + } + + @Override + protected boolean doTask() + { + Block block = Block.blocksList[this.world.getBlockId(tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ())]; + TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world); + + if (tileEntity.getGrabbedEntities().size() > 0 && tileEntity.getGrabbedEntities().get(0) instanceof EntityItem && ((EntityItem)tileEntity.getGrabbedEntities().get(0)).getEntityItem().itemID == Block.torchRedstoneIdle.blockID) + { + //TODO have armbot cause redstone power at location + DebugToPlayer.SendToClosest(this.tileEntity, 10, "powering"); + } + else + { + return false; + } + + this.curTimes++; + + if (this.curTimes >= this.times) + return false; + + return true; + } + + @Override + public String toString() + { + return "POWERTO " + Integer.toString(this.times); + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) + { + super.readFromNBT(taskCompound); + this.times = taskCompound.getInteger("useTimes"); + this.curTimes = taskCompound.getInteger("useCurTimes"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) + { + super.writeToNBT(taskCompound); + taskCompound.setInteger("useTimes", this.times); + taskCompound.setInteger("useCurTimes", this.curTimes); + } +} diff --git a/src/minecraft/assemblyline/common/machine/command/CommandUse.java b/src/minecraft/assemblyline/common/machine/command/CommandUse.java index d8794d211..dc5e0776e 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandUse.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandUse.java @@ -1,15 +1,10 @@ package assemblyline.common.machine.command; import net.minecraft.block.Block; -import net.minecraft.block.BlockLever; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.common.ISidedInventory; import assemblyline.api.IArmbotUseable; -import assemblyline.common.DebugToPlayer; public class CommandUse extends Command { @@ -57,7 +52,7 @@ public class CommandUse extends Command } } - else + else if(block != null) { try{ boolean f = block.onBlockActivated(this.world, tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ(), null, 0, 0, 0, 0); diff --git a/src/minecraft/assemblyline/common/DebugToPlayer.java b/src/minecraft/dark/minecraft/helpers/DebugToPlayer.java similarity index 97% rename from src/minecraft/assemblyline/common/DebugToPlayer.java rename to src/minecraft/dark/minecraft/helpers/DebugToPlayer.java index 74c8f0f40..ab532cb59 100644 --- a/src/minecraft/assemblyline/common/DebugToPlayer.java +++ b/src/minecraft/dark/minecraft/helpers/DebugToPlayer.java @@ -1,4 +1,4 @@ -package assemblyline.common; +package dark.minecraft.helpers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; diff --git a/src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java b/src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java new file mode 100644 index 000000000..30cbc4b29 --- /dev/null +++ b/src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java @@ -0,0 +1,93 @@ +package dark.minecraft.helpers; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemWorldHelper +{ + + /** + * gets all EntityItems in a location using a start and end point + */ + public static List findAllItemIn(World world, Vector3 start, Vector3 end) + { + return world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(start.x, start.y, start.z, end.x, end.x, end.x)); + } + + /** + * Gets all EntityItems in an area and sorts them by a list of itemStacks + * + * @param world - world being worked in + * @param start - start point + * @param end - end point + * @param disiredItems - list of item that are being looked for + * @return a list of EntityItem that match the itemStacks desired + */ + public static List findSelectItems(World world, Vector3 start, Vector3 end, List disiredItems) + { + List entityItems = ItemWorldHelper.findAllItemIn(world, start, end); + List newItemList = new ArrayList(); + + for (EntityItem entityItem : entityItems) + { + for (ItemStack itemStack : disiredItems) + { + if (entityItem.getEntityItem().itemID == itemStack.itemID && entityItem.getEntityItem().getItemDamage() == itemStack.getItemDamage() && !newItemList.contains(entityItem)) + { + entityItems.add(entityItem); + break; + } + } + } + return newItemList; + } + + /** + * Drops an item stack at the exact center of the location without any velocity or random throw angle + * + * @param world - world to drop the item in + * @param x y z - location vector + * @param stack - itemstack to drop + * @return if the item was spawned in the world + */ + public static boolean dropItemStackExact(World world, double x, double y, double z, ItemStack stack) + { + if (!world.isRemote && stack != null) + { + EntityItem entity = new EntityItem(world, x, y, z, stack); + entity.delayBeforeCanPickup = 10; + return world.spawnEntityInWorld(entity); + } + return false; + } + + /** + * grabs all the items that the block can drop then pass them onto dropBlockAsItem_do + * + * @param world + * @param x + * @param y + * @param z + */ + public static void dropBlockAsItem(World world, int x, int y, int z) + { + if (!world.isRemote) + { + int meta = world.getBlockMetadata(x, y, z); + int id = world.getBlockId(x, y, z); + ArrayList items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0); + + for (ItemStack item : items) + { + dropItemStackExact(world, x + .5, y + .5, z + .5, item); + } + } + } +}