added control of wether an AI can be loaded from NBT

This commit is contained in:
SpaceToad 2014-08-18 09:07:57 +02:00
parent 846e186c9a
commit 4f41d134a7
6 changed files with 35 additions and 3 deletions

View file

@ -25,4 +25,9 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa
} }
@Override
public boolean canLoadFromNBT() {
return true;
}
} }

View file

@ -64,6 +64,10 @@ public class AIRobot {
return 0.1; return 0.1;
} }
public boolean canLoadFromNBT() {
return false;
}
/** /**
* Tries to receive items in parameters, return items that are left after * Tries to receive items in parameters, return items that are left after
* the operation. * the operation.
@ -150,7 +154,7 @@ public class AIRobot {
writeSelfToNBT(data); writeSelfToNBT(data);
nbt.setTag("data", data); nbt.setTag("data", data);
if (delegateAI != null) { if (delegateAI != null && delegateAI.canLoadFromNBT()) {
NBTTagCompound sub = new NBTTagCompound(); NBTTagCompound sub = new NBTTagCompound();
delegateAI.writeToNBT(sub); delegateAI.writeToNBT(sub);
@ -167,8 +171,11 @@ public class AIRobot {
try { try {
delegateAI = (AIRobot) Class.forName(sub.getString("class")).getConstructor(EntityRobotBase.class) delegateAI = (AIRobot) Class.forName(sub.getString("class")).getConstructor(EntityRobotBase.class)
.newInstance(robot); .newInstance(robot);
delegateAI.parentAI = this;
delegateAI.loadFromNBT(sub); if (delegateAI.canLoadFromNBT()) {
delegateAI.parentAI = this;
delegateAI.loadFromNBT(sub);
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -133,6 +133,11 @@ public class AIRobotGotoBlock extends AIRobotGoto {
} }
} }
@Override
public boolean canLoadFromNBT() {
return true;
}
@Override @Override
public void writeSelfToNBT(NBTTagCompound nbt) { public void writeSelfToNBT(NBTTagCompound nbt) {
super.writeSelfToNBT(nbt); super.writeSelfToNBT(nbt);

View file

@ -31,4 +31,9 @@ public class AIRobotGotoSleep extends AIRobot {
terminate(); terminate();
} }
} }
@Override
public boolean canLoadFromNBT() {
return true;
}
} }

View file

@ -79,6 +79,11 @@ public class AIRobotGotoStation extends AIRobot {
return docked; return docked;
} }
@Override
public boolean canLoadFromNBT() {
return true;
}
@Override @Override
public void writeSelfToNBT(NBTTagCompound nbt) { public void writeSelfToNBT(NBTTagCompound nbt) {
NBTTagCompound indexNBT = new NBTTagCompound(); NBTTagCompound indexNBT = new NBTTagCompound();

View file

@ -55,4 +55,9 @@ public class AIRobotMain extends AIRobot {
public AIRobot getOverridingAI() { public AIRobot getOverridingAI() {
return overridingAI; return overridingAI;
} }
@Override
public boolean canLoadFromNBT() {
return true;
}
} }