From bd4fb9ccd2c8661ec2ed43de6693ce7346132f7f Mon Sep 17 00:00:00 2001 From: Rseifert Date: Sun, 22 Jul 2012 21:24:46 -0400 Subject: [PATCH] recoded control to use bots setup controler to use bots for task rather than mine itself. --- .../src/eui/robotics/TileEntityComp.java | 115 +++++++++++++++--- 1 file changed, 95 insertions(+), 20 deletions(-) diff --git a/minecraft/net/minecraft/src/eui/robotics/TileEntityComp.java b/minecraft/net/minecraft/src/eui/robotics/TileEntityComp.java index 0d3a18e6..170388ae 100644 --- a/minecraft/net/minecraft/src/eui/robotics/TileEntityComp.java +++ b/minecraft/net/minecraft/src/eui/robotics/TileEntityComp.java @@ -12,6 +12,8 @@ import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.Material; import net.minecraft.src.ModLoader; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NBTTagList; import net.minecraft.src.TileEntity; import net.minecraft.src.universalelectricity.Vector3; 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) { ++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)) { ++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); updateCount = 0; Vector3 targetVec = findBlock(thisBlock,Block.leaves,2,hasScanned); @@ -48,24 +64,49 @@ public class TileEntityComp extends TileEntityElectricUnit { int Targetz = targetVec.intZ(); ModLoader.getMinecraftInstance().thePlayer.addChatMessage("rb:"+Targetx+"X:"+Targety+"Y:"+Targetz+"Z"); int blockTargetc = worldObj.getBlockId(Targetx, Targety, Targetz); - worldObj.setBlock(Targetx, Targety, Targetz, 0); - - if(blockTargetc > 0) - { - EntityItem dropedItem = new EntityItem(worldObj, Targetx, Targety - 0.3D, Targetz, new ItemStack(blockTargetc,1,1)); - worldObj.spawnEntityInWorld(dropedItem); - } + boolean taskreceived = sendTask(targetVec,"harvest"); + if(taskreceived) + { + ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Harvest Task sent to robot"); + } + else + { + ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Task not sent"); + } } else { - ModLoader.getMinecraftInstance().thePlayer.addChatMessage("N/A");//nothing found froms scan + ModLoader.getMinecraftInstance().thePlayer.addChatMessage("N/A");//nothing found from scan 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 @@ -93,7 +134,7 @@ public class TileEntityComp extends TileEntityElectricUnit { Startz += range; Starty += range; int pauseCount = 0; - ModLoader.getMinecraftInstance().thePlayer.addChatMessage("starting Scan For " + block.getBlockName()); + //ModLoader.getMinecraftInstance().thePlayer.addChatMessage("starting Scan For " + block.getBlockName()); int y = Starty; for(int iY=0;iY < (distanceY*2);iY++) { @@ -110,11 +151,11 @@ public class TileEntityComp extends TileEntityElectricUnit { { 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) { Vector3 targetBlock = new Vector3(x,y,z); - ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Target Block Found"); + //ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Target Block Found"); return targetBlock; } @@ -137,9 +178,25 @@ public class TileEntityComp extends TileEntityElectricUnit { 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. 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) { - + 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 { @@ -175,4 +238,16 @@ public class TileEntityComp extends TileEntityElectricUnit { { return true; } + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + super.readFromNBT(par1NBTTagCompound); + + } + /** + * Writes a tile entity to NBT. + */ + public void writeToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeToNBT(par1NBTTagCompound); + } }