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
This commit is contained in:
parent
8c60099e0e
commit
9aceb50fd6
9 changed files with 176 additions and 106 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@ CHANGELOG
|
|||
!/src/
|
||||
/src/minecraft/*
|
||||
!/src/minecraft/assemblyline/
|
||||
!/src/minecraft/dark/
|
||||
!/src/minecraft/universalelectricity/
|
||||
!/src/minecraft/dan200
|
||||
!/src/minecraft/ic2
|
||||
|
|
|
@ -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<EntityItem> 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<EntityItem> 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<EntityItem> 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<EntityItem> 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ItemStack> 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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package assemblyline.common;
|
||||
package dark.minecraft.helpers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
93
src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java
Normal file
93
src/minecraft/dark/minecraft/helpers/ItemWorldHelper.java
Normal file
|
@ -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<EntityItem> 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<EntityItem> findSelectItems(World world, Vector3 start, Vector3 end, List<ItemStack> disiredItems)
|
||||
{
|
||||
List<EntityItem> entityItems = ItemWorldHelper.findAllItemIn(world, start, end);
|
||||
List<EntityItem> newItemList = new ArrayList<EntityItem>();
|
||||
|
||||
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<ItemStack> items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0);
|
||||
|
||||
for (ItemStack item : items)
|
||||
{
|
||||
dropItemStackExact(world, x + .5, y + .5, z + .5, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue