Hi! This is an implementation of an idea I got after playing with NFC tags and readers. It gives user way to write data to tags - small stickers, that can be placed in world (not unlike paintings), but also on items and animals. Tags can be read by peripherals (in both stand-alone and turtle versions), even after placed.
With tags you can create programs for turtle, by placing commands on his path (for things like patrolling, delivery routes, etc.). They can also be used as plain old visual programming tool or ID cards.
Videos
Spoiler
Intro - placing tags and controlling turtle[media]http://www.youtube.com/watch?v=IvVABPdoDDY[/media]
1.1 update: making in-game GUIs
[media]http://www.youtube.com/watch?v=ZPAxdr_tubI[/media]
Tags (updated: 2013-07-21)
Spoiler
- Tags store data as simple strings.
- Storage on tag is limited. Currently, there are only 5 tag sizes (4 available in survival) - unlimited, 64, 256, 1K and 4K characters.
- Tags come in three variants: normal, glass (transparent) and poster (covers whole block side). All variants are functionally identical.
- Data can be written with peripherals (tag writer and printer, stand-alone and turtle versions).
- Every tag has (hopefully) unique serial id.
- Tags can also have printed label and icon. This data is not readable by peripherals. To modify tag, use printer.
- After tag is placed in world (simply use it on block, any side is valid), it can be rotated by right clicking. Left click to drop as item.
- Tags can be also placed on items and animals (no visual indication yet). They can also be read while held by player or placed in item frame
Spoiler
- Tag writer (stationary and turtle versions): can be used to read and write data to tags and print icons or labels on them.
- Tag scanner (stationary only) - read tags on nearby entities (like free floating items or animals). Can also be bounded with advanced reader.
- Tag manipulator (turtle only) - tool for placing and removing tags on animals. It was created, because normal .place() sometimes behaves strange (e.g. user can't declare, if tag should be placec only on entity or ground). To put tag on entity, select inventory slot with tag and call .attack(). To remove - select empty slot and call same again.
Writer
To put tag in writer, use it on block. After programming/printing click again to eject tag (if you have tag in hand, it will replace current one). Writers also have proper inventories, so it is possible to use things like hoppers or pipes (probably, not tested).
Writers need ink to use printing functions like changing icons or labels. On stationary writers simply use black dye on block. For turtle, use either loadink program or API method.
Printers will emit 'tag',side event after tag is inserted.
API is also described in built-in help (help tag-printer)
Scanner
Scanner peripheral can be bound with advanced reader by right clicking while sneaking.
Scanner will emit 'tag_scan',side,reader_serial event after any bound reader is used on tag. After that, methods like .contents() will operate on scanned tag.
Icons
Printers can change tag icons. There are three available icon types:
- Predefined - badly drawn by me!
- Text. Use 'text!' prefix (like that: 'text!Too complicated'). Break line with _. Text will be automatically scalled to fit tag. Length of text (non-space, non-line break characters) is limited by config option.
- Bitmap: Use 'bitmap!' prefix. Break line with _. Use any other characted other than space to mark black pixel. Image will be automatically scalled. Number of black pixels is limited by config option.
Tag writer
Programs
All programs wait for newly inserted tags and eject as soon as work is done.
readtag - print tag contents of any inserted tag
writetag - ask for new contents and write any inserted tag
clonetag - read one tag and copy data to any inserted tag
printtag - print icon and label to any inserted tag. If you don't supply parameters, program will ask for it
progtag [path to file]- automatically program tags using data from file, line by line. Format of this file is described below. In any moment you can press space to skip currently programmed contents or any other key to abort.
writetag and clonetag have two optional command line parameters - icon and label. When used, program will try to print on any inserted tag
progtag file format
Program accepts four types of lines:
- line starting with – - comments
- n @ library_id - program n tags with contents from library
- n [icon] [label] : contents - program n tags with contents, and print if optional parameters are supplied
- any other line - write line to tags, without any modifications
result hasTag() - is there valid tag in peripheral?
result eject([side]) - eject current tag. If argument is given, peripheral will try to eject tag into neighboring inventory
str,size contents() - return current tag contents
result,new_size write(string new_contents) - write data to tag
size_description,size_in_bytes size() - return current tag size
int serial() - return current tag serial id
contents,icon,label library(string id) - get tag data from library
result print([string icon], [string label]) - print icon and label to tag. If parameter is not supplied or nil, function will clear that property.
int inkLevel() - return current ink level
Turtle tag writerThis peripheral can read stand-alone and embedded (on items) tags from few sources:
- In player hand
- Tags places in world
- Items and tags floating in world (dropped items)
- Items and tags in item frames
- Tags on animals
follow program
Turtle peripherals supply program called follow. Command will scan for neighbour tags and execute code found on it. See tutorial for example of use.
Code has access to few modified commands (all standard turtle command are visible in module called t):
- up, down, forward, back - turtle will move in one direction, until new tag is found.
- detect, compare, drop, suck - those functions have new parameters: side and restore. Before running command, turtle will rotate to face side. If side is up or down, he will use *Up and *Down instead of normal command. If restore is true, turtle will return to initial position. Without params, command will work like normal ones.
suck('left', true) == t.rotateLeft() t.suck() t.turnRight() suck('up', true) == t.suckUp()
During execution, code from tags can use few variables:
reader - peripheral side, copied program from parameters
tagDir - where is tag containing currently executed code
serial - serial id of currently scanned tag
prev() - call previous command
holdPrev() - don't replace prev() with current command
pushPostamble(function) - postamble is function called after any execution. This will push new value onto stack (only top function is called)
popPostamble() - pop previous postamble from stack
push(value) - during execution commands can use value stack. For example, comparision tags leave value on stack, that can be later used by branch tags
pop() - pop and return value from stack
top() - get current stack top
Common problems:- Can't move forward - turtle.forward() returned false. Most of the time, turtle ran out of fuel
- Tag … was read twice in row - after executing turtle must end on different tag. Add movement command or stop() to tag.
To reduce API calls parameters, turtle peripherals work on single, selected tag. scanForTag(dir) and selectFromSlot(slotId) both select tag as a target - first one looks for tags placed in world, second one - in turtle inventory. Any next command will also use selected tag. If you move out of range or remove item from slot, selected tag will become invalid.
For example, to get data from tag placed right to turtle, use following code:
if p.scanForTag('right') then
print(p.contents())
print(p.size())
end
result scanForTag([string direction = "front"]) - scan for tags on nearby blocks and select first found. Return true if anything found. Possible argument values: front, back, up, down, left, right
result selectFromSlot([int slot = current]) - select tag from inventory. Works only for single tags.
result isTagValid() - is currently selected tag valid?
str,size contents() - return selected tag contents
result,new_size write(string new_contents) - write data to selected tag
size_description,size_in_bytes size() - return selected tag size
int serial() - return selected tag serial id
contents,icon,label library(string id) - get tag data from library
result print([string icon], [string label]) - print icon and label to tag. If parameter is not supplied or nil, program will clear that property.
int inkLevel() - return current ink level
int loadInk([slot = current]) - load ink from inventory slot
Spoiler
Warning: recipes are not fully balanced right now, and may be tweaked in future.Tags:
To make glass tags, use glass panels instead of paper:
Every paper tag can be converted to big tag without losing any info:
Every tag can be dyed, without losing data on it:
Hand-held tag readers (normal and advanced)
Tag manipulator
Can be used to remove tags from animals
Components
Writer, printer and antenna components - used in other recipes.
Peripherals
Stand alone (writer and scanner):
Turtle peripherals (writer and manipulator)
Tags can be also placed on items. Simply use tag and any item in crafting grid:
Tutorial - First steps (updated 2013-07-20)
Spoiler
Since documentation still misses few things and IMO this mod may have steep learning curve, I wrote two simple tutorials for easy start.Using predefined tags
Mod comes with few predefined tags. They are visible in creative tab for mod, unless you switched if off in config. In survival this data can be accessed by using progtag or API call library from any peripheral (see help). If you want to add your own tags, simply modify file <mc_install_dir>/cctags/lua/library.json (after modification, you can make file read only, to prevent overwrite on update).
You will need following tags: Start, Turn Right, Turn Left, Stop. Place these in following pattern, starting from top left (start is green, stop is red). You can rotate tags with right-click.
When done, position printer/writer turtle in front of first tag ("Start") and call follow right (if tag peripheral is on right).
To see what's on predefined tags, use tag reader.
Custom tags
Sometimes predefined tags are not enough. Since follow program executes any code on tag, it is possible to program custom commands to make more advanced paths.
This instruction shows how to replicate above sceenshot, and make it fully functional. Tags used in this example need little bit more manual control than library ones (you can easily replicate functionality with predefined ones, though).
First, you need to create tags with needed code. You can use progtag to do it automatically. This program interprets lines like that:
1 forward Start : forward()
This one means: write string forward() to one tag, print label Start and icon called forward on it. Icons and labels are optional and can be omitted (you can then use writer peripheral instead).(If you are patient, you can also program tags one by one with writetag).
Write following code into file on computer with tag printer as peripheral (on any side)
-- this is a comment - you may skip this
-- start point: start moving forward until new tag is found
1 forward Start : forward()
-- same as previous tag, only up
1 forward Up : up()
-- suck(dir, revert) will rotate turtle in chest direction, suck item and rotate back (tagDir is predefined variable that holds tag orientation)
1 energy Refuel : suck(tagDir, true) refuel() up()
-- Random fact: In Lua you can write whole program without single new line (or semicolon)
1 right Right : turnRight() forward()
-- stop() - end execution
1 no Stop : print("Done") stop()
Use black dye on printer to load ink. Then call progtag <name_of_file_you_just_wrote_and_hopefully_also_saved> and follow instructions on screen - simply put 5 tags into printer, one by one. Programmed tags will be automatically ejected.When you are done, place tags in world and start program follow turtle.
Tutorial: Something Practical (updated 2013-07-27)
Spoiler
This tutorial contains few examples of tag usage. One of them is block sorter (pictured). Not exactly normal tutorial, but I try to explain few things.
Download here: http://ᚠ.ᛒ.net/cctags-tutorial-v4.1 (needs CCTags version >= 1.0 needed, either for MC 1.6.2 or 1.5.2).
If you have block id problems, use included config files.
Changelog and previous versions
Spoiler
Version 1.1 [MC 1.6.2] [MC 1.5.2]- Merged writers and printers (all printers are now writers, old writers may need to broken and placed again)
- Added scanner peripheral - entity (items, animals) reader in stand-alone form
- Added remote reader (can be bound to scanner to send events)
- Added tag manipulator - tool for easy removal of tags on living entities. Can be also used as turtle tool
- FIX: turtles show in creative inventory (no recipes though)
- FIX: tag hitbox has now correct, smaller size
- FIX: peripherals will now reset target after failed scan
- Mod is open source now
- Another batch of new tags
- Fixed NPE crash on clicking tag with empty hand
- Turtles can row read tags in player hand
- Fixed broken readtag program
- Tags can now be used on animals and items
- Turtle can now read tags lying on ground and places in item frames
- Added macros (see tutorial and library)
- Peripherals can now eject tags into neighbor inventories
- Dyes can be now used directly on tags on blocks
- Corrected tag brightness
- Simplified lua cod
- Fix broken textures after resource pack reload
- New library tags - comparision operators, basic redstone, etc. (updated tutorial world)
- Tags in library are now ordered less randomly
- Other small bugfixes
- Update to Minecraft 1.6.2
- New icon types: text and bitmap
- follow: postamble and argument stack
- New library tags
- Glass and big tags
- some changes and additions to tag library
- few bugfixes
- Tag library
- optional follow-env file
- few bugfixes
- Serial numbers for tags
- some new functions for follow
- Initial release
Mod is still in development, so it may be rough around edges (especially graphics. I have no idea how to do that stuff) - so no warranty at all. If it does something nasty, please post bug report. Any other feedback is also appreciated.
Current version: 1.1 (published: 2013-07-24)
Download here [MC 1.6.2] [MC 1.5.2]
Quick links:
Icon list: http://ᛒ.net/doc/cctag-icons.html
Tag library (visible in creative mode): http://ᛒ.net/doc/library.html
Source code: https://github.com/boq/cctags