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

Command Computer's Turtle API

Started by Bomb Bloke, 21 March 2015 - 12:39 PM
Bomb Bloke #1
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 on 22 March 2015 - 09:41 PM
biggest yikes #2
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
Edited on 21 March 2015 - 01:10 PM
Bomb Bloke #3
Posted 21 March 2015 - 11:40 PM
Oops! That's what I get for making last minute changes past midnight. Give it another go. ;)/>
biggest yikes #4
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 on 22 March 2015 - 03:15 PM
Bomb Bloke #5
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.
biggest yikes #6
Posted 12 April 2015 - 10:08 PM
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 on 12 April 2015 - 08:08 PM
Agent Silence #7
Posted 15 April 2015 - 12:33 AM
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
Bomb Bloke #8
Posted 15 April 2015 - 12:52 AM
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.
moomoomoo3O9 #9
Posted 24 July 2015 - 12:19 AM
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.
negamartin #10
Posted 24 July 2015 - 02: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?
Bomb Bloke #11
Posted 24 July 2015 - 03: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 on 24 July 2015 - 01:41 AM
Selim #12
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.
Bomb Bloke #13
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…
Selim #14
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.
Lion4ever #15
Posted 14 December 2015 - 03:56 PM
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.
Bomb Bloke #16
Posted 15 December 2015 - 12:48 AM
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!

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. :)/>
Lion4ever #17
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
Bomb Bloke #18
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 on 15 December 2015 - 01:26 PM
Wojbie #19
Posted 15 December 2015 - 02:36 PM
Perhaps invisible immortal floating armor stand with turtle as head?
Lion4ever #20
Posted 15 December 2015 - 04:23 PM
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.

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.

Perhaps invisible immortal floating armor stand with turtle as head?
With or without armor? :D/>
I am going to add that as a default.
Lion4ever #21
Posted 15 December 2015 - 05:08 PM
Updated.
Window is top left again
Only asking for type instead of selector now.
And default is an ArmorStand with a turtle on its head.