Jump to content




Command Computer's Turtle API

turtle api command

20 replies to this topic

#1 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 21 March 2015 - 01:39 PM

pastebin get CQUAprWH turtle

Not entirely sure this is useful, but the idea seemed like fun, so this evening I put it together. Haven't done much in the way of testing, though it seems to work with eg this.

Here we have a turtle API for use with command computers. Run it and the system will ask you to specify the co-ordinates of your virtual turtle before loading the API for you (you can't load it as an API yourself).

The "turtle"'s main physical presence is tied to the original command computer, and so cannot wrap peripherals that aren't attached to that command computer, and its redstone capabilities suffer from the same limitations. However, it is able to "move" around the world, digging, placing, and so on. Mobs will not block it.

Attacking always returns false, as does sucking or equipping items (that is to say, these functions are not implemented, and I'm not sure I can implement them). The turtle always assumes it has a digging tool available, which it'll use in a silk-touch-like manner.

It cannot consume fuel items, but initialises with a billion fuel units. Attempting to refuel will top it back up to maximum.

Because the command computer has no inventory of its own, to give your virtual turtle items you must first give them to a real turtle. Run this script on that turtle, and it'll copy a readout of what it's holding to a floppy in an attached disk drive. The command computer will use that listing if the same disk is available to it when you run the script on that. There's no method of extracting items from the virtual turtle, but considering you need creative-mode access to run it in the first place, that isn't much of a problem.

Edited by Bomb Bloke, 22 March 2015 - 10:41 PM.


#2 biggest yikes

  • Members
  • 573 posts

Posted 21 March 2015 - 02:09 PM

Sounds cool, but I got a big fat juicy error in the face when booted with CC 1.73
Posted Image

Edited by Atenefyr, 21 March 2015 - 02:10 PM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 21 March 2015 - 11:40 PM

Oops! That's what I get for making last minute changes past midnight. Give it another go. ;)

#4 biggest yikes

  • Members
  • 573 posts

Posted 22 March 2015 - 02:02 PM

Testing now, it's so freaking cool! :D
Only thing is, clicking in the edit program is bugged because of the brown outline..

Also, I made a small program that can give an item to your virtual turtle without having to place another turtle. ( http://pastebin.com/g9KPetvv ) It requires a disk drive attached, and you can give an item with it's ID, count, and metadata, so if you installed the program and typed "give ComputerCraft:CC-Turtle 1 0" it would give a normal turtle to your virtual turtle to place down. It will also add items on if there is already an inventory.txt. :D

Edited by Atenefyr, 22 March 2015 - 04:15 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 March 2015 - 12:42 PM

That's a good point; I can't really center my little turtle window without using a custom coroutine manager to filter the mouse_click events. Ah well, I've stuck it up in the top-left corner instead. That still leaves open the possibility of users clicking "out-of-bounds", but I'm not too fussed.

(Though, people actually use edit??)

Can't help but read your script's name as "turtle a pig give". Tee hee... But be wary of using "table" as a variable name! You're discarding the table API by doing that!

It may or may not be important to note that when entering item / block names manually, case matters. Come to think of it, TheOriginalBIT's Item Dictionary peripheral could potentially be ideal for facilitating item name entry, especially if it were rigged to do non-case-sensitive lookups... Unfortunately that's out of commission at the moment, but I may have to bug him about it.

#6 biggest yikes

  • Members
  • 573 posts

Posted 12 April 2015 - 09:08 PM

View PostBomb Bloke, on 23 March 2015 - 12:42 PM, said:

be wary of using "table" as a variable name! You're discarding the table API by doing that!
Ugh, now I have to reset my password for the billionth time because Pastebin always refuses to let me log in, so I can change that. Great.
Thanks for the warning, though :P

Edited by Atenefyr, 12 April 2015 - 09:08 PM.


#7 Agent Silence

  • Members
  • 319 posts
  • Location[string "FindMe"]:23143: bad argument #1 to 'returnPos' (vector expected, got nil)

Posted 14 April 2015 - 11:33 PM

You can use /setblock to create the turtle. You can also change the direction of it
/setblock X Y Z turtleIDHere 4
1 = East, 2 = West, 3 = South, 4 = North

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 April 2015 - 11:52 PM

Indeed, but I prefer using a command computer as the "dummy" for a couple of reasons: I can't create a turtle which looks notably different from a normal one (I can't make one the colour of a command computer for eg), and people can more easily interfere with an actual turtle.

Also, I'm not sure that command'd work. Turtles use NBT tags for their facing.

#9 moomoomoo3O9

  • Members
  • 82 posts
  • LocationPork roll land

Posted 23 July 2015 - 11:19 PM

View PostBomb Bloke, on 14 April 2015 - 11:52 PM, said:

Indeed, but I prefer using a command computer as the "dummy" for a couple of reasons: I can't create a turtle which looks notably different from a normal one (I can't make one the colour of a command computer for eg), and people can more easily interfere with an actual turtle.

Also, I'm not sure that command'd work. Turtles use NBT tags for their facing.
You can summon falling sand to place blocks with NBT using command computers (but you can't detect NBT unfortunately), so rotation could be possible if you didn't need to keep an inventory and knew its starting orientation.

#10 negamartin

  • Members
  • 46 posts

Posted 24 July 2015 - 01:09 AM

Isn't it possible to just use setblock's NBT parameter? Maybe you could even summon a real turtle, with suck/drop capabilities. Now that I think of it, placing a turtle with your same ID can make suck, drop, rs, peripheral wrapping, and even(but slower) non silktouch digging work. But using real turtle.dig would be kinda pointless, because you can use a real turtle. Maybe only placing a real turtle when suck/drop/rs/peripheral is required?

#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 July 2015 - 02:41 AM

To my limited understanding, the falling sand trick was the way to setblock before the current setblock command was introduced.

I'm aware of how to place a turtle with a specific facing, but prefer to place something that looks specifically "Command Computer"-related. None of the 16 colours available to turtles cut the mustard. I was really just commenting on the specific command structure Agent Silence provided.

Using a "real" turtle to perform the functions the Command Computer cannot sorta defeats the purpose, that being to, well, do everything a turtle can do without having an actual turtle do it. But yes, substituting in a real turtle purely for the sake of sucking items or for attacking is tempting. Unfortunately, the only command I'm aware of that would allow me to then delete them without dropping their items into the world is "blockdata", which requires MC 1.8.

Edited by Bomb Bloke, 24 July 2015 - 02:41 AM.


#12 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 11 December 2015 - 05:55 PM

Couldn't you give the "Turtles" a virtual inventory tracked in a table on the Command Computer? Then when the "Turtle" is broken /summon each item from the inventory to get back the items.

#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 12 December 2015 - 01:50 AM

The script does track a virtual inventory for them, but I'm not sure I can think of a method for detecting that the turtle has been "broken" which I like.

ComputerCraft's move to 1.8 should open up some possibilities, however; for example, I believe it will be possible for this "turtle" to drop items into a chest. Sucking will still be an issue without a method of reading NBT data, however...

#14 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 13 December 2015 - 04:47 PM

Just call
commands.getBlockInfo(number x, number y, number z)
every so often on where it thinks the "Turtle" is at.

#15 Lion4ever

  • Members
  • 91 posts

Posted 14 December 2015 - 03:56 PM

View PostBomb Bloke, on 12 December 2015 - 01:50 AM, said:

ComputerCraft's move to 1.8 should open up some possibilities, [...] Sucking will still be an issue without a method of reading NBT data, however...
Luckily 1.8 does offer a method like that: /blockdata ~ ~ ~ {}
It returns false, a complain that nothing has changed and the nbt tag.

Since 1.8 has a /entitydata: Can you modify your api so that the turtle can be represented by any mob (with {NoAI:1b} ) and Armorstands (with {NoGravity:1b} )? Or allow me to modify your script and link it from here?
With the ArmorStand Pose tag it would even be possible to have an animated turtle/player like thing.

#16 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 December 2015 - 12:48 AM

View PostLion4ever, on 14 December 2015 - 03:56 PM, said:

Luckily 1.8 does offer a method like that: /blockdata ~ ~ ~ {}
It returns false, a complain that nothing has changed and the nbt tag.

:o :o :o

And we have an NBT reader for tile entities!

Mwuahahaha!

View PostLion4ever, on 14 December 2015 - 03:56 PM, said:

Since 1.8 has a /entitydata: Can you modify your api so that the turtle can be represented by any mob (with {NoAI:1b} ) and Armorstands (with {NoGravity:1b} )? Or allow me to modify your script and link it from here?
With the ArmorStand Pose tag it would even be possible to have an animated turtle/player like thing.

I've got a bit on my plate, so it'll likely be a little while before I get around to playing with the new 1.8 commands. If you'd like to modify the script yourself, that'd be great. :)

#17 Lion4ever

  • Members
  • 91 posts

Posted 15 December 2015 - 05:46 AM

Ok, moving entities does now work, but there aren't any animations for armorstands yet.
http://pastebin.com/rYsd9J8B

#18 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 December 2015 - 02:26 PM

I see lots of code in there for which I've little idea as to the purpose... and some of your code, too! ;) Pretty cool!

The turtle window wasn't centered because of mouse_click events; I'll stick a translator in there eventually, but for now it might be better to stick it back up in the top left.

Can the script perhaps be rigged to create a suitable entity, like a lobotomised mini-slime or something? I'm too lazy to look up a selector to make it control anything other than myself...

Edited by Bomb Bloke, 15 December 2015 - 02:26 PM.


#19 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 15 December 2015 - 02:36 PM

Perhaps invisible immortal floating armor stand with turtle as head?

#20 Lion4ever

  • Members
  • 91 posts

Posted 15 December 2015 - 04:23 PM

View PostBomb Bloke, on 15 December 2015 - 02:26 PM, said:

The turtle window wasn't centered because of mouse_click events; I'll stick a translator in there eventually, but for now it might be better to stick it back up in the top left.
Ok, i'll change that back then.

View PostBomb Bloke, on 15 December 2015 - 02:26 PM, said:

Can the script perhaps be rigged to create a suitable entity, like a lobotomised mini-slime or something? I'm too lazy to look up a selector to make it control anything other than myself...
@e[type=Pig,c=1]
Asking for a selcetor was my first choice because it is by far the most flexible way to select a entity and the ability to seize a creeper running by and let him do your work is quite satisfying. Only asking for the type may indeed be a bit easier for the user.

View PostWojbie, on 15 December 2015 - 02:36 PM, said:

Perhaps invisible immortal floating armor stand with turtle as head?
With or without armor? :D
I am going to add that as a default.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users