made progress with robot loading / unloading, for #1921

This commit is contained in:
SpaceToad 2014-06-29 16:58:44 +02:00
parent 8ca47462d5
commit 27cf9473c6
8 changed files with 91 additions and 72 deletions

View file

@ -79,13 +79,18 @@ public class AIRobot {
}
public final void cycle() {
preempt(delegateAI);
try {
preempt(delegateAI);
if (delegateAI != null) {
delegateAI.cycle();
} else {
robot.setEnergy(robot.getEnergy() - getEnergyCost());
update();
if (delegateAI != null) {
delegateAI.cycle();
} else {
robot.setEnergy(robot.getEnergy() - getEnergyCost());
update();
}
} catch (Throwable e) {
e.printStackTrace();
abort();
}
}

View file

@ -68,7 +68,6 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.StatementManager;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.robots.DockingStationRegistry;
import buildcraft.builders.urbanism.EntityRobotUrbanism;
import buildcraft.core.BlockSpring;
import buildcraft.core.BuildCraftConfiguration;
import buildcraft.core.CommandBuildCraft;
@ -336,8 +335,6 @@ public class BuildCraftCore extends BuildCraftMod {
loadRecipes();
}
EntityRegistry.registerModEntity(EntityRobot.class, "bcRobot", EntityIds.ROBOT, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityRobotUrbanism.class, "bcRobotUrbanism", EntityIds.ROBOT_URBANISM, instance, 50, 1, true);
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcRobot");
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser");
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser");

View file

@ -1,54 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.builders.urbanism;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import buildcraft.core.robots.EntityRobot;
public class EntityRobotUrbanism extends EntityRobot {
UrbanistTask task;
public EntityRobotUrbanism(World par1World) {
super(par1World);
}
public boolean isAvailable () {
return task == null;
}
public void setTask (UrbanistTask task) {
this.task = task;
if (!worldObj.isRemote) {
task.setup(this);
}
}
@Override
public void onUpdate() {
super.onUpdate();
if (!worldObj.isRemote) {
if (task != null) {
task.update(this);
if (task.done()) {
task = null;
}
}
}
}
@Override
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {
this.setDead();
}
}

View file

@ -10,6 +10,11 @@ package buildcraft.core.robots;
import java.util.LinkedList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.utils.PathFinding;
@ -48,20 +53,18 @@ public class AIRobotGotoBlock extends AIRobotGoto {
@Override
public void start() {
robot.undock();
}
if (path == null) {
@Override
public void update() {
if (path == null && pathSearch == null) {
pathSearch = new PathFinding(robot.worldObj, new BlockIndex((int) Math.floor(robot.posX),
(int) Math.floor(robot.posY), (int) Math.floor(robot.posZ)), new BlockIndex(
(int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)));
pathSearchJob = new PathFindingJob(pathSearch, 100);
pathSearchJob.start();
}
}
@Override
public void update() {
if (path != null) {
} else if (path != null) {
double distance = robot.getDistance(nextX, nextY, nextZ);
if (!robot.isMoving() || distance > prevDistance) {
@ -116,4 +119,46 @@ public class AIRobotGotoBlock extends AIRobotGoto {
robot.motionZ = 0;
}
}
@Override
public void writeSelfToNBT(NBTTagCompound nbt) {
super.writeSelfToNBT(nbt);
nbt.setFloat("finalX", finalX);
nbt.setFloat("finalY", finalY);
nbt.setFloat("finalZ", finalZ);
if (path != null) {
NBTTagList pathList = new NBTTagList();
for (BlockIndex i : path) {
NBTTagCompound subNBT = new NBTTagCompound();
i.writeTo(subNBT);
pathList.appendTag(subNBT);
}
nbt.setTag("path", pathList);
}
}
@Override
public void loadSelfFromNBT(NBTTagCompound nbt) {
super.loadSelfFromNBT(nbt);
finalX = nbt.getFloat("finalX");
finalY = nbt.getFloat("finalY");
finalZ = nbt.getFloat("finalZ");
if (nbt.hasKey("path")) {
NBTTagList pathList = nbt.getTagList("path", Constants.NBT.TAG_COMPOUND);
path = new LinkedList<BlockIndex>();
for (int i = 0; i < pathList.tagCount(); ++i) {
path.add(new BlockIndex(pathList.getCompoundTagAt(i)));
}
setNextInPath();
}
}
}

View file

@ -32,7 +32,11 @@ public class AIRobotMain extends AIRobot {
@Override
public void update() {
startDelegateAI(robot.getBoard());
AIRobot board = robot.getBoard();
if (board != null) {
startDelegateAI(board);
}
}
@Override

View file

@ -222,6 +222,14 @@ public class EntityRobot extends EntityRobotBase implements
if (mjStored <= 0) {
setDead();
}
if (linkedDockingStation == null) {
// Defensive code. There should always be a station linked, but
// in case there's not (consecutive to a wrong load for
// example), just kill the robot.
setDead();
}
}
super.onUpdate();
@ -338,6 +346,8 @@ public class EntityRobot extends EntityRobotBase implements
laser.writeToNBT(nbtLaser);
nbt.setTag("laser", nbtLaser);
nbt.setDouble("mjStored", mjStored);
for (int i = 0; i < inv.length; ++i) {
NBTTagCompound stackNbt = new NBTTagCompound();
@ -350,7 +360,7 @@ public class EntityRobot extends EntityRobotBase implements
NBTTagCompound ai = new NBTTagCompound();
mainAI.writeToNBT(ai);
nbt.setTag("mainAi", ai);
nbt.setTag("mainAI", ai);
if (mainAI.getDelegateAI() != board) {
NBTTagCompound boardNBT = new NBTTagCompound();
@ -374,6 +384,8 @@ public class EntityRobot extends EntityRobotBase implements
laser.readFromNBT(nbt.getCompoundTag("laser"));
mjStored = nbt.getDouble("mjStored");
for (int i = 0; i < inv.length; ++i) {
inv[i] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("inv[" + i + "]"));
}
@ -388,6 +400,8 @@ public class EntityRobot extends EntityRobotBase implements
} else {
board = (RedstoneBoardRobot) mainAI.getDelegateAI();
}
dataWatcher.updateObject(16, board.getNBTHandler().getID());
}
@Override

View file

@ -19,6 +19,10 @@ import buildcraft.api.robots.EntityRobotBase;
public class BoardRobotLumberjack extends BoardRobotGenericBreakBlock {
public BoardRobotLumberjack(EntityRobotBase iRobot) {
super(iRobot);
}
public BoardRobotLumberjack(EntityRobotBase iRobot, NBTTagCompound nbt) {
super(iRobot);
}

View file

@ -42,6 +42,10 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
private int range;
private IStackFilter stackFilter;
public BoardRobotPicker(EntityRobotBase iRobot) {
super(iRobot);
}
public BoardRobotPicker(EntityRobotBase robot, NBTTagCompound nbt) {
super(robot);
data = nbt;