Search in sources :

Example 1 with Gate

use of buildcraft.transport.Gate in project BuildCraft by BuildCraft.

the class GatePluggable method onAttachedPipe.

@Override
public void onAttachedPipe(IPipeTile pipe, EnumFacing direction) {
    TileGenericPipe pipeReal = (TileGenericPipe) pipe;
    if (!pipeReal.getWorld().isRemote) {
        if (instantiatedGate != null) {
            pipeReal.pipe.gates[direction.ordinal()] = instantiatedGate;
        } else {
            Gate gate = pipeReal.pipe.gates[direction.ordinal()];
            if (gate == null || gate.material != material || gate.logic != logic) {
                pipeReal.pipe.gates[direction.ordinal()] = GateFactory.makeGate(pipeReal.pipe, material, logic, direction);
                for (IGateExpansion expansion : expansions) {
                    pipeReal.pipe.gates[direction.ordinal()].addGateExpansion(expansion);
                }
                pipeReal.scheduleRenderUpdate();
            }
        }
        realGate = pipeReal.pipe.gates[direction.ordinal()];
    }
}
Also used : TileGenericPipe(buildcraft.transport.TileGenericPipe) IGateExpansion(buildcraft.api.gates.IGateExpansion) Gate(buildcraft.transport.Gate) KeyPlugGate(buildcraft.transport.client.model.key.KeyPlugGate)

Example 2 with Gate

use of buildcraft.transport.Gate in project BuildCraft by BuildCraft.

the class GateFactory method makeGate.

public static Gate makeGate(Pipe<?> pipe, NBTTagCompound nbt) {
    GateMaterial material = GateMaterial.REDSTONE;
    GateLogic logic = GateLogic.AND;
    EnumFacing direction = null;
    // Legacy Support
    if (nbt.hasKey("Kind")) {
        int kind = nbt.getInteger("Kind");
        switch(kind) {
            case 1:
            case 2:
                material = GateMaterial.IRON;
                break;
            case 3:
            case 4:
                material = GateMaterial.GOLD;
                break;
            case 5:
            case 6:
                material = GateMaterial.DIAMOND;
                break;
        }
        switch(kind) {
            case 2:
            case 4:
            case 6:
                logic = GateLogic.OR;
                break;
        }
    }
    if (nbt.hasKey("material")) {
        try {
            material = GateMaterial.valueOf(nbt.getString("material"));
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    if (nbt.hasKey("logic")) {
        try {
            logic = GateLogic.valueOf(nbt.getString("logic"));
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    if (nbt.hasKey("direction")) {
        direction = EnumFacing.getFront(nbt.getInteger("direction"));
    }
    Gate gate = makeGate(pipe, material, logic, direction);
    gate.readFromNBT(nbt);
    // Legacy support
    if (nbt.hasKey("Pulser")) {
        NBTTagCompound pulsarTag = nbt.getCompoundTag("Pulser");
        GateExpansionController pulsarCon = GateExpansionPulsar.INSTANCE.makeController(pipe.container);
        pulsarCon.readFromNBT(pulsarTag);
        gate.expansions.put(GateExpansionPulsar.INSTANCE, pulsarCon);
    }
    NBTTagList exList = nbt.getTagList("expansions", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < exList.tagCount(); i++) {
        NBTTagCompound conNBT = exList.getCompoundTagAt(i);
        IGateExpansion ex = GateExpansions.getExpansion(conNBT.getString("type"));
        if (ex != null) {
            GateExpansionController con = ex.makeController(pipe.container);
            con.readFromNBT(conNBT.getCompoundTag("data"));
            gate.expansions.put(ex, con);
        }
    }
    return gate;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) GateMaterial(buildcraft.transport.gates.GateDefinition.GateMaterial) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IGateExpansion(buildcraft.api.gates.IGateExpansion) Gate(buildcraft.transport.Gate) GateExpansionController(buildcraft.api.gates.GateExpansionController) GateLogic(buildcraft.transport.gates.GateDefinition.GateLogic)

Example 3 with Gate

use of buildcraft.transport.Gate in project BuildCraft by BuildCraft.

the class GatePluggable method onDetachedPipe.

@Override
public void onDetachedPipe(IPipeTile pipe, EnumFacing direction) {
    TileGenericPipe pipeReal = (TileGenericPipe) pipe;
    if (!pipeReal.getWorld().isRemote) {
        Gate gate = pipeReal.pipe.gates[direction.ordinal()];
        if (gate != null) {
            gate.resetGate();
            pipeReal.pipe.gates[direction.ordinal()] = null;
        }
        pipeReal.scheduleRenderUpdate();
    }
}
Also used : TileGenericPipe(buildcraft.transport.TileGenericPipe) Gate(buildcraft.transport.Gate) KeyPlugGate(buildcraft.transport.client.model.key.KeyPlugGate)

Aggregations

Gate (buildcraft.transport.Gate)3 IGateExpansion (buildcraft.api.gates.IGateExpansion)2 TileGenericPipe (buildcraft.transport.TileGenericPipe)2 KeyPlugGate (buildcraft.transport.client.model.key.KeyPlugGate)2 GateExpansionController (buildcraft.api.gates.GateExpansionController)1 GateLogic (buildcraft.transport.gates.GateDefinition.GateLogic)1 GateMaterial (buildcraft.transport.gates.GateDefinition.GateMaterial)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 EnumFacing (net.minecraft.util.EnumFacing)1