tag:blogger.com,1999:blog-9007601562606157016.post3445001845582447620..comments2023-05-11T16:21:37.725+01:00Comments on <Stuff about="code" />: Raspberry Pi - Minecraft CannonMartin O'Hanlonhttp://www.blogger.com/profile/03047799173301971515noreply@blogger.comBlogger34125tag:blogger.com,1999:blog-9007601562606157016.post-79607479441905677002015-02-10T23:33:46.335+00:002015-02-10T23:33:46.335+00:00Martin,
1) Thanks SO MUCH!!
2) Seems to work grea...Martin, <br />1) Thanks SO MUCH!!<br />2) Seems to work great on Bukkit!<br />3) You Rock!! I told my sons that the author of the "amazing book" responded to our inquiry and updated the code to help them learn, and they were speechless (which is rare... :=) ) <br />They said they want to try to prepare a "special creation" for you based on what they're learning, so something interesting may be coming your way.... <br /><br />Can't wait to go over the code with them in detail as they work through the rest of the book to help them really "get it". You've already gone over the top in helping with the inspiration!<br />Thanks again!derekfchttps://www.blogger.com/profile/14173492640889561077noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-49643180165776083142015-02-10T18:53:39.144+00:002015-02-10T18:53:39.144+00:00So I tested using Bukkit (I only tested it on a Pi...So I tested using Bukkit (I only tested it on a Pi) and as you reported Bukkit ended up reporting a load of errors. It turns out it was because I was using GLOWING_OBSIDIAN for the bullet and unfortunately glowing obsidian doesn't exist as a block on the full version of Minecraft. So I've change it to TNT. <br /><br />I dont know why you received the error in Python though. <br /><br />I have updated it in github.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-3353693957116864772015-02-10T15:42:25.729+00:002015-02-10T15:42:25.729+00:00Thanks SO MUCH, Martin - I got it started and to s...Thanks SO MUCH, Martin - I got it started and to start, stop (exit), tilt, and rotate, but _not_ to fire - it seemed to throw a number of exceptions in Bukkit and would freeze in the python shell, but then produced the following stack trace:<br /><br />Traceback (most recent call last):<br /> File "/Users/username/Desktop/AdventuresInMinecraft/MyAdventures/minecraft-cannon-updated.py", line 393, in <br /> CannonCommands().cmdloop()<br /> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cmd.py", line 142, in cmdloop<br /> stop = self.onecmd(line)<br /> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cmd.py", line 221, in onecmd<br /> return func(arg)<br /> File "/Users/username/Desktop/AdventuresInMinecraft/MyAdventures/minecraft-cannon-updated.py", line 377, in do_fire<br /> while(bullet.update()):<br /> File "/Users/username/Desktop/AdventuresInMinecraft/MyAdventures/minecraft-cannon-updated.py", line 264, in update<br /> if self.mc.getBlock(newDrawPos.x, newDrawPos.y, newDrawPos.z) == block.AIR:<br /> File "/Users/username/Desktop/AdventuresInMinecraft/MyAdventures/mcpi/minecraft.py", line 123, in getBlock<br /> return int(self.conn.sendReceive("world.getBlock", intFloor(args)))<br />ValueError: invalid literal for int() with base 10: ''<br /><br />I also saved the various errors from Bukkit terminal if those would be helpful. <br /><br />Hopefully it is an easy fix to get the firing working - Thanks again!! So exciting to show the boys!! derekfchttps://www.blogger.com/profile/14173492640889561077noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-33841758613594579072015-02-10T09:57:42.794+00:002015-02-10T09:57:42.794+00:00Hi Derek,
The reason the cannon program doesnt wo...Hi Derek,<br /><br />The reason the cannon program doesnt work when you copy it to the MyAdventures folder is a simple one. I wrote it a long time ago using v0.1 of the api the api with AIM is v0.1.1. This morning I updated the code on github to use v0.1.1 so you should be able to re-download it and try again.<br /><br />MartinMartin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-85219588662999833262015-02-09T01:59:11.921+00:002015-02-09T01:59:11.921+00:00Hi Martin, I'm a dad of 2 boys 8 and 11 who ar...Hi Martin, I'm a dad of 2 boys 8 and 11 who are starting to work through your great book Adventures in Minecraft. The cannon does not seem to work, even after adjusting the code at the top for mcpi. instead of minecraft. We still get a number of errors. We're on Mac Yosemite with the bukkit / python 2.7.6 setup recommended from the book, including downloading the starter zip, so we're saving .py files to the MyAdventures sub-folder of the Desktop. I was trying to get this working for them as an inspiration to what they'll be able to work and understand as they master the book... I showed them the Blocks to Bombs in the same environment, and they were thrilled / inspired. I think it would be great if we could get the Cannon working in the Adventures in Minecraft environment - I think the different API might be the issue, per some of the comments above. Could you please make suggestions to how we might fix it to work for the AiM setup - please understand I'm a relative Noob as well, so I'm learning as I go with them. Or perhaps we could get another branch on Git for those wanting to add on to the AiM recommended envinroment? I'm sure it would be a study inspiration for others as well. Thanks so much for the awesome Adventures in Minecraft and the great site / code. derekfchttps://www.blogger.com/profile/14173492640889561077noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-13443144628736346132014-10-02T18:04:25.220+01:002014-10-02T18:04:25.220+01:00Yes and its a little more complex than i thought, ...Yes and its a little more complex than i thought, it started flickering my screen so i stopped it? is that normal?!Anonymoushttps://www.blogger.com/profile/00639957415205472708noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-36892335307120450192014-10-02T10:08:22.252+01:002014-10-02T10:08:22.252+01:00Have you followed the Download and run instruction...Have you followed the Download and run instructions above? This should download the code from github.com and run it. You will need to be in a minecraft world when you run it.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-2217230630374184802014-09-27T11:40:15.017+01:002014-09-27T11:40:15.017+01:00Or if anyone else could help that would be great!Or if anyone else could help that would be great!Anonymoushttps://www.blogger.com/profile/00639957415205472708noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-30118663917098005242014-09-27T11:23:51.729+01:002014-09-27T11:23:51.729+01:00Hey Martin i am completely new to the raspberry pi...Hey Martin i am completely new to the raspberry pi and have only just got minecraft up and running, I love my pi to bits and would be seriously grateful if you could give me a step by step guide to making this cannon work? Anonymoushttps://www.blogger.com/profile/00639957415205472708noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-69707464801961979002014-09-02T09:18:39.693+01:002014-09-02T09:18:39.693+01:00Fantastic, Ill be sure to have a look.Fantastic, Ill be sure to have a look.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-64923249509936616462014-09-01T22:13:59.110+01:002014-09-01T22:13:59.110+01:00My 7 year old isn't very good with the command...My 7 year old isn't very good with the command line and it takes him a couple of seconds to switch between Terminal and Minecraft server so I added a countdown (5 seconds to get in a good viewing position after firing) and a GUI. <br />Here's the repo if anyone wants it (it's essentialy your work)<br />https://github.com/Shane-Lester/Cannon-gui.git<br />Needs Qt so:<br />sudo apt-get install python-pyside <br /><br />Thanks for you work on this, I've enjoyed it.<br /><br />ShaneAnonymoushttps://www.blogger.com/profile/11705144309604482060noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-72826832659950417342014-06-10T15:32:08.858+01:002014-06-10T15:32:08.858+01:00The error is because I wrote the cannon against v0...The error is because I wrote the cannon against v0.1.0 of the API and you are using v0.1.1 of the api. If you use the API version which is included in the minecraft folder in github it'll work fine. <br /><br />Or you can fix it by rounding the values passed in setBlock in the drawPoint3d function.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-48178951463371608502014-06-09T12:15:04.659+01:002014-06-09T12:15:04.659+01:00Hi Martin,
Just came across this post and thought ...Hi Martin,<br />Just came across this post and thought I would try it out at my code club.<br />I am running the latest raspbian wheezy build.<br /><br />I have entered start and the cannon is created, then rotate 10, at this point I get the following error messages<br /><br /> File "minecraft-cannon.py", line 393, in <br /> CannonCommands().cmdloop()<br /> File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop<br /> stop = self.onecmd(line)<br /> File "/usr/lib/python2.7/cmd.py", line 221, in onecmd<br /> return func(arg)<br /> File "minecraft-cannon.py", line 382, in do_rotate<br /> self.cannon.setDirection(int(direction))<br /> File "minecraft-cannon.py", line 342, in setDirection<br /> self.clearGun()<br /> File "minecraft-cannon.py", line 336, in clearGun<br /> self.drawGunInMC(block.AIR)<br /> File "minecraft-cannon.py", line 330, in drawGunInMC<br /> blockType, blockData)<br /> File "minecraft-cannon.py", line 100, in drawLine<br /> self.drawVertices(self.getLine(x1, y1, z1, x2, y2, z2), blockType, blockData)<br /> File "minecraft-cannon.py", line 96, in drawVertices<br /> self.drawPoint3d(vertex.x, vertex.y, vertex.z, blockType, blockData)<br /> File "minecraft-cannon.py", line 39, in drawPoint3d<br /> self.mc.setBlock(x,y,z,blockType,blockData)<br /> File "/home/pi/minecraft/minecraft.py", line 138, in setBlock<br /> self.conn.send("world.setBlock", intFloor(args))<br /> File "/home/pi/minecraft/minecraft.py", line 22, in intFloor<br /> return [int(math.floor(x)) for x in flatten(args)]<br />TypeError: a float is required<br /><br />I am using Python 2.7 not 3<br />cheers<br />Steve GaleRambleOnhttps://www.blogger.com/profile/08476819559402683756noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-80251665289975511092014-04-10T16:49:07.914+01:002014-04-10T16:49:07.914+01:00Ok. At some point I must have come across the sam...Ok. At some point I must have come across the same issue, because I have modded by minecraft-stuff class to take care of the issue, so change:<br /><br />def drawPoint3d(self, x, y, z, blockType, blockData=None):<br /><br />to<br /><br />def drawPoint3d(x, y, z, blockType, blockData=0):Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-20391856722647023312014-04-10T14:26:01.033+01:002014-04-10T14:26:01.033+01:00I see. Ill have to update the code when I get 2 m...I see. Ill have to update the code when I get 2 mins.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-82108099304466047632014-04-10T11:30:39.204+01:002014-04-10T11:30:39.204+01:00Finally figured this out -- in your github the fil...Finally figured this out -- in your github the file minecraft/minecraft.py is from v0.1.0. Check line 5: Minecraft PI low level api v0.1_0<br />Where as I am using 0.1.1 which amongst other things has a fussier setTilePos()LXFjbhttps://www.blogger.com/profile/08977996470114114574noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-36070625555285688622014-04-10T11:28:50.050+01:002014-04-10T11:28:50.050+01:00This comment has been removed by the author.LXFjbhttps://www.blogger.com/profile/08977996470114114574noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-79857223523214311692014-04-09T21:21:47.154+01:002014-04-09T21:21:47.154+01:00I have just retried the code, got it fresh out of ...I have just retried the code, got it fresh out of github and no problems. Sorry dont know what to suggest.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-61685562409144874652014-04-09T16:26:00.393+01:002014-04-09T16:26:00.393+01:00This is with Python 2.7.3 on up-to-date Raspbian, ...This is with Python 2.7.3 on up-to-date Raspbian, mcpi 0.1.1 and the code from your github. It's very odd, and I would like to understand it better, but handling of None vs actual nothing is hard. With your code, if I start the cannon and then issue the fire command, then the bullet draw() function triggers the error, which ultimately is thrown by math.floor being called with an empty list, which is clearly wrong. LXFjbhttps://www.blogger.com/profile/08977996470114114574noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-33217149719474644322014-03-27T14:05:46.017+00:002014-03-27T14:05:46.017+00:00I have no idea why you need to do this! I use the...I have no idea why you need to do this! I use the same MinecraftDrawing class in loads of my projects and I have never seen this issue. Its using the minecraft.py and block.py api libraries which came with 0.1.1. What version are you using? Also what version of python were you using?Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-41891967863659564122014-03-26T11:34:24.002+00:002014-03-26T11:34:24.002+00:00Hi Martin. Nice Cannon.
I found I had to modify th...Hi Martin. Nice Cannon.<br />I found I had to modify the code slightly in order to fire/adjust the weapon though. Problem was the call to self.mc.setBlock on line 38, which doesn't work if blockData is None, i.e. if the preceding call to drawPoint3d is made without a blockData argument. Here is a diff against my working version which may or may not clarify things:<br /><br /> def drawPoint3d(self, x, y, z, blockType, blockData=None):<br />- self.mc.setBlock(x,y,z,blockType,blockData)<br />+ if blockData == None:<br />+ self.mc.setBlock(x,y,z,blockType)<br />+ else:<br />+ self.mc.setBlock(x,y,z,blockType,blockData)<br /><br />Do you have any insight as to why I need to do this? Am thinking maybe something changed in mcpi 0.1.1. Anyways, thanks for your tutorials!LXFjbhttps://www.blogger.com/profile/08977996470114114574noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-72709402608399782412014-01-08T15:55:34.505+00:002014-01-08T15:55:34.505+00:00Either. If you run the program from the command l...Either. If you run the program from the command line e.g. by using python minecraft-cannon.py, just type the commands into the command line. If you are running the code from Idle, type it into the Python run window.Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-88876607501542672952014-01-07T19:17:14.010+00:002014-01-07T19:17:14.010+00:00Should I use a command line terminal or a python c...Should I use a command line terminal or a python code editor to type in the cannon's code?Anonymoushttps://www.blogger.com/profile/05280304958827634057noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-77076210749055603392013-12-13T09:25:47.368+00:002013-12-13T09:25:47.368+00:00What do you mean? Do you mean a minecraft server ...What do you mean? Do you mean a minecraft server running on a Pi?Martin O'Hanlonhttps://www.blogger.com/profile/03047799173301971515noreply@blogger.comtag:blogger.com,1999:blog-9007601562606157016.post-62524699338407899262013-12-12T20:45:52.732+00:002013-12-12T20:45:52.732+00:00you are so epic Martin, hey do you know if there i...you are so epic Martin, hey do you know if there is a way to make a pi server that is.not connected by lan?Harvey Grahamhttps://www.blogger.com/profile/09665061301176805174noreply@blogger.com