Search in sources :

Example 6 with IGateExpansion

use of buildcraft.api.gates.IGateExpansion in project BuildCraft by BuildCraft.

the class ItemGate method getSubItems.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List itemList) {
    for (GateMaterial material : GateMaterial.VALUES) {
        for (GateLogic logic : GateLogic.VALUES) {
            if (material == GateMaterial.REDSTONE && logic == GateLogic.OR) {
                continue;
            }
            itemList.add(makeGateItem(material, logic));
            ItemStack stackAllExpansion = makeGateItem(material, logic);
            for (IGateExpansion exp : GateExpansions.getExpansions()) {
                if (exp.canAddToGate(material.numTriggerParameters, material.numActionParameters)) {
                    ItemStack stackExpansion = makeGateItem(material, logic);
                    addGateExpansion(stackExpansion, exp);
                    addGateExpansion(stackAllExpansion, exp);
                    itemList.add(stackExpansion);
                }
            }
            itemList.add(stackAllExpansion);
        }
    }
}
Also used : GateMaterial(buildcraft.transport.gates.GateDefinition.GateMaterial) IGateExpansion(buildcraft.api.gates.IGateExpansion) ItemStack(net.minecraft.item.ItemStack) GateLogic(buildcraft.transport.gates.GateDefinition.GateLogic) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 7 with IGateExpansion

use of buildcraft.api.gates.IGateExpansion 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 8 with IGateExpansion

use of buildcraft.api.gates.IGateExpansion in project BuildCraft by BuildCraft.

the class IMCHandlerTransport method processGateExpansionRecipeAddIMC.

public static void processGateExpansionRecipeAddIMC(IMCEvent event, IMCMessage msg) {
    boolean failed = false;
    if (!msg.isNBTMessage()) {
        failed = true;
    } else {
        NBTTagCompound recipe = msg.getNBTValue();
        if (!recipe.hasKey("id") || !recipe.hasKey("expansion") || !recipe.hasKey("input")) {
            failed = true;
        } else {
            IGateExpansion exp = GateExpansions.getExpansion(recipe.getString("expansion"));
            ItemStack is = ItemStack.loadItemStackFromNBT(recipe.getCompoundTag("input"));
            if (exp == null || is == null) {
                failed = true;
            } else {
                GateExpansions.registerExpansion(exp, is);
            }
        }
    }
    if (failed) {
        BCLog.logger.warn("Received invalid gate expansion recipe IMC message from mod %s!", msg.getSender());
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IGateExpansion(buildcraft.api.gates.IGateExpansion) ItemStack(net.minecraft.item.ItemStack)

Example 9 with IGateExpansion

use of buildcraft.api.gates.IGateExpansion 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 10 with IGateExpansion

use of buildcraft.api.gates.IGateExpansion in project BuildCraft by BuildCraft.

the class ItemGate method makeGateItem.

public static ItemStack makeGateItem(Gate gate) {
    ItemStack stack = new ItemStack(BuildCraftTransport.pipeGate);
    NBTTagCompound nbt = InvUtils.getItemData(stack);
    nbt.setByte(NBT_TAG_MAT, (byte) gate.material.ordinal());
    nbt.setByte(NBT_TAG_LOGIC, (byte) gate.logic.ordinal());
    for (IGateExpansion expansion : gate.expansions.keySet()) {
        addGateExpansion(stack, expansion);
    }
    return stack;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IGateExpansion(buildcraft.api.gates.IGateExpansion) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IGateExpansion (buildcraft.api.gates.IGateExpansion)13 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 GateLogic (buildcraft.transport.gates.GateDefinition.GateLogic)3 GateMaterial (buildcraft.transport.gates.GateDefinition.GateMaterial)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 Gate (buildcraft.transport.Gate)2 KeyPlugGate (buildcraft.transport.client.model.key.KeyPlugGate)2 GateDefinition (buildcraft.transport.gates.GateDefinition)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 GateExpansionController (buildcraft.api.gates.GateExpansionController)1 TileGenericPipe (buildcraft.transport.TileGenericPipe)1 GatePluggable (buildcraft.transport.gates.GatePluggable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EnumFacing (net.minecraft.util.EnumFacing)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1