minor progress in saving builder state, for #1575
This commit is contained in:
parent
8fd7eb4f91
commit
b93c700a8a
4 changed files with 79 additions and 33 deletions
|
@ -22,7 +22,10 @@ public class Position {
|
|||
public ForgeDirection orientation;
|
||||
|
||||
public Position() {
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
orientation = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public Position(double ci, double cj, double ck) {
|
||||
|
@ -127,12 +130,14 @@ public class Position {
|
|||
nbttagcompound.setDouble("i", x);
|
||||
nbttagcompound.setDouble("j", y);
|
||||
nbttagcompound.setDouble("k", z);
|
||||
nbttagcompound.setByte("orientation", (byte) orientation.ordinal());
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
x = nbttagcompound.getDouble("i");
|
||||
y = nbttagcompound.getDouble("j");
|
||||
z = nbttagcompound.getDouble("k");
|
||||
orientation = ForgeDirection.values() [nbttagcompound.getByte("orientation")];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.mj.MjBattery;
|
||||
import buildcraft.core.IBoxProvider;
|
||||
|
@ -22,8 +21,8 @@ import buildcraft.core.TileBuildCraft;
|
|||
import buildcraft.core.network.NetworkData;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCMessageInfo;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public abstract class TileAbstractBuilder extends TileBuildCraft implements IInventory, IBoxProvider {
|
||||
|
||||
|
@ -40,6 +39,22 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements IInv
|
|||
|
||||
protected SafeTimeTracker buildTracker = new SafeTimeTracker(5);
|
||||
|
||||
@Override
|
||||
public void initialize () {
|
||||
super.initialize();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
RPCHandler.rpcServer(this, "uploadBuildersInAction");
|
||||
}
|
||||
}
|
||||
|
||||
@RPC (RPCSide.SERVER)
|
||||
private void uploadBuildersInAction (RPCMessageInfo info) {
|
||||
for (BuildingItem i : buildersInAction) {
|
||||
RPCHandler.rpcPlayer(this, "launchItem", info.sender, i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -87,37 +102,17 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements IInv
|
|||
mjStored -= quantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
mjStored = nbttagcompound.getDouble("mjStored");
|
||||
|
||||
NBTTagList buildingList = new NBTTagList();
|
||||
|
||||
for (BuildingItem item : buildersInAction) {
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
item.writeToNBT(sub);
|
||||
buildingList.appendTag(sub);
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("buildersInAction", buildingList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setDouble("mjStored", mjStored);
|
||||
|
||||
NBTTagList buildingList = nbttagcompound
|
||||
.getTagList("buildersInAction",
|
||||
Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < buildingList.tagCount(); ++i) {
|
||||
BuildingItem item = new BuildingItem();
|
||||
item.readFromNBT(buildingList.getCompoundTagAt(i));
|
||||
addBuildingItem(item);
|
||||
mjStored = nbttagcompound.getDouble("mjStored");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setDouble("mjStored", mjStored);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
|||
|
||||
private LinkedList <ItemStack> requiredToBuild;
|
||||
|
||||
NBTTagCompound initNBT = null;
|
||||
|
||||
private class PathIterator {
|
||||
|
||||
public Iterator<BlockIndex> currentIterator;
|
||||
|
@ -189,6 +191,26 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if (initNBT != null) {
|
||||
iterateBpt();
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
NBTTagCompound builderCpt = new NBTTagCompound();
|
||||
bluePrintBuilder.loadBuildStateToNBT(initNBT, this);
|
||||
initNBT.setTag("builderState", builderCpt);
|
||||
}
|
||||
|
||||
/*
|
||||
* if (currentPathIterator != null) { NBTTagCompound iteratorNBT =
|
||||
* new NBTTagCompound();
|
||||
* currentPathIterator.to.writeTo(iteratorNBT);
|
||||
* nbttagcompound.setTag ("iterator", iteratorNBT); }
|
||||
*/
|
||||
|
||||
initNBT = null;
|
||||
}
|
||||
|
||||
box.kind = Kind.STRIPES;
|
||||
|
||||
for (int x = xCoord - 1; x <= xCoord + 1; ++x) {
|
||||
|
@ -445,6 +467,9 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
|||
}
|
||||
|
||||
done = nbttagcompound.getBoolean("done");
|
||||
|
||||
// The rest of load has to be done upon initialize.
|
||||
initNBT = nbttagcompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -475,7 +500,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
|||
|
||||
if (bluePrintBuilder != null) {
|
||||
NBTTagCompound builderCpt = new NBTTagCompound();
|
||||
bluePrintBuilder.saveBuildStateToNBT(builderCpt);
|
||||
bluePrintBuilder.saveBuildStateToNBT(builderCpt, this);
|
||||
nbttagcompound.setTag("builderState", builderCpt);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveBuildStateToNBT (NBTTagCompound nbt) {
|
||||
public void saveBuildStateToNBT (NBTTagCompound nbt, TileAbstractBuilder builder) {
|
||||
NBTTagList clearList = new NBTTagList();
|
||||
|
||||
for (BlockIndex loc : clearedLocations) {
|
||||
|
@ -174,9 +174,19 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
}
|
||||
|
||||
nbt.setTag("builtList", builtList);
|
||||
|
||||
NBTTagList buildingList = new NBTTagList();
|
||||
|
||||
for (BuildingItem item : builder.buildersInAction) {
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
item.writeToNBT(sub);
|
||||
buildingList.appendTag(sub);
|
||||
}
|
||||
|
||||
public void loadBuildStateToNBT (NBTTagCompound nbt) {
|
||||
nbt.setTag("buildersInAction", buildingList);
|
||||
}
|
||||
|
||||
public void loadBuildStateToNBT (NBTTagCompound nbt, TileAbstractBuilder builder) {
|
||||
NBTTagList clearList = nbt.getTagList("clearList", Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < clearList.tagCount(); ++i) {
|
||||
|
@ -192,5 +202,16 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
|
||||
builtLocations.add (new BlockIndex(cpt));
|
||||
}
|
||||
|
||||
NBTTagList buildingList = nbt
|
||||
.getTagList("buildersInAction",
|
||||
Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < buildingList.tagCount(); ++i) {
|
||||
BuildingItem item = new BuildingItem();
|
||||
item.readFromNBT(buildingList.getCompoundTagAt(i));
|
||||
item.context = getContext();
|
||||
builder.buildersInAction.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue