Search in sources :

Example 1 with IPipeListener

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;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IPipeListener(buildcraft.api.transport.pipe_bc8.IPipeListener)

Example 2 with IPipeListener

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;
}
Also used : IPipe_BC8(buildcraft.api.transport.pipe_bc8.IPipe_BC8) NBTTagList(net.minecraft.nbt.NBTTagList) PipeBehaviour_BC8(buildcraft.api.transport.pipe_bc8.PipeBehaviour_BC8) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IPipeListener(buildcraft.api.transport.pipe_bc8.IPipeListener)

Aggregations

IPipeListener (buildcraft.api.transport.pipe_bc8.IPipeListener)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IPipe_BC8 (buildcraft.api.transport.pipe_bc8.IPipe_BC8)1 PipeBehaviour_BC8 (buildcraft.api.transport.pipe_bc8.PipeBehaviour_BC8)1 EnumFacing (net.minecraft.util.EnumFacing)1