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 ForgeDirection orientation;
|
||||||
|
|
||||||
public Position() {
|
public Position() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
z = 0;
|
||||||
|
orientation = ForgeDirection.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position(double ci, double cj, double ck) {
|
public Position(double ci, double cj, double ck) {
|
||||||
|
@ -127,12 +130,14 @@ public class Position {
|
||||||
nbttagcompound.setDouble("i", x);
|
nbttagcompound.setDouble("i", x);
|
||||||
nbttagcompound.setDouble("j", y);
|
nbttagcompound.setDouble("j", y);
|
||||||
nbttagcompound.setDouble("k", z);
|
nbttagcompound.setDouble("k", z);
|
||||||
|
nbttagcompound.setByte("orientation", (byte) orientation.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
x = nbttagcompound.getDouble("i");
|
x = nbttagcompound.getDouble("i");
|
||||||
y = nbttagcompound.getDouble("j");
|
y = nbttagcompound.getDouble("j");
|
||||||
z = nbttagcompound.getDouble("k");
|
z = nbttagcompound.getDouble("k");
|
||||||
|
orientation = ForgeDirection.values() [nbttagcompound.getByte("orientation")];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.LinkedList;
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import buildcraft.api.core.SafeTimeTracker;
|
import buildcraft.api.core.SafeTimeTracker;
|
||||||
import buildcraft.api.mj.MjBattery;
|
import buildcraft.api.mj.MjBattery;
|
||||||
import buildcraft.core.IBoxProvider;
|
import buildcraft.core.IBoxProvider;
|
||||||
|
@ -22,8 +21,8 @@ import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.network.NetworkData;
|
import buildcraft.core.network.NetworkData;
|
||||||
import buildcraft.core.network.RPC;
|
import buildcraft.core.network.RPC;
|
||||||
import buildcraft.core.network.RPCHandler;
|
import buildcraft.core.network.RPCHandler;
|
||||||
|
import buildcraft.core.network.RPCMessageInfo;
|
||||||
import buildcraft.core.network.RPCSide;
|
import buildcraft.core.network.RPCSide;
|
||||||
import buildcraft.core.utils.Utils;
|
|
||||||
|
|
||||||
public abstract class TileAbstractBuilder extends TileBuildCraft implements IInventory, IBoxProvider {
|
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);
|
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
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
@ -87,37 +102,17 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements IInv
|
||||||
mjStored -= quantity;
|
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
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.writeToNBT(nbttagcompound);
|
super.writeToNBT(nbttagcompound);
|
||||||
|
|
||||||
nbttagcompound.setDouble("mjStored", mjStored);
|
mjStored = nbttagcompound.getDouble("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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
private LinkedList <ItemStack> requiredToBuild;
|
||||||
|
|
||||||
|
NBTTagCompound initNBT = null;
|
||||||
|
|
||||||
private class PathIterator {
|
private class PathIterator {
|
||||||
|
|
||||||
public Iterator<BlockIndex> currentIterator;
|
public Iterator<BlockIndex> currentIterator;
|
||||||
|
@ -189,6 +191,26 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
||||||
return;
|
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;
|
box.kind = Kind.STRIPES;
|
||||||
|
|
||||||
for (int x = xCoord - 1; x <= xCoord + 1; ++x) {
|
for (int x = xCoord - 1; x <= xCoord + 1; ++x) {
|
||||||
|
@ -445,6 +467,9 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
done = nbttagcompound.getBoolean("done");
|
done = nbttagcompound.getBoolean("done");
|
||||||
|
|
||||||
|
// The rest of load has to be done upon initialize.
|
||||||
|
initNBT = nbttagcompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -475,7 +500,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
||||||
|
|
||||||
if (bluePrintBuilder != null) {
|
if (bluePrintBuilder != null) {
|
||||||
NBTTagCompound builderCpt = new NBTTagCompound();
|
NBTTagCompound builderCpt = new NBTTagCompound();
|
||||||
bluePrintBuilder.saveBuildStateToNBT(builderCpt);
|
bluePrintBuilder.saveBuildStateToNBT(builderCpt, this);
|
||||||
nbttagcompound.setTag("builderState", builderCpt);
|
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();
|
NBTTagList clearList = new NBTTagList();
|
||||||
|
|
||||||
for (BlockIndex loc : clearedLocations) {
|
for (BlockIndex loc : clearedLocations) {
|
||||||
|
@ -174,9 +174,19 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
nbt.setTag("builtList", builtList);
|
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());
|
NBTTagList clearList = nbt.getTagList("clearList", Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||||
|
|
||||||
for (int i = 0; i < clearList.tagCount(); ++i) {
|
for (int i = 0; i < clearList.tagCount(); ++i) {
|
||||||
|
@ -192,5 +202,16 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
||||||
|
|
||||||
builtLocations.add (new BlockIndex(cpt));
|
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…
Add table
Reference in a new issue