Search in sources :

Example 1 with GateMaterial

use of buildcraft.transport.gates.GateDefinition.GateMaterial in project BuildCraft by BuildCraft.

the class GateItemModel method getState.

private KeyPlugGate getState(ItemStack stack) {
    GateMaterial material = ItemGate.getMaterial(stack);
    GateLogic logic = ItemGate.getLogic(stack);
    Set<IGateExpansion> expansions = ItemGate.getInstalledExpansions(stack);
    // states.add(exp.getRenderState());
    return new KeyPlugGate(EnumFacing.UP, material, logic, false, expansions.toArray(new IGateExpansion[0]));
}
Also used : GateMaterial(buildcraft.transport.gates.GateDefinition.GateMaterial) IGateExpansion(buildcraft.api.gates.IGateExpansion) KeyPlugGate(buildcraft.transport.client.model.key.KeyPlugGate) GateLogic(buildcraft.transport.gates.GateDefinition.GateLogic)

Example 2 with GateMaterial

use of buildcraft.transport.gates.GateDefinition.GateMaterial 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 3 with GateMaterial

use of buildcraft.transport.gates.GateDefinition.GateMaterial 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 4 with GateMaterial

use of buildcraft.transport.gates.GateDefinition.GateMaterial in project BuildCraft by BuildCraft.

the class ItemGateCopier method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    }
    boolean isCopying = !player.isSneaking();
    Block block = world.getBlockState(pos).getBlock();
    TileEntity tile = world.getTileEntity(pos);
    NBTTagCompound data = NBTUtilBC.getItemData(stack);
    PipePluggable pluggable = null;
    Gate gate = null;
    if (tile == null || !(tile instanceof IPipeTile)) {
        isCopying = true;
    } else {
        if (tile instanceof TileGenericPipe && block instanceof BlockGenericPipe) {
            RaytraceResult rayTraceResult = ((BlockGenericPipe) block).doRayTrace(world, pos, player);
            if (rayTraceResult != null && rayTraceResult.boundingBox != null && rayTraceResult.hitPart == Part.Pluggable) {
                pluggable = ((TileGenericPipe) tile).getPipePluggable(rayTraceResult.sideHit);
            }
        } else {
            pluggable = ((IPipeTile) tile).getPipePluggable(side);
        }
    }
    if (pluggable instanceof GatePluggable) {
        gate = ((GatePluggable) pluggable).realGate;
    }
    if (isCopying) {
        if (gate == null) {
            data = new NBTTagCompound();
            stack.setTagCompound(data);
            // Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
            data.setBoolean("Unbreakable", true);
            // Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
            data.setInteger("HideFlags", 4);
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.clear"));
            return true;
        }
        data = new NBTTagCompound();
        stack.setTagCompound(data);
        gate.writeStatementsToNBT(data);
        data.setByte("material", (byte) gate.material.ordinal());
        data.setByte("logic", (byte) gate.logic.ordinal());
        player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gateCopied"));
        // Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
        data.setBoolean("Unbreakable", true);
        // Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
        data.setInteger("HideFlags", 4);
    } else {
        if (!data.hasKey("logic")) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noInformation"));
            return true;
        } else if (gate == null) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noGate"));
            return true;
        }
        GateMaterial dataMaterial = GateMaterial.fromOrdinal(data.getByte("material"));
        GateMaterial gateMaterial = gate.material;
        if (gateMaterial.numSlots < dataMaterial.numSlots) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.slots"));
        }
        if (gateMaterial.numActionParameters < dataMaterial.numActionParameters) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.actionParameters"));
        }
        if (gateMaterial.numTriggerParameters < dataMaterial.numTriggerParameters) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.triggerParameters"));
        }
        if (data.getByte("logic") != gate.logic.ordinal()) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.logic"));
        }
        gate.readStatementsFromNBT(data);
        if (!gate.verifyGateStatements()) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.load"));
        }
        if (tile instanceof TileGenericPipe) {
            ((TileGenericPipe) tile).sendNetworkUpdate();
        }
        player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gatePasted"));
        return true;
    }
    return true;
}
Also used : IPipeTile(buildcraft.api.transport.IPipeTile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) TileEntity(net.minecraft.tileentity.TileEntity) GateMaterial(buildcraft.transport.gates.GateDefinition.GateMaterial) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) Block(net.minecraft.block.Block) RaytraceResult(buildcraft.transport.BlockGenericPipe.RaytraceResult) GatePluggable(buildcraft.transport.gates.GatePluggable)

Aggregations

GateMaterial (buildcraft.transport.gates.GateDefinition.GateMaterial)4 IGateExpansion (buildcraft.api.gates.IGateExpansion)3 GateLogic (buildcraft.transport.gates.GateDefinition.GateLogic)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 GateExpansionController (buildcraft.api.gates.GateExpansionController)1 IPipeTile (buildcraft.api.transport.IPipeTile)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 RaytraceResult (buildcraft.transport.BlockGenericPipe.RaytraceResult)1 Gate (buildcraft.transport.Gate)1 KeyPlugGate (buildcraft.transport.client.model.key.KeyPlugGate)1 GatePluggable (buildcraft.transport.gates.GatePluggable)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 EnumFacing (net.minecraft.util.EnumFacing)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1