recoded control to use bots

setup controler to use bots for task rather than mine itself.
This commit is contained in:
Rseifert 2012-07-22 21:24:46 -04:00
parent 965e482e13
commit bd4fb9ccd2

View file

@ -12,6 +12,8 @@ import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.Material; import net.minecraft.src.Material;
import net.minecraft.src.ModLoader; import net.minecraft.src.ModLoader;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.universalelectricity.Vector3; import net.minecraft.src.universalelectricity.Vector3;
import net.minecraft.src.universalelectricity.electricity.TileEntityElectricUnit; import net.minecraft.src.universalelectricity.electricity.TileEntityElectricUnit;
@ -28,12 +30,26 @@ public class TileEntityComp extends TileEntityElectricUnit {
public void onUpdate(float watts, float voltage, byte side) public void onUpdate(float watts, float voltage, byte side)
{ {
++updateCount; ++updateCount;
cleanList();
for(int b =0;b<4;b++)
{
if(BotList[b] ==null)
{
//spawn bot for testing
EntityShoeBot bot = new EntityShoeBot(worldObj);
bot.setLocationAndAngles(this.xCoord, this.yCoord+1, this.zCoord, 10, 10);
bot.linkFrq[0]=this.xCoord;
bot.linkFrq[1]=this.yCoord;
bot.linkFrq[2]=this.zCoord;
bot.isLinked = true;
worldObj.spawnEntityInWorld(bot);
BotList[b]=bot;
}
}
if(updateCount >= 100 && worldObj.checkChunksExist(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1)) if(updateCount >= 100 && worldObj.checkChunksExist(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1))
{ {
++scanCount; ++scanCount;
if(scanCount < 10){hasScanned = true;}else{scanCount = 0;} if(scanCount < 10){hasScanned = true;}else{scanCount = 0;hasScanned=false;}
Vector3 thisBlock = new Vector3(this.xCoord,this.yCoord,this.zCoord); Vector3 thisBlock = new Vector3(this.xCoord,this.yCoord,this.zCoord);
updateCount = 0; updateCount = 0;
Vector3 targetVec = findBlock(thisBlock,Block.leaves,2,hasScanned); Vector3 targetVec = findBlock(thisBlock,Block.leaves,2,hasScanned);
@ -48,24 +64,49 @@ public class TileEntityComp extends TileEntityElectricUnit {
int Targetz = targetVec.intZ(); int Targetz = targetVec.intZ();
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("rb:"+Targetx+"X:"+Targety+"Y:"+Targetz+"Z"); ModLoader.getMinecraftInstance().thePlayer.addChatMessage("rb:"+Targetx+"X:"+Targety+"Y:"+Targetz+"Z");
int blockTargetc = worldObj.getBlockId(Targetx, Targety, Targetz); int blockTargetc = worldObj.getBlockId(Targetx, Targety, Targetz);
worldObj.setBlock(Targetx, Targety, Targetz, 0); boolean taskreceived = sendTask(targetVec,"harvest");
if(taskreceived)
if(blockTargetc > 0) {
{ ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Harvest Task sent to robot");
EntityItem dropedItem = new EntityItem(worldObj, Targetx, Targety - 0.3D, Targetz, new ItemStack(blockTargetc,1,1)); }
worldObj.spawnEntityInWorld(dropedItem); else
} {
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Task not sent");
}
} }
else else
{ {
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("N/A");//nothing found froms scan ModLoader.getMinecraftInstance().thePlayer.addChatMessage("N/A");//nothing found from scan
scanCount = 0; scanCount = 0;
} }
//resets scan to zero location every 10 scans
} }
} }
/**
*
* @param taskLoc - location of the task
* @param task - what is the task harvest, replace, mine, build
* @param bot - bot being given the task
* @return whether or not the task was received
*/
public boolean sendTask(Vector3 taskLoc,String task)
{
for(int i = 0;i < BotList.length;i++)
{
if(BotList[i] instanceof EntityRobot)
{
String botTaskMain = BotList[i].getTaskType();
if(botTaskMain.toLowerCase() == task.toLowerCase())
{
if(BotList[i].isIdle())
{
return BotList[i].setWorkTask(taskLoc,task);
}
}
}
}
return false;
}
/** /**
* *
* @param startSpot - center of the scan radius * @param startSpot - center of the scan radius
@ -93,7 +134,7 @@ public class TileEntityComp extends TileEntityElectricUnit {
Startz += range; Startz += range;
Starty += range; Starty += range;
int pauseCount = 0; int pauseCount = 0;
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("starting Scan For " + block.getBlockName()); //ModLoader.getMinecraftInstance().thePlayer.addChatMessage("starting Scan For " + block.getBlockName());
int y = Starty; int y = Starty;
for(int iY=0;iY < (distanceY*2);iY++) for(int iY=0;iY < (distanceY*2);iY++)
{ {
@ -110,11 +151,11 @@ public class TileEntityComp extends TileEntityElectricUnit {
{ {
int blockTargetID = worldObj.getBlockId(x, y, z); int blockTargetID = worldObj.getBlockId(x, y, z);
System.out.println("BlockAt:"+x+"x:"+y+"y:"+z+"z:"+blockTargetID+"ID"); //System.out.println("BlockAt:"+x+"x:"+y+"y:"+z+"z:"+blockTargetID+"ID");
if(blockTargetID == block.blockID) if(blockTargetID == block.blockID)
{ {
Vector3 targetBlock = new Vector3(x,y,z); Vector3 targetBlock = new Vector3(x,y,z);
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Target Block Found"); //ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Target Block Found");
return targetBlock; return targetBlock;
} }
@ -137,9 +178,25 @@ public class TileEntityComp extends TileEntityElectricUnit {
return BotList; return BotList;
} }
public void addBot(EntityRobot bot) public boolean addBot(EntityRobot bot)
{ {
for(int i = 0; i < 4; i++)
{
if(BotList[i] == bot)
{
return true;
}
}
for(int i = 0; i < 4; i++)
{
if(BotList[i] == null)
{
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Bot Added");
BotList[i] = bot;
return true;
}
}
return false;
} }
/**will be used to update the bot list on restart or reload of the world. /**will be used to update the bot list on restart or reload of the world.
This way entity ids that are not bots are not stored in the list. This way entity ids that are not bots are not stored in the list.
@ -152,7 +209,13 @@ public class TileEntityComp extends TileEntityElectricUnit {
{ {
if(BotList[i] instanceof EntityRobot) if(BotList[i] instanceof EntityRobot)
{ {
EntityRobot Bot = BotList[i];
Vector3 thisLoc = new Vector3(this.xCoord,this.yCoord,this.zCoord);
Vector3 botFrq = new Vector3(Bot.linkFrq[0],Bot.linkFrq[1],Bot.linkFrq[2]);
if(!botFrq.isEqual(thisLoc))
{
BotList[i] = null;
}
} }
else else
{ {
@ -175,4 +238,16 @@ public class TileEntityComp extends TileEntityElectricUnit {
{ {
return true; return true;
} }
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
}
/**
* Writes a tile entity to NBT.
*/
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
}
} }