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

Command block peripheral for MC 1.4

Started by ComputerCraftFan11, 30 September 2012 - 09:42 PM
ComputerCraftFan11 #1
Posted 30 September 2012 - 11:42 PM
With the new command blocks coming up, computercraft needs a way to communicate with them, and this does just that.

With the command peripheral, you get a item that you can attach to a computer (only for admins, no recipe) and it will execute commands.

The commands will be executed like this:

cmd = peripheral.wrap("side")
cmd.execute("Command","Arguments")

Why would this be useful? You can use it to create emails or computers that can connect to the minecraft chat. Another example could be item shops, this is a function that could give a player a item:

sender = peripheral.wrap("front")
while true do
  id, message = rednet.receive()
  if string.sub(message,1,4) == "ITEM" then
	itemID = rednet.receive(0)
	playerID = rednet.receive(0)
	price = sender.execute("worth",itemID) --essentials
	playersBAL = fs.open(".accounts/" ..playerID, "r")
	local tBal = tonumber(playersBAL.readAll())
	playersBAL.close()
	if tBal > price then
	  print(sender.execute("give",playerID,itemID)) --prints "Giving <player> <id>"
	  print("Complete!")
	end
end

Images of what it could look like:
GopherAtl #2
Posted 01 October 2012 - 02:57 AM
I expect there will be a peripheral for this within a few days after a version of CC is released supporting an official (non-snapshot) release of MC that includes the command blocks. :)/>/> The tricky part is going to be user accounts, I would think; I'm not sure how the command block decides what user to execute it's commands as, has anyone looked at the snapshot code or just experimented with the command blocks enough to answer that?
JJRcop #3
Posted 01 October 2012 - 03:26 AM
I think it would be better to just have a peripheral API for the Command Block itself… You know, using peripheral.wrap on a command block?
GopherAtl #4
Posted 01 October 2012 - 03:31 AM
that's…how peripheral add-ons work. Implement the … IPeripheral, I think? interface, and a computer can wrap it. I think you get the ability to craft a turtle with one as a free bonus.

If you mean it should be an official part of CC, well, it might, but I wouldn't count on it. Falls into that category of "people would use them, get hacked, and blame computercraft for being insecure." The command block itself is only intended for use in adventure maps, and I expect they'll have protection against just anyone using them to execute op commands by the time they're officially included in minecraft. Computercraft natively wrapping them would completely break that protection, so not likely in the main, official distro of cc.
Cloudy #5
Posted 01 October 2012 - 09:23 AM
I'd like to include some interaction. Command blocks can only be placed by ops anyway - so it wouldn't be any less secure than the block by itself.
BigSHinyToys #6
Posted 01 October 2012 - 03:25 PM
Now we are getting some ware. given the right set up hacking a computer controlling a command block via WIFI could be a very run challenge.
GopherAtl #7
Posted 01 October 2012 - 04:30 PM
…which is why I would personally be against such a peripheral interface being part of cc core, but hey, whatever lol.
JJRcop #8
Posted 01 October 2012 - 05:40 PM
Either way, I am against this particular idea. With a new block and everything. I'll make a new thread with a core peripheral for the Command Block.