You are on page 1of 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 something
craftable 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 Down and
Forward commands (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).
(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 Controller was 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.
The GUI
Miner has a GUI, new, remade one.
Right click miner to open it.
Programming screen
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 Check to check program for syntax errors. If it is all right, Launch button will be enabled.
Click Launch to 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 Pause to pause program execution, click it again to Resume it.
The same happens when you connect/disconnect the miner to keyboard.
Click Restart to 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 Stop to halt the program. It then cannot be resumed, only restart is possible.
Terminal screen
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
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.
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.
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.
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
dir or dir.axis or axis
- contains a string description of the rotation.
- possible values: x+, x-, z+, z-
dir.compass or compass
- 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 or angle
- 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.
Miscelanous
These 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.
- 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
do or run( Command list );
do or 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.
go or fw or forward();
go or fw or 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
bw or backward();
bw or back( steps );
- 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.
Rotation
left();
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.
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 items
and 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
BUCKET or BUCKETS - matches all buckets
FUEL - matches all that burns in furnace in miner
BUILDING or BUILDING_BLOCKS - matches blocks usable for building, eg. bridge
ORES - matches all ores
VALUABLE or PRECIOUS or 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.
Deposit items of kind
deposit or depo or 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!
deposit or depo or store( numberOfStacks, TYPE );
deposit or depo or 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
depoKeep or storeKeep( TYPE );
- deposit all except the given TYPE
- if keepAllFuel option is enabled, fuel will be excluded
depoKeep or storeKeep( numberOfStacks, TYPE );
depoKeep or 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
stacks or countStacks( TYPE ) ;
stacks or 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();
- returns number of empty slots in the main cargo inventory
Counting fuel, predicting how long it will last
fuel or 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 or isFull();
full or isFull(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.
empty or 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 or destroyItems( TYPE );
- destroy all items matching type
- type ALL will destroy all
burn or destroy or burnItems or destroyItems( numberOfStacks, TYPE );
burn or destroy or burnItems or destroyItems( 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
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 = TUNNEL
COBBLEMAKER = COBBLE = MAKE_COBBLE
Capability functions
clearCap or clearCfg or clearOpt();
resetCap or resetCfg or resetOpt();
- set all capabilities to FALSE.
- useful at the beginning of a program, when you dont know what is on and what off
cap or cfg or opt( OPTION );
- get option value (true, false)
cap or cfg or opt( 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.
capOn or cfgOn or optOn( OPTION1, OPTION2, );
- set named capabilities to TRUE
capOff or cfgOff or optOff( OPTION1, OPTION2, );
- set named capabilities to TRUE
hasCap or hasCfg or 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 do need here.
eg. F1
F1, F2, F3, F4 - front
B1 ... - back
L1... - left
R1... - right
U1... - up
D1... - down
u1... - 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?
getBlock or getId or idAt(SIDE_NAME);
returns ID number of the block, or 0 if its air (AIR)
eg. if( idAt(F1) == DIRT ) bell();
Place a block
place or setBlock(SIDE_NAME, BLOCK);
- place the described block on given side, if there is space and if the block is
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 IDs
idMatch or 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.

You might also like