how to program miners

Upload: d3m0ncx

Post on 03-Jun-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 How to Program Miners

    1/17

    How to program Miners

    in PowerCraft 3.4.7+Miners now use Weasel to execute the program,

    so you should also read the WEASEL GUIDE.

    To start the story of Miners, I have to explain how Miner works. Despite the obvious gears,

    steam engine, loads of metal stuff and some electric circuits, Miner also contains a controller

    circuit.

    This controller circuit has a command buffer, which can store list of simple commands, like:

    Command Action

    F, B Move forwards / move backwards

    5, -5 Number of steps forward / backward

    L, R Turn LEFT / RIGHT

    S, N, E, W Turn to SOUTH / NORTH / EAST / WEST

    U Mine one step forward and up. It lays half step if somethingcraftable to half step is inside. Cobblestone works best. If miner

    stands on half step and you execute Up, it will perform Forward

    command instead.

    D Mine one step down and forward, without movement.

    If you want to make a descending corridor, repeat Downand

    Forwardcommands (DF)

    Q, (deposit),

    (store)

    Store contents into nearby chest. Q command cant store buckets,

    power dust and power crystals.If you check Keep all fuel in the Miners GUI, coal and other

    burnable items wont be stored.

    X, (halt) Turn into blocks (iron cubes and chest with the contents).

    https://docs.google.com/a/ondrovo.com/document/d/1rvoxcVprUxrsp3_nDuMazwH-4CWwXW0ttknhiot2568/edithttps://docs.google.com/a/ondrovo.com/document/d/1rvoxcVprUxrsp3_nDuMazwH-4CWwXW0ttknhiot2568/edithttps://docs.google.com/a/ondrovo.com/document/d/1rvoxcVprUxrsp3_nDuMazwH-4CWwXW0ttknhiot2568/edithttps://docs.google.com/a/ondrovo.com/document/d/1rvoxcVprUxrsp3_nDuMazwH-4CWwXW0ttknhiot2568/edit
  • 8/11/2019 How to Program Miners

    2/17

    (M), (!M) Enable, disable mining. You can also write (mining:on), or

    (m:on). Or symbols * and %.

    (B), (!B) Enable and disable building bridge. (bridge:on) works too. Also with

    off, of course. And (br) works as well.

    (L),(!L) Enable and disable lava filling. Its recommended not to turn this

    off. (lava:on) works too.

    Lava filling is available only for level 4+ miners.

    (W),(!W) Enable and disable water filling. Works for level 6+ miners. It does

    something very similar to lava filling.

    (loopN: .) Repeat N-times (replace N with number). Works for any positive

    number, even with more digits. Repeated code can contain loops or

    anything other.

    (@N: ) Shorter alias for loop. (@50:10L10R )

    If you know this and dont want to learn weasel,

    you can still use this ond syntax. Execute it like this:

    run("DFDFDFDF (@20:UFFF)");

    This is the old circuitry.

    In version 3.4.7, a modified Weasel Controllerwas added to Miner.

    The save format was changed, which explains why you have to break miners before updating.

    This Miner Controller, internally called Brain, holds a list of weasel instructions, weasel memory,

    system and data stack and lets you control most of the things miner can do.

  • 8/11/2019 How to Program Miners

    3/17

    The GUI

    Miner has a GUI, new, remade one.

    Right click miner to open it.

    Programming screen

  • 8/11/2019 How to Program Miners

    4/17

    At the top there are tabs. Click them to open other pages of the GUI.

    Program changes are saved instantly, dont worry.

    Click Undo All to cancel all changes youve made to the program since opening the GUI.

    Click Checkto check program for syntax errors. If it is all right, Launchbutton will be enabled.

    Click Launchto start the program. This clears some temporary counters in the Brain, compiles

    the program and inserts the assembler instructions to the internal program memory.

    Click Pauseto pause program execution, click it again to Resumeit.

    The same happens when you connect/disconnect the miner to keyboard.

    Click Restartto restart the program. This restarts the assembler instructions in weasel, the old

    program. If you changed the program code in editor, it wont have any effect now.

    Click Stopto halt the program. It then cannot be resumed, only restart is possible.

    Terminal screen

  • 8/11/2019 How to Program Miners

    5/17

    This is a new Miners feature. Technically it is the Terminal gadget you know from weasel

    integrated into miner. Though it is not an exact copy. The so called active mode where

    terminal calls termIn function does not work here, instead you have to check the input text

    manually.

    Here is a brief summary of terminal controls:

    # read input text if any, otherwise ""userInput = term();

    userInput = term.in();

    userInput = term.getInput();

    # print line to terminal

    term( "This is printed");

    term.print( "This too.");

    term.out( "Yes, also this.");

    # check if there is an user input

    until( term.hasInput()){

    pause;

    }

    theInput = term();

    # clear the terminal

  • 8/11/2019 How to Program Miners

    6/17

    term.reset();

    and aliases

    term.restart();

    term.clear();

    term.cls();

    Settings screen

    These are the Miners settings, aka configuration or capabilities.

    If the checkbox is grayed out, it means you need higher level to use it.

    Heres a list of their effects.

    Mining

    Enables block mining. If mining is disabled and miner bumps into wall, it wont try to break it,

    instead it will wait for new instructions.

    Bridge building

    If there is some material in the chest and miner is about to fall off a cliff / into a cave, it places

    blocks under itself to make a bridge.

    Air filling - tunnel mode

    This ability is most useful in the nether to make safe corridors between portals.

  • 8/11/2019 How to Program Miners

    7/17

    Miner with this enabled fills all air blocks near it with blocks from the chest. It fills only blocks in

    the front side, so the corridor wont be filled back after the miner makes some more.

    Lava filling

    Miner can fill nearby lava blocks with stuff from its chest, and if there is an empty bucked, it fills

    this bucket with lava for later use as fuel - the bucket is not destroyed by it.

    Water filling

    The same as for lava, but water flows faster, so it sometimes results in weird underwater

    structures. It can be used to make underwater tunnels, just like Air Filling in Nether.

    Compress items

    Item compression is very handy in desert, where it turns sand to sandstone - and since

    PowerCraft adds the reverse recipe, you can later get the sand back.

    This also works for most items that can be crafted to get compact blocks:

    Ingots, Diamond, Redstone, Glowstone, Clay, Lapis and few others.

    the compression is run after an item is collected, and only this one item type is compressed at

    once. If you place sand into miner, it wont get compressed until some more sand is added.

    Make cobble

    This is a very handy option, but you must be level 7 to use it.

    If such a miner has water and lava buckets in the inventory, it is able to create cobblestone for

    building purposes - bridge, filling and weasel-controlled building.

    Keep all fuel

    This option forces the Deposit command to keep all items and blocks that can be used as fuel.It also by default keeps all chests, crystals and buckets - unless you call deposit from weasel

    with some specific parameters.

    Place torches

    When its dark and there are torches in the cargo storage, miner places them on wall while

    mining - every approx. 5 blocks.

    Torches only on floor

    This was added to make the torch placing more reliable in large mines. If miner mines a room in

    rock, it always has enough light from the torches on wall, but when it goes back in a next row,

    it breaks them - which obviously results in a huge open space with no light - and guess what

    happens if you arent on peaceful.

    That is when this option is used. Miner places torches preferably on floor, thus all the room will

    be neatly illuminated.

  • 8/11/2019 How to Program Miners

    8/17

    Cargo storage screen

    Each Power Crystal type (= 1 level up) has its own slot.

    Crystals collected (after mining) are automatically placed in the correct slots.

    Shift transport works too.

    You can insert fuel into the main storage area, and all collected items are placed here too.

    When miner is destroyed, this inventory is moved into the newly created chest blocks.

    First are moved crystals, then the main inventory line by line. If there are some items left, they

    will be dropped next to the chest.

  • 8/11/2019 How to Program Miners

    9/17

    Weasel variables

    The Weasel Engine used in miners is identical to the one in Weasel Controller devices, which

    means all the math, string, time etc functions work here too.

    There is a set of status variables, but most of the things is done using functions.

    here are the variables:

    pos.x- x position of the miner

    pos.y- y position (vertical)

    pos.z- z position

    diror dir.axis oraxis

    - contains a string description of the rotation.

    - possible values: x+, x-, z+, z-dir.compassorcompass

    - world side: N, S, E, W.

    - it is defined by looking at the sun, so you can get idea of the sides by doing the same.

    - sun rises on E.

    dir.angle orangle

    - get 360 value for the rotation. This is the internal representation of rotation,

    and I dont think youll have any use for it.

    level

    - current miners level, 1 - 8

    Miner functions

    Here is the real beauty of Weasel. The engine is so universal that it allowed me to add functions

    doing almost anything you can image.

    There are really many of these, so Ive divided them to few groups.

    MiscelanousThese are the same as for weasel controller.

    How to control terminal is described above.

    tx(channel, state);

    - transmit state on a radio channel channel.

    - state is boolean, true or false.

  • 8/11/2019 How to Program Miners

    10/17

    - after you set channel on, dont forget to set it off again to release the channel

    for possible other transmitters.

    state =rx(channel);

    - get state of a radio channel, boolean

    value = nget(varName);

    - get variable from global network

    - if no such variable exists returns 0

    nset(varName, value);

    - set variable to global network.

    sleep(ticks);

    - same as weasel controller, sleeps some ticks

    Movement

    door run( Command list );

    door run( Command list, repeat );

    - command list is a string made of the the basic commands.

    - as you may remember, there can also be loops, though the old variable

    system was removed.

    Commands are described at the very top of this guide.Numbers mean number of steps forward or backward (if negative).

    Spaces can be used for separating code blocks or whatever you want, they are ignored.

    (@5: ) - this repeats the 5 times.

    example:

    do(DF); - execute down(); followed by forward();

    do(20R,4); - 20 steps forward, turn right; repeat this 4 times.

    do((@20: U) FR, 4); - 20x up, front, right; repeat 4 times.

    goor fwor forward();

    goor fwor forward( steps );- go forward. If mining is enabled, mine blocks;

    - if mining is not enabled and way is blocked, skip this command.

    - negative number = back

    bwor backward();

    bwor back( steps );

  • 8/11/2019 How to Program Miners

    11/17

    - go backwards.

    - miner cant mine when going back.

    - negative number = forward

    up();

    up( steps );- as described in the beginning, this mines up, lays half-step when needed and

    when such a block can be crafted, and moves on top of this block.

    down();

    - mine down

    - makes sure there is a block under the just mined 2 blocks, if not, place one.

    - this is typically followed by forward(), since down() itself does not move the miner.

    Rotationleft();

    left( count );

    - turn to left;

    - if count is set, it turns to left count-times (count 2 = turn around; turn -1 = turn right)

    right();

    right( count );

    - just like left;

    turn();turn( timesRight );

    - turn is just like right( count ), but the default count is 2, which means turn around.

    north()

    south()

    east()

    west()

    - turn to a worlds side, based on sun movement

    xplus();

    xminus();zplus();

    zminus();

    - move to a direction based on axis direction

    - eg. xplus moves to a positive direction of x axis. (x1, x2, x3...)

    - these can be used instead of north south etc, because they are much more

    useful when making a program based on coordinates.

  • 8/11/2019 How to Program Miners

    12/17

    Inventory functions

    Here it is important to explain the system of block and item constants.

    To make it easier, I have made lots of numeric and string constants, describing various itemsand blocks.

    Item and block constants

    I wont write them here all, whats important is that in the program editor they are highlighted.

    common examples:

    DIRT, COBBLE, DIAMOND_ORE, GRAVEL, SAND, LEAVES, LOG, BRICK, STONE_BRICK,

    OBSIDIAN, CRYSTAL...

    if the name is multi-word, the most probable name is with under_score.

    There are also many items:

    FLINT, GOLD, IRON, DIAMOND, LAPIS, REED, BUCKET_WATER or BUCKET_W, COAL

    etc.

    If your needed block or item does not have a constant, just use its ID number instead.

    Group Constants

    These constants can match a whole group of item types.

    ALL - can be used when you are supposed to enter number of stacks, and it will take all

    if you use ALL in burn command, all will be burnt.

    BLOCKS- matches all blocks

    ITEMS- matches all non-blocks

    BUCKETorBUCKETS - matches all buckets

    FUEL - matches all that burns in furnace in miner

    BUILDINGor BUILDING_BLOCKS- matches blocks usable for building, eg. bridge

    ORES- matches all ores

    VALUABLE or PRECIOUSor RARE- matches things that are certainly worth keeping, such as

    storage blocks, diamond, ingots, nuggets, glowstone, clay, obsidian, bedrock, crystals, power

    dust etc.

    JUNK- matches gravel, saplings, leaves, dirt and seeds.

    Functions for depositing and item manipulation.

    All of these (except burn and counting) work only if there is a storage block near the miner, eg.

    chest.

  • 8/11/2019 How to Program Miners

    13/17

    Deposit items of kind

    depositor depoor store( TYPE );

    - deposit all items of a kind

    - type may be any of the constants, note that constants are used without - they are most often equal to ID numbers!

    depositor depoor store( numberOfStacks, TYPE );

    depositor depoor store( numberOfStacks, TYPE1, TYPE2, TYPE3... );

    - deposit number of stacks matching TYPE.

    - you can use more types at once, the number of stacks will be used for them all

    together

    (eg. 5, DIRT, STONE may store 3 dirt and 2 stone stacks)

    - use ALL constant instead of number to match all - useful when used with multiple

    item types, because

    Deposit items not of kind

    depoKeepor storeKeep( TYPE );

    - deposit all except the given TYPE

    - if keepAllFuel option is enabled, fuel will be excluded

    depoKeepor storeKeep( numberOfStacks, TYPE );

    depoKeepor storeKeep( numberOfStacks, TYPE1, TYPE2, TYPE3... );

    - lets you define how many stacks of the type should be kept.

    - if you want to keep some stone for bridges but deposit all the rest, you can do depoKeep(10, BUILDING), which keeps 10 stacks of the best building blocks.

    - depoKeep(ALL, BUILDING, FUEL) stores all items that arent fuel and are not

    good for building (eg. flint)

    Item counting functions

    stacksor countStacks( TYPE ) ;

    stacksor countStacks( TYPE1, TYPE2, TYPE3... ) ;

    - count stacks of given type(s) - if more types, the counts are added together

    - of course this works also for groups, eg. FUEL

    items or countItems( TYPE ) ;

    items or countItems( TYPE1, TYPE2, TYPE3... ) ;

    - count individual items of given type(s)

    - 64-item stack will give you number 64

    countEmpty();

  • 8/11/2019 How to Program Miners

    14/17

    - returns number of empty slots in the main cargo inventory

    Counting fuel, predicting how long it will last

    fuelor countFuel()

    - counts all fuel points available from items in the cargo storage, + points currently stored in the fuel buffer

    - for one step up to 4 points are needed

    - for breaking weak blocks (dirt, sand, wood) 10 points are used

    - common stone blocks need 20 points

    - breaking ores can take 100 - 150 points based on how rare the ore is

    - obsidian costs 600 points

    - bedrock costs 2000 points

    - Of course miner does not mine one block at a time. It mines 4 at once, and if they are

    all bedrock, one step can cost up to 8004 points - that is over 5 coals, or nearly 3 power

    dusts.

    Empty / full checks

    full orisFull();

    full orisFull(strict);

    - checks if the cargo storage is full or not.

    - strict = require all slots fully used.

    - if you set strict to false, you get True even if there is only one item in each slot.

    emptyor isEmpty();

    - gives true if the cargo storage is empty

    - this has very little use, since there is always some fuel, torches or buckets left.

    Item destruction

    burn or destroy or burnItems ordestroyItems( TYPE );

    - destroy all items matching type

    - type ALL will destroy all

    burn or destroy or burnItems ordestroyItems( numberOfStacks, TYPE );

    burn or destroy or burnItems ordestroyItems( numberOfStacks, TYPE1, TYPE2... );

    - destroy N stacks matching type

    burnKeep or destroyKeep( TYPE );

    - destroy all but given type

    burnKeep or destroyKeep( numberOfStacks, TYPE1, TYPE2... );

    - destroy items matching given type, but KEEP number of stacks.

    - eg. destroyKeep(20, BUILDING) destroys all building blocks, but keeps 20

  • 8/11/2019 How to Program Miners

    15/17

    stacks for bridges.

    cleanup();

    - this is probably useless;

    - it should reorder the inventory and merge stacks of the same items

    Miners special capabilities = config manipulation

    The program can toggle config options when you need it.

    Note that enabling some feature not available at current level is useless - it simply wont work,

    despite you will see the cross in the GUI screen. This is protected.

    Capability constants

    We have constants for capabilities, so it should be very easy to use them.

    What they do is described above next to the GUI image.

    KEEP_FUEL

    TORCHES

    TORCHES_FLOOR

    COMPRESS

    MINING

    BRIDGE

    LAVA =LAVAFILL =LAVA_FILL

    WATER = WATERFILL =WATER_FILL

    AIR = AIRFILL =AIR_FILL =TUNNELCOBBLEMAKER =COBBLE =MAKE_COBBLE

    Capability functions

    clearCap or clearCfg or clearOpt();

    resetCap orresetCfg orresetOpt();

    - set all capabilities to FALSE.

    - useful at the beginning of a program, when you dont know what is on and what off

    capor cfg oropt( OPTION );

    - get option value (true, false)

    cap orcfg oropt( OPTION, value );

    - set option value - true or false.

    - if this capability is not available at this level, then this will set the flag,

    but wont have any effect.

  • 8/11/2019 How to Program Miners

    16/17

    capOn orcfgOn or optOn( OPTION1, OPTION2, );

    - set named capabilities to TRUE

    capOff orcfgOff or optOff( OPTION1, OPTION2, );

    - set named capabilities to TRUE

    hasCaporhasCfgor hasOpt( OPTION );

    - returns true if this option is available at current level.

    BLOCK MANIPULATION

    Side names

    Miner has 6 sides.

    Each side has 4 blocks - 1,2,3,4.

    Side name is made of side letter and block number.

    This is not a constant, like DIRT or COBBLE. You doneed here.

    eg. F1

    F1, F2, F3, F4- front

    B1... - back

    L1... - left

    R1... - right

    U1... - up

    D1... - downu1... - frontUp (only 2 blocks)

    d1... - frontDown (only 2 blocks)

    The blocks are numbered this way from the view of miner:

    1 2

    3 4

    What block is there?

    getBlockor getIdoridAt(SIDE_NAME);

    returns ID number of the block, or 0 if its air (AIR)

    eg. if( idAt(F1) == DIRT ) bell();

    Place a block

    placeor setBlock(SIDE_NAME, BLOCK);

    - place the described block on given side, if there is space and if the block is

  • 8/11/2019 How to Program Miners

    17/17

    in Cargo Storage.

    - You can use BUILDING as block id, and it will get the first block suitable for building.

    - You can also use BLOCKS, PRECIOUS and the other group names.

    Compare block IDsidMatchor ideq(ID1, ID2);

    - returns true if the IDs are equal.

    - The ID1 is id number, while ID2 can be a constant.

    - If you get a block id using idAt or others, you should use ideq to compare it.

    - This also understand block groups:

    ideq(DIRT, BUILDING) will return true.