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

View file

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

View file

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

View file

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

View file

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