use of buildcraft.api.transport.pipe_bc8.IPipeListener in project BuildCraft by BuildCraft.
the class Pipe_BC8 method writeToNBT.
@Override
public NBTBase writeToNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("behaviour", behaviour.writeToNBT());
NBTTagList list = new NBTTagList();
for (IPipeListener listener : listenerMap.values()) {
NBTTagCompound comp = new NBTTagCompound();
comp.setString("type", PipeAPI_BC8.PIPE_LISTENER_REGISTRY.getGlobalUniqueTag(listener));
comp.setTag("data", listener.writeToNBT());
list.appendTag(comp);
}
nbt.setTag("listeners", list);
NBTTagCompound connections = new NBTTagCompound();
for (EnumFacing face : EnumFacing.values()) {
if (connectionMap.containsKey(face)) {
PipeConnection connection = connectionMap.get(face);
NBTTagCompound compound = connection.saveConnection();
connections.setTag(face.name(), compound);
}
}
nbt.setTag("connections", connections);
return nbt;
}
use of buildcraft.api.transport.pipe_bc8.IPipeListener in project BuildCraft by BuildCraft.
the class Pipe_BC8 method readFromNBT.
@Override
public Pipe_BC8 readFromNBT(NBTBase base) {
NBTTagCompound nbt = (NBTTagCompound) base;
PipeBehaviour_BC8 behaviour = this.behaviour.readFromNBT(nbt.getTag("behaviour"));
Pipe_BC8 pipe = new Pipe_BC8(holder, behaviour, getWorld());
NBTTagList list = nbt.getTagList("listeners", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound comp = list.getCompoundTagAt(i);
String type = comp.getString("type");
IPipeListener listener = PipeAPI_BC8.PIPE_LISTENER_REGISTRY.getFactory(type).createNewListener(pipe);
pipe.bus.registerHandler(listener);
pipe.listenerMap.put(pipe.nextListenerId++, listener);
}
initNBT = (NBTTagCompound) nbt.copy();
return pipe;
}
Aggregations