This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
boq's profile picture

[Cc 1.55/cc1.53][Mc 1.6.2/mc 1.5.2] Cctags

Started by boq, 29 June 2013 - 02:23 PM
boq #1
Posted 29 June 2013 - 04:23 PM
(sorry for broken topic title, it looks like there is some kind of anti-shouting filter that breaks it all the time)

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
SpoilerIntro - 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
Peripherals (updated: 2013-08-24)
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.
Peripheral installs few programs, that can be used to manipulate tags without direct calls to API.

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.
To get list of available predefined icons, write help icons. You can also see available icons here:

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
API

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 writer
This 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
loadink - load ink from current slot

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()
    
Program will try to execute program follow-env before start. You can use this to add your own functions (anything declared in this file will be visible to code on tags).

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.
API
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
Recipes (updated 2013-08-24)
SpoilerWarning: 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)
SpoilerSince 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
SpoilerVersion 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
Version 1.0 [MC 1.6.2] [MC 1.5.2]
  • Mod is open source now
  • Another batch of new tags
  • Fixed NPE crash on clicking tag with empty hand
Version 0.7b [MC 1.6.2] [MC 1.5.2]
  • Turtles can row read tags in player hand
  • Fixed broken readtag program
Version 0.7
  • 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
Version 0.6b
  • Fix broken textures after resource pack reload
Version 0.6
  • New library tags - comparision operators, basic redstone, etc. (updated tutorial world)
  • Tags in library are now ordered less randomly
  • Other small bugfixes
Version 0.5
  • Update to Minecraft 1.6.2
  • New icon types: text and bitmap
  • follow: postamble and argument stack
  • New library tags
Version 0.4
  • Glass and big tags
  • some changes and additions to tag library
  • few bugfixes
Version 0.3
  • Tag library
  • optional follow-env file
  • few bugfixes
Version 0.2
  • Serial numbers for tags
  • some new functions for follow
Version 0.1
  • 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
Edited on 27 August 2013 - 02:53 PM
Lyqyd #2
Posted 29 June 2013 - 07:29 PM
Split into new topic.
PixelToast #3
Posted 29 June 2013 - 07:49 PM
nice domain, will mess around with it soon :3 looks cool
Cloudy #4
Posted 02 July 2013 - 03:39 AM
Love the idea.
karelmikie3 #5
Posted 02 July 2013 - 07:07 AM
it looks awesome i will try it when i get home from school :3
boq #6
Posted 06 July 2013 - 02:50 PM
Hi. Just released new version. Update adds posters and glass tags:

I'm starting to run out of ideas (still have few, though), so I will probably slow down updates little bit and focus on bugs.

Weeeelllll, about bugs: mod is now public for about one week, and I got almost no feedback on gameplay. So if there are any issues or bugs (or just general poor quality and overcomplication), that make you to throw away this mod in disgust just after first run, let me know. I will try to fix that as soon as possible.
Edited on 06 July 2013 - 02:42 PM
DeweySalt #7
Posted 06 July 2013 - 06:09 PM
It'd be nice if this had some better documentation :/ Whenever I try to wrap the peripheral, or even get the methods, I just get a nil value. Even the default 'follow' program just gives me the error 'follow:47: Can't move forward', and no, there is no block infront of the turtle.
boq #8
Posted 06 July 2013 - 06:15 PM
How about fuel? 'Can't move forward' is just generic error, when turtle.forward() returns false.
About wrapping - peripheral.wrap(side) should work fine. Can you describe, what exactly are you doing?
DeweySalt #9
Posted 06 July 2013 - 06:37 PM
Oh yes, now the 'follow' program works fine, silly me, sorry :P/>
But other than that, I am doing p = peripheral.wrap("right") (the writer is on the right side) and unpack(p.getMethods()) (or p.listMethods(), I can't remember) in the lua prompt, but it just returns lua:1: attempt to index (a nil value).

Also, not sure what the difference is between the writer and the printer, I've tried the above with both.
boq #10
Posted 06 July 2013 - 06:43 PM
Ah, then you want peripheral.getMethods("right"). Also, you can try "help tag-writer" and "help tag-printer" to get peripherals documentation (also, copies of source and help files are in <minecraft folder>/cctags).
DeweySalt #11
Posted 06 July 2013 - 06:52 PM
Okay, so now I have the methods, but how do you 'select' a tag from the world? By using scanForTags? What I mean is in the 'help tag-writer' it says that you need a tag to be selected in order to use the contents() method, so how would you select a tag for it's contents to be read if it's already placed down in the world?

Please disregard this post, I just had to re-look over the help tag-writer.

On another note, this is a very nice mod. I have a 'maintance turtle' which goes around my house making sure all my automations are functioning and this helps out quite a bit.
boq #12
Posted 06 July 2013 - 07:00 PM
Yeah, that part of documentation needs work (thanks for pointing that). scanForTag(dir) and selectFromSlot(slotId) both select tag as a target for peripheral. First one looks for tags placed in world, second one - in turtle inventory.

For example, to read tag in front of turtle, call
p.scanForTag()
print(p.contents())
print(p.size())
Any next command will also use selected tag (until you move out of range).
scanForTag() will return false, if nothing is found. isTagValid() will return true, if anything is selected.
There is also helper method tags.scanForTags() that will return direction and contents of first found tag on any side.
DeweySalt #13
Posted 06 July 2013 - 07:24 PM
I suggest putting what you just said in the OP :)/>
boq #14
Posted 13 July 2013 - 01:15 PM


Hi! Just updated mod to 1.6.2. New version includes few features, like text icons.

Also, if you are still confused what this mod is about, I added tutorial (in form of world) to original post.
Mandrake Fernflower #15
Posted 13 July 2013 - 01:31 PM
Nice, I think I could use this for a shared computing project where people can update the shared computing code by replacing the poster that has the firmware on it!
boq #16
Posted 13 July 2013 - 01:39 PM
Interesting idea! Can you post results, after it's done? Also, send me info about any bug/bad design/annoying thing you can find. I can fix it, while I'm still here.
KaoS #17
Posted 13 July 2013 - 02:07 PM
such an awesome idea to lose to the dark side

MC 1.6.2 :(/> not even gonna try it
boq #18
Posted 13 July 2013 - 02:11 PM
Uh, why? Too early?
KaoS #19
Posted 13 July 2013 - 02:14 PM
not many mods have updated to 1.6.2 and mod loaders like MMC and FTB are not compatible with it. I love MMC
immibis #20
Posted 13 July 2013 - 09:32 PM
You don't need MMC, forge has an installer.
KaoS #21
Posted 14 July 2013 - 08:51 AM
Yeah but having multiple separate instances of MC is great
Xakorik #22
Posted 15 July 2013 - 11:10 AM
Yeah but having multiple separate instances of MC is great

You can have separate instances of MC, just done manually
KaoS #23
Posted 15 July 2013 - 01:22 PM
manually

<_</>

but I guess I might be whining a bit much. ANYWAYS we are hijacking this guy's thread. I understand you guys' points, I'm just stubborn
boq #24
Posted 15 July 2013 - 02:35 PM
I don't mind. It's not like anything is happening here right now.

Also: new version (mostly small changes) and updated tutorial.

BTW: I noticed yesterday somebody was frantically trying to download cctags-0.4. Sorry, my fault. Should be fixed now.
Yurij #25
Posted 16 July 2013 - 09:05 AM
Theres a problem with 1.6.2
The textures of the tags while using a resource pack is all wrong.
And they stay that way after switching back to default until you restart minecraft

The tags here are using the icon "right"
Using a resource pack (DokuCraft):


After switching back to default:
boq #26
Posted 16 July 2013 - 11:49 AM
Finally, first bugreport! Updated to version 0.6b - should work now.
Yurij #27
Posted 18 July 2013 - 07:03 PM
This is an awesome addon for cc.
I have been able to make my semi-automatic sugar cane farm much more flexible.
boq #28
Posted 20 July 2013 - 02:43 PM

Hey,

Just pushed new version 0.7. Added macros, tags on animals, items and lots of small fixes. And upgraded tutorial (was previous link broken? I'm not sure and nobody told me anything…). Anyway, I'm now almost out of ideas for features, so future updates won't be so frequent.

Edit: Most of the Big Mods are still not ported and 1.6 is little bit boring right now. So I've decided to backport everything from current version to MC 1.5.2. Download here or in OP.
TehSomeLuigi #29
Posted 26 July 2013 - 07:06 AM
Yeah but having multiple separate instances of MC is great

You can have multiple instances of Minecraft in the new launcher, use the forge installer, then just create a profile, select Minecraft version as release-1.6.2 Forge x.x.x.xxx (or similar), and CHANGE the game directory option (so the mods folder, etc, doesn't overlap). To change an existing one use "Edit Profile" button.

Hope this Helps.
boq #30
Posted 27 July 2013 - 12:35 PM
Wow, what an active topic I have…


[media]http://www.youtube.com/watch?v=IvVABPdoDDY[/media]
Anyway, I decided to bump version to 1.0, open source it and make cheesy promo video. Also, even more junk added to tutorial.
KaoS #31
Posted 27 July 2013 - 03:07 PM
Edit: Most of the Big Mods are still not ported and 1.6 is little bit boring right now. So I've decided to backport everything from current version to MC 1.5.2. Download here or in OP.
You, sir, have my respect. I have never seen a mod author backport his creation. I will try it immediately
boq #32
Posted 27 July 2013 - 03:14 PM
Well, number of downloads is horribly low, so I had to do something.

BTW, even if you don't like mod, please, give me feedback why. Especially if it's because of bug (doesn't even need to be here, I'm also available on esper.net)
Yurij #33
Posted 28 July 2013 - 07:17 AM
Feature suggestion:
Inactivate tags with a redstone signal
boq #34
Posted 28 July 2013 - 08:39 AM
Feature suggestion:
Inactivate tags with a redstone signal

Thanks for suggestion, but I want to keep tags passive (no logic, all processing in turtle), so that probably won't happen. Unless there is situation where this can't be done with tags like this and this or anything similar.
Yurij #35
Posted 01 August 2013 - 05:01 AM
Thanks for suggestion, but I want to keep tags passive (no logic, all processing in turtle), so that probably won't happen. Unless there is situation where this can't be done with tags like this and this or anything similar.

Ok.
What I did instead was to make the turtle check for redstone signal before executing the commands on the tag

Is there a way for turtles to get the label of tags?
boq #36
Posted 01 August 2013 - 01:47 PM
Is there a way for turtles to get the label of tags?

Sorry, but no. And I'm not planning to do something like that. In-game explanation: they are physically printed on tag, in human readable form (as well as icons), so turtle can't read them (unless someone does separate scanner peripheral).

But I don't think this is big nuisance - just add label to tag contents.
Yurij #37
Posted 01 August 2013 - 04:21 PM
Sorry, but no. And I'm not planning to do something like that. In-game explanation: they are physically printed on tag, in human readable form (as well as icons), so turtle can't read them (unless someone does separate scanner peripheral). But I don't think this is big nuisance - just add label to tag contents.

To be able to get the label with the turtle is not that important actually.
It was just for the messages about ignored tags would be a tad more aesthetic
NOTUSEDPLEASEDELETE #38
Posted 01 August 2013 - 05:14 PM
Skylanders in Minecraft is just 1 step away! And great work on your peripheral.
boq #39
Posted 02 August 2013 - 03:36 PM
Hmm, interesting! This gave me an idea for new mechanics.

Unfortunately, my free time (and access to internet) will be limited for next two weeks, so I probably won't be able to release new version. Sorry!
MulticolouredMarshmellow #40
Posted 02 August 2013 - 08:36 PM
Awesome! Nice work!

It's amazing how you turn code into awesomeness
boq #41
Posted 24 August 2013 - 03:48 PM
Finally found some time to make new version. This is probably first update that has content based on feedback (not much, but still something).

I also added new feature - remote tag reading. Demo:
[media]http://www.youtube.com/watch?v=ZPAxdr_tubI[/media]
Mikeemoo #42
Posted 30 August 2013 - 09:27 AM
Really nice!
ETHANATOR360 #43
Posted 30 August 2013 - 10:59 AM
i like it
PinYin #44
Posted 31 August 2013 - 08:35 AM
Found a bug: connect a scanner with using a wired modems. Game crashings
boq #45
Posted 31 August 2013 - 08:49 AM
Found a bug: connect a scanner with using a wired modems. Game crashings

Can't reproduce. Please post your crash report.