├── raspberryjammod ├── TODO ├── mcpipy │ ├── NeuroPy │ │ ├── __init__.py │ │ └── README.txt │ ├── mcpi │ │ ├── __init__.py │ │ ├── security.py │ │ ├── settings.py │ │ ├── minecraft-pi-edition-LICENSE.txt │ │ ├── util.py │ │ ├── event.py │ │ ├── entity.py │ │ ├── mcpi_protocol_spec.txt │ │ ├── vec3.py │ │ └── connection.py │ ├── models │ │ ├── COPYRIGHT │ │ ├── ds9.txt │ │ ├── cube.txt │ │ ├── humanoid_quad.txt │ │ ├── head.txt │ │ ├── skyscraper.txt │ │ ├── dragon.txt │ │ ├── cessna.txt │ │ ├── redstardestroyer.txt │ │ ├── atat.txt │ │ ├── knight.txt │ │ ├── jemcruiser.txt │ │ ├── yt1300.txt │ │ ├── shuttle.txt │ │ ├── neghvar.txt │ │ ├── stardestroyer.txt │ │ ├── RaspberryPi.txt │ │ ├── City_Ground-Notts.txt │ │ ├── NY_LIL.txt │ │ ├── bop.txt │ │ └── 1701d.txt │ ├── ovalegg.png │ ├── pysanka.jpg │ ├── pysanka2.jpg │ ├── mcpipy.v12.suo │ ├── sign.py │ ├── turtle.py │ ├── top.py │ ├── vehicles │ │ ├── readme.md │ │ ├── TIE_Fighter.py │ │ └── X-Wing_Fighter.py │ ├── mc.py │ ├── star.py │ ├── helloworld.py │ ├── snowflake.py │ ├── test.py │ ├── simplefractaltree.py │ ├── turtledonut.py │ ├── simpletree.py │ ├── benchmark.py │ ├── interpreter.py │ ├── sphere.py │ ├── ltree.py │ ├── squarecurve.py │ ├── bridge.py │ ├── glasscube.py │ ├── nt7s_sphere.py │ ├── knot.py │ ├── zhuowei_rainbow.py │ ├── teleport.py │ ├── explosify.py │ ├── hilbert.py │ ├── dragoncurve.py │ ├── donut.py │ ├── fancytree.py │ ├── trefoil.py │ ├── brooksc_findpos.py │ ├── knot2.py │ ├── README.md │ ├── server.py │ ├── mcpipy.sln │ ├── spiral.py │ ├── mcdragoncurve.py │ ├── console.py │ ├── mobius.py │ ├── turtleconsole.py │ ├── digitalclock.py │ ├── neurosky.py │ ├── egg.py │ ├── trefoil2.py │ ├── borromean.py │ ├── klein.py │ ├── globe.py │ ├── spacefill.py │ ├── gf_drawbuilding.py │ ├── fleap_railgen.py │ ├── clock.py │ ├── win32move.py │ ├── mengersponge.py │ ├── sierpinski3d.py │ ├── lforest.py │ ├── klein2.py │ ├── stuffaboutcode_bridge.py │ ├── grenade.py │ ├── jjinux_sierpinski_triangle.py │ ├── blocks_to_bombs.py │ ├── stuffaboutcode_basics.py │ ├── toschematic.py │ ├── stuffaboutcode_hideandseek.py │ ├── camera.py │ ├── life.py │ ├── lsystem.py │ ├── input.py │ ├── text.py │ ├── scan.py │ ├── import.py │ ├── mcpipy.pyproj │ ├── castle.py │ ├── brooksc_tntsnake.py │ ├── pysanka.py │ ├── davef21370_maze.py │ ├── mandelbrot.py │ ├── astrotutor_magic.py │ └── symmetry.py ├── depends.txt ├── LICENSE ├── settings.conf ├── socket │ ├── core.dll │ ├── cx64.dll │ ├── core-x64.dll │ └── patch-x64.lua ├── installation.txt ├── slowbit32.lua └── socket.lua ├── LICENSE ├── raspberryjammod-minetest-windows-msvc.zip └── README.md /raspberryjammod/TODO: -------------------------------------------------------------------------------- 1 | win32move doesn't work -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/NeuroPy/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/LICENSE -------------------------------------------------------------------------------- /raspberryjammod/depends.txt: -------------------------------------------------------------------------------- 1 | default 2 | wool 3 | farming? 4 | doors? 5 | flowers? 6 | stained_glass? -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['minecraft', 'block', 'entity', 'connection'] 2 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/security.py: -------------------------------------------------------------------------------- 1 | AUTHENTICATION_USERNAME=None 2 | AUTHENTICATION_PASSWORD=None 3 | -------------------------------------------------------------------------------- /raspberryjammod/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/LICENSE -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/COPYRIGHT: -------------------------------------------------------------------------------- 1 | See copyright and credits for the meshes in the individual txt files. 2 | -------------------------------------------------------------------------------- /raspberryjammod/settings.conf: -------------------------------------------------------------------------------- 1 | python = python 2 | restrict_to_local_connections = false 3 | support_websockets = true 4 | -------------------------------------------------------------------------------- /raspberryjammod/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/socket/core.dll -------------------------------------------------------------------------------- /raspberryjammod/socket/cx64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/socket/cx64.dll -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/ovalegg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/mcpipy/ovalegg.png -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/pysanka.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/mcpipy/pysanka.jpg -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/pysanka2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/mcpipy/pysanka2.jpg -------------------------------------------------------------------------------- /raspberryjammod/socket/core-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/socket/core-x64.dll -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpipy.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/mcpipy/mcpipy.v12.suo -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/ds9.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod/mcpipy/models/ds9.txt -------------------------------------------------------------------------------- /raspberryjammod-minetest-windows-msvc.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpruss/raspberryjammod-minetest/HEAD/raspberryjammod-minetest-windows-msvc.zip -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/sign.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | mc = Minecraft() 3 | mc.setBlock(-1,-1,-1,1) 4 | mc.conn.send("world.setBlocks",0,0,0,5,5,5,63,1,"{id:\"Sign\",Text1:\"My sign\"}") 5 | -------------------------------------------------------------------------------- /raspberryjammod/installation.txt: -------------------------------------------------------------------------------- 1 | In socket/core.dll is a win32 Microsoft Visual C build from luasockets as well as a win64 2 | build. Replace with something that fits your operating system if you need to. 3 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/turtle.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | # for backwards compatibility with earlier versions of 5 | # Pruss's instructable 6 | from mcturtle import * 7 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/cube.txt: -------------------------------------------------------------------------------- 1 | file cube.obj 2 | size 50 3 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/cube.obj 4 | credits Downloaded from Martin O'Hanlon's repository 5 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/top.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | 3 | mc = Minecraft() 4 | 5 | playerPos = mc.player.getTilePos() 6 | mc.player.setPos(playerPos.x, mc.getHeight(playerPos.x, playerPos.z)+1, playerPos.z) 7 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/vehicles/readme.md: -------------------------------------------------------------------------------- 1 | Minecraft TIE Fighter vehicle copyright (c) 2015 C. Pruss and D. Pruss 2 | Minecraft X-Wing Fighter vehicle copyright (c) 2015 C. Pruss 3 | Unlimited free distribution permitted 4 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/humanoid_quad.txt: -------------------------------------------------------------------------------- 1 | file humanoid_quad.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/humanoid_quad.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/head.txt: -------------------------------------------------------------------------------- 1 | file head.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/head.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | swapyz 0 5 | size 50 6 | default GOLD_BLOCK 7 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mc.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcpi.minecraft import * 6 | from mcpi.entity import * 7 | from mcpi.block import * 8 | from mcpi.settings import * 9 | from math import * 10 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/skyscraper.txt: -------------------------------------------------------------------------------- 1 | file skyscraper.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/skyscraper.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | swapyz 0 5 | size 100 6 | default IRON_BLOCK 7 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/star.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | t = Turtle() 7 | t.penblock(GOLD_BLOCK) 8 | t.turtle(GIANT) 9 | t.pendelay(0.01) 10 | for i in range(7): 11 | t.go(50) 12 | t.left(180.-180./7) 13 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/helloworld.py: -------------------------------------------------------------------------------- 1 | import mcpi.minecraft as minecraft 2 | import mcpi.block as block 3 | import server 4 | import sys 5 | mc = minecraft.Minecraft() 6 | mc.postToChat("Hello world!") 7 | playerPos = mc.player.getPos() 8 | mc.setBlock(playerPos.x,playerPos.y-1,playerPos.z,block.DIAMOND_ORE) 9 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/dragon.txt: -------------------------------------------------------------------------------- 1 | file 'dragon.ply' 2 | urlgz http://www.cc.gatech.edu/data_files/large_models/dragon.ply.gz 3 | swapyz 0 4 | credits Mesh from Georgia Tech's Website (based on Stanford's scan) 5 | yaw 0 6 | pitch 0 7 | roll 0 8 | size 100 9 | default REDSTONE_BLOCK 10 | end 11 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/settings.py: -------------------------------------------------------------------------------- 1 | from os import environ 2 | 3 | MINECRAFT_POCKET_EDITION = 0 4 | MINECRAFT_PI = 1 5 | MINECRAFT_DESKTOP = 2 6 | 7 | minecraftType = MINECRAFT_DESKTOP 8 | 9 | try: 10 | minecraftType = int(environ['MINECRAFT_TYPE']) 11 | except: 12 | pass 13 | 14 | isPE = ( minecraftType != MINECRAFT_DESKTOP ) 15 | 16 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/minecraft-pi-edition-LICENSE.txt: -------------------------------------------------------------------------------- 1 | *** The real license isn't finished yet, here's what goes in plain english *** 2 | 3 | You may execute the minecraft-pi binary on a Raspberry Pi or an emulator 4 | You may use any of the source code included in the distribution for any purpose (except evil) 5 | 6 | You may not redistribute any modified binary parts of the distribution 7 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/cessna.txt: -------------------------------------------------------------------------------- 1 | file cessna.obj 2 | size 100 3 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/cessna.obj 4 | credits Downloaded from Martin O'Hanlon's repository 5 | default IRON_BLOCK 6 | materials 7 | yellow WOOL_YELLOW 8 | red WOOL_RED 9 | white WOOL_WHITE 10 | black WOOL_BLACK 11 | glass GLASS 12 | dkgrey WOOL_GRAY 13 | 14 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/redstardestroyer.txt: -------------------------------------------------------------------------------- 1 | file stardestroyer.obj 2 | #urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/ds9.obj.gz 3 | swapyz 0 4 | size 200 5 | default WOOL_RED 6 | credits Model and Maps by Alex Lukachuk chimaera@club-internet.fr. Source: scifi3d.com. Star Wars is copyright (c) Lucasfilm. Noncommercial use only. 7 | 8 | materials 9 | end 10 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/atat.txt: -------------------------------------------------------------------------------- 1 | file 'atat.obj' 2 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/atat.obj.gz 3 | swapyz 0 4 | credits Brad Blackburn . Downloaded from scifi3d.com. Star Wars is copyright (c) Lucasfilm. Noncommercial use only. 5 | yaw 90 6 | size 100 7 | default STONE 8 | #order material position 9 | materials 10 | New.2 default 11 | New.1 default 12 | end 13 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/snowflake.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | import lsystem 6 | from mcturtle import * 7 | t = Turtle() 8 | t.pendelay(0) 9 | t.penblock(GOLD_BLOCK) 10 | t.turtle(None) 11 | 12 | rules = { 'F': 'F-F++F-F' } 13 | axiom = 'F++F++F' 14 | 15 | dictionary = { 16 | 'F': lambda: t.go(2), 17 | '+': lambda: t.yaw(60), 18 | '-': lambda: t.yaw(-60), 19 | } 20 | 21 | lsystem.lsystem(axiom, rules, dictionary, 4) 22 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import mcpi.minecraft as minecraft 4 | import mcpi.block as block 5 | import server 6 | import math 7 | 8 | mc = minecraft.Minecraft.create(server.address) 9 | mc.player.setPos(0,3,4) 10 | print "hello" 11 | mc.setBlock(0,0,0,3,0) 12 | print mc.getBlock(0,0,0) 13 | pos = mc.player.getPos() 14 | pos.x = pos.x - 10 15 | print mc.player.getPitch() 16 | print mc.player.getRotation() 17 | print mc.player.getDirection() 18 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/simplefractaltree.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from turtle import * 6 | 7 | def tree(depth): 8 | t.up(30) 9 | t.go(20) 10 | if depth > 1: 11 | tree(depth-1) 12 | t.back(20) 13 | t.down(60) 14 | t.go(20) 15 | if depth > 1: 16 | tree(depth-1) 17 | t.back(20) 18 | t.up(30) 19 | 20 | t = Turtle() 21 | t.follow() 22 | t.verticalangle(90) 23 | t.pendelay(0) 24 | t.go(20) 25 | tree(5) 26 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/turtledonut.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | 7 | t = Turtle() 8 | t.pendelay(0) 9 | radius = 20 10 | circumference = 2 * radius * pi 11 | t.penwidth(10) 12 | t.penblock(GLASS) 13 | for i in range(90): 14 | t.go(circumference/90.) 15 | t.left(4) 16 | t.penwidth(7) 17 | t.penblock(GOLD_BLOCK) 18 | for i in range(90): 19 | t.go(circumference/90.) 20 | t.left(4) 21 | t.penup() 22 | t.back(20) 23 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/simpletree.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | t = Turtle() 7 | t.pendelay(0) 8 | t.turtle(None) 9 | 10 | def tree(counter,branchLen): 11 | if counter == 0: 12 | return 13 | t.go(branchLen) 14 | for i in range(4): 15 | t.pitch(30) 16 | tree(counter-1,branchLen*0.75) 17 | t.pitch(-30) 18 | t.roll(90) 19 | t.back(branchLen) 20 | 21 | t.penblock(WOOD) 22 | t.verticalangle(90) 23 | tree(6,20) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # raspberryjammod-minetest 2 | Raspberry Jam Mod for Minetest 3 | 4 | Implements most of Raspberry PI Minecraft API in Minetest. 5 | 6 | If you have secure.enable_security = true in minetest.conf, then make sure you have raspberryjammod 7 | listed under secure.trusted_mods. Raspberry Jam Mod cannot be rewritten without needing to be trusted, 8 | because of the following essential features: 9 | - loading tcp/ip socket dynamic library 10 | - executing and terminating python interpreter with /py command. 11 | -------------------------------------------------------------------------------- /raspberryjammod/socket/patch-x64.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- core-x64.dll is compiled with msvc 12, without any changes to the luasockets 3 | -- source. Unfortunately, this forces it to be named core.dll, which doesn't work 4 | -- well with what I did to socket.lua to make it load the x64 version as needed. 5 | -- So we patch it. 6 | -- 7 | 8 | local f = assert(io.open("core-x64.dll", "rb")) 9 | local data = f:read("*all") 10 | f:close() 11 | data = data:gsub("luaopen_socket_core", "luaopen_socket_cx64") 12 | local f = assert(io.open("cx64.dll", "wb")) 13 | f:write(data) 14 | f:close() 15 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/benchmark.py: -------------------------------------------------------------------------------- 1 | from time import time 2 | from mcpi.minecraft import Minecraft 3 | mc = Minecraft.create() 4 | t = time() 5 | for i in range(1000): 6 | mc.getBlock(0,0,0) 7 | print "getBlock : {}ms".format(1000.*(time()-t)/1000.) 8 | t = time() 9 | for i in range(10000): 10 | mc.setBlock(0,0,0,1) 11 | mc.getBlock(0,0,0) 12 | print "setBlock same : {}ms".format(1000.*(time()-t)/10000.) 13 | t = time() 14 | for i in range(10000): 15 | mc.setBlock(0,0,0,i&1) 16 | mc.getBlock(0,0,0) 17 | print "setBlock different : {}ms".format(1000.*(time()-t)/10000.) 18 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/interpreter.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander R. Pruss 3 | # 4 | # Useful for checking which interpreter RaspberryJamMod's /py command is picking up. 5 | # 6 | 7 | import mc 8 | import sys 9 | import os 10 | 11 | mc = mc.Minecraft() 12 | mc.postToChat("Python interpreter "+sys.executable+" "+sys.version) 13 | try: 14 | userName = os.environ['MINECRAFT_PLAYER_NAME'] 15 | except: 16 | userName = "unspecified" 17 | try: 18 | userId = os.environ['MINECRAFT_PLAYER_ID'] 19 | except: 20 | userId = "unspecified" 21 | mc.postToChat("Invoked by user "+userName+" "+userId) 22 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/sphere.py: -------------------------------------------------------------------------------- 1 | from mcturtle import * 2 | import sys 3 | from ast import literal_eval 4 | 5 | def parseBlock(s): 6 | try: 7 | return literal_eval(s) 8 | except: 9 | return globals()[s.upper()] 10 | 11 | t = Turtle() 12 | t.pendelay(0) 13 | if len(sys.argv) >= 2: 14 | radius = int(sys.argv[1]) 15 | else: 16 | radius = 10 17 | if len(sys.argv) >= 3: 18 | material = parseBlock(sys.argv[2]) 19 | else: 20 | material = GOLD_BLOCK 21 | t.penwidth(2*radius) 22 | t.penblock(material) 23 | t.go(0) 24 | t.pitch(90) 25 | t.penup() 26 | t.go(radius+2) 27 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/knight.txt: -------------------------------------------------------------------------------- 1 | file 'knight.stl' 2 | swapyz 1 3 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/knight.stl.gz 4 | credits Knight from Chess - Classic Set by SteedMaker. CC Attribution Share Alike 3.0 5 | yaw 0 6 | pitch 0 7 | roll 0 8 | size 100 9 | default STAINED_GLASS_BLUE 10 | #order material position 11 | materials 12 | end 13 | 14 | Knight from Chess - Classic Set by SteedMaker. 15 | http://www.thingiverse.com/thing:34017 16 | licensed under the Creative Commons - Attribution - Share Alike license 3.0 17 | http://creativecommons.org/licenses/by-sa/3.0/ 18 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/ltree.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | import lsystem 6 | from mcturtle import * 7 | 8 | t = Turtle() 9 | t.pendelay(0) 10 | t.penblock(WOOD) 11 | t.turtle(None) 12 | t.pitch(90) 13 | 14 | rules = {'L':'[^FL]>[^FL]>[^FL]'} 15 | axiom = 'FL' 16 | 17 | dictionary = { 18 | 'F': lambda: t.go(10), 19 | '+': lambda: t.yaw(90), 20 | '-': lambda: t.yaw(-90), 21 | '^': lambda: t.pitch(20), 22 | '&': lambda: t.pitch(-20), 23 | '>': lambda: t.roll(120), 24 | '<': lambda: t.roll(-120), 25 | '[': lambda: t.push(), 26 | ']': lambda: t.pop() 27 | } 28 | 29 | lsystem.lsystem(axiom,rules,dictionary,5) 30 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/squarecurve.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | import lsystem 6 | from mcturtle import * 7 | t = Turtle() 8 | t.pendelay(0) 9 | t.turtle(None) 10 | t.penblock(BRICK_BLOCK) 11 | t.gridalign() 12 | 13 | # http://mathforum.org/advanced/robertd/lsys2d.html 14 | rules = { 'X': 'XF-F+F-XF+F+XF-F+F-X' } 15 | 16 | def go(): 17 | t.startface() 18 | for i in range(4): 19 | t.go(4) 20 | t.pitch(90) 21 | t.endface() 22 | t.go(4) 23 | 24 | dictionary = { 25 | 'F': go, 26 | '+': lambda: t.yaw(90), 27 | '-': lambda: t.yaw(-90), 28 | } 29 | 30 | lsystem.lsystem('X', rules, dictionary, 4) 31 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/bridge.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | 6 | from mc import * 7 | import time 8 | import os 9 | 10 | mc = Minecraft() 11 | 12 | bridge = [] 13 | 14 | while True: 15 | pos = mc.player.getTilePos() 16 | pos.y = pos.y - 1 17 | belowBlock = mc.getBlock(pos) 18 | if belowBlock == AIR.id or belowBlock == WATER_FLOWING.id or belowBlock == WATER_STATIONARY.id: 19 | bridge.append(pos) 20 | mc.setBlock(pos, STAINED_GLASS_BLUE) 21 | if len(bridge) > 10: 22 | firstPos = bridge.pop(0) 23 | if not firstPos in bridge: 24 | mc.setBlock(firstPos, AIR) 25 | time.sleep(0.05) 26 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/glasscube.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | 7 | t = Turtle() 8 | t.turtle(None) 9 | t.pendelay(0) 10 | t.angle(0) # align to grid 11 | 12 | def face(): 13 | t.startface() 14 | for i in range(4): 15 | t.go(20) 16 | t.yaw(90) 17 | t.endface() 18 | 19 | t.penblock(GLASS) 20 | for i in range(2): 21 | face() 22 | t.roll(-90) 23 | face() 24 | t.roll(90) 25 | t.pitch(90) 26 | face() 27 | t.pitch(-90) 28 | t.penup() 29 | t.go(20) 30 | t.yaw(90) 31 | t.go(20) 32 | t.pitch(90) 33 | t.go(20) 34 | t.pitch(-90) 35 | t.yaw(90) 36 | t.pitch(-90) 37 | t.pendown() 38 | 39 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/nt7s_sphere.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # mcpipy.com retrieved from URL below, written by Jason Milldrum, NT7S 4 | # http://www.nt7s.com/blog/2013/02/exploring-minecraft-pi-edition/ 5 | 6 | 7 | import mcpi.minecraft as minecraft 8 | import mcpi.block as block 9 | import server 10 | 11 | 12 | mc = minecraft.Minecraft.create(server.address) 13 | 14 | radius = 8 15 | 16 | mc.postToChat("Hello, here's your sphere") 17 | 18 | playerPos = mc.player.getPos() 19 | 20 | for x in range(radius*-1,radius): 21 | for y in range(radius*-1, radius): 22 | for z in range(radius*-1,radius): 23 | if x**2 + y**2 + z**2 < radius**2: 24 | mc.setBlock(playerPos.x + x, playerPos.y + y + radius, playerPos.z - z - 10, block.GLASS) -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/knot.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | # 6 | # Draw a knot 7 | # 8 | 9 | from mc import * 10 | 11 | mc = Minecraft() 12 | playerPos = mc.player.getPos() 13 | scale = 10 14 | x0 = int(playerPos.x) 15 | y0 = int(playerPos.y+5*scale) 16 | z0 = int(playerPos.z) 17 | t = 0 18 | done = set() 19 | while t < 2*pi: 20 | # cinquefoil from http://www.maa.org/sites/default/files/images/upload_library/23/stemkoski/knots/page6.html 21 | x = x0+int( scale * cos(2*t) * (3 + cos(5*t)) ) 22 | y = y0+5*scale+int( scale * sin(2*t) * (3 + cos(5*t)) ) 23 | z = z0+int( scale * sin(5*t) ) 24 | if (x,y,z) not in done: 25 | mc.setBlock(x,y,z,GOLD_BLOCK) 26 | done.add((x,y,z)) 27 | t += 2*pi / 10000 28 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/util.py: -------------------------------------------------------------------------------- 1 | import collections 2 | import math 3 | 4 | def flatten(l): 5 | for e in l: 6 | if isinstance(e, collections.Iterable) and not isinstance(e, basestring): 7 | for ee in flatten(e): yield ee 8 | else: yield e 9 | 10 | # this is highly optimized to iterables consisting at base level of ints and floats only 11 | def floorFlatten(l): 12 | for e in l: 13 | if isinstance(e, int): 14 | yield str(e) 15 | elif isinstance(e, float): 16 | yield str(int(math.floor(e))) 17 | elif not e is None: 18 | for ee in floorFlatten(e): yield ee 19 | 20 | def flatten_parameters_to_string(l): 21 | return ",".join(map(str, flatten(l))) 22 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/zhuowei_rainbow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # mcpipy.com retrieved from URL below, written by zhuowei 5 | # http://www.minecraftforum.net/topic/1638036-my-first-script-for-minecraft-pi-api-a-rainbow/ 6 | 7 | import mcpi.minecraft as minecraft 8 | import mcpi.block as block 9 | from math import * 10 | import server 11 | 12 | colors = [14, 1, 4, 5, 3, 11, 10] 13 | 14 | mc = minecraft.Minecraft.create(server.address) 15 | height = 60 16 | 17 | mc.setBlocks(-64,0,0,64,height + len(colors),0,0) 18 | for x in range(0, 128): 19 | for colourindex in range(0, len(colors)): 20 | y = sin((x / 128.0) * pi) * height + colourindex 21 | mc.setBlock(x - 64, int(y), 0, block.WOOL.id, colors[len(colors) - 1 - colourindex]) -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/jemcruiser.txt: -------------------------------------------------------------------------------- 1 | file 'jemcruiser.3ds' 2 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/jemcruiser.3ds.gz 3 | swapyz 1 4 | credits Jemhadar Cruiser by William Burningham, 3DS conversion by Erik Timmermans. trekmeshes.ch. Star Trek is copyright Paramount Pictures. Non-commercial use only. 5 | yaw 180 6 | pitch 0 7 | roll 0 8 | size 100 9 | default WOOL_PURPLE 10 | order jh-blue-glow 1 11 | order blue-glow 1 12 | order blue-glow-rear 1 13 | materials 14 | jem'hadar-black WOOL_BLACK 15 | jem'hadar-drk WOOL_GRAY 16 | jem'hadar-grey1 WOOL_GRAY 17 | jem'hadar1 default 18 | jem'hadar2 default 19 | jem'hadar3 default 20 | jh-blue-glow SEA_LANTERN 21 | blue-glow SEA_LANTERN 22 | blue-glow-rear SEA_LANTERN 23 | end 24 | 25 | [Insert any detailed licensing information here] -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/yt1300.txt: -------------------------------------------------------------------------------- 1 | file 'yt1300.3ds' 2 | swapyz 1 3 | credits Model by MOJO courtesy of ROBOTFARM and scifi3d.com. Star Wars is copyright (c) Lucasfilm. Non-commercial use only. 4 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/yt1300.3ds.gz 5 | yaw 180 6 | pitch 0 7 | roll 0 8 | size 100 9 | default STONE 10 | order LIGHTS 2 11 | order GLASS 1 12 | materials 13 | LIGHTS SEA_LANTERN 14 | Default default 15 | HULL default 16 | SOLAR_PANALS default 17 | GUN default 18 | GLASS GLASS 19 | radar default 20 | Material_#13 default 21 | detail1 default 22 | end 23 | 24 | Star Wars is copyright (c) Lucasfilm. Non-commercial use only. 25 | 26 | Model courtesy of ROBOTFARM 27 | http://www.robotfarm.de/launch.html 28 | See the site for additional info. 29 | Main author of meshes: MOJO 30 | Downloaded from scifi3d.com -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/teleport.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | from random import * 7 | from time import * 8 | 9 | mc = Minecraft() 10 | pos = mc.player.getTilePos() 11 | 12 | goldPieces = 0 13 | 14 | while goldPieces < 10: 15 | x = pos.x + randint(-10,10) 16 | z = pos.z + randint(-10,10) 17 | if mc.getBlock(x,pos.y-1,z) != GOLD_BLOCK.id: 18 | mc.setBlock(x,pos.y-1,z,GOLD_BLOCK) 19 | goldPieces = goldPieces + 1 20 | 21 | startTime = time() 22 | while goldPieces > 0: 23 | pos = mc.player.getTilePos() 24 | if mc.getBlock(pos.x,pos.y - 1,pos.z) == GOLD_BLOCK.id: 25 | mc.setBlock(pos.x,pos.y - 1,pos.z,COBBLESTONE) 26 | mc.player.setPos(pos.x,pos.y + 5, pos.z) 27 | goldPieces = goldPieces - 1 28 | sleep(0.01) 29 | 30 | mc.postToChat("You took "+str(time()-startTime)+" seconds") 31 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/explosify.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import math 7 | import sys 8 | from ast import literal_eval 9 | 10 | def parseBlock(s): 11 | try: 12 | return literal_eval(s) 13 | except: 14 | return globals()[s.upper()] 15 | 16 | def replace(mcx,mcy,mcz,R,mcblock): 17 | for x in range(-R,R): 18 | for y in range(-R,R): 19 | for z in range(-R,R): 20 | if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != AIR.id): 21 | mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock) 22 | 23 | mc = Minecraft() 24 | 25 | playerPos = mc.player.getPos() 26 | R = 20 27 | b = TNT 28 | 29 | if len(sys.argv) >= 2: 30 | R = int(sys.argv[1]) 31 | if len(sys.argv) >= 3: 32 | b = parseBlock(sys.argv[2]) 33 | 34 | replace(playerPos.x, playerPos.y, playerPos.z, R, b) 35 | 36 | mc.postToChat("Explosify done") 37 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/hilbert.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | import lsystem 5 | from mcturtle import * 6 | from sys import argv 7 | t = Turtle() 8 | t.pendelay(0) 9 | t.turtle(None) 10 | t.gridalign() 11 | 12 | # Hilbert curve axiom and production rule by Stan Wagon, Mathematica in Action (chapter 6), W. H. Freeman and Co., 1991 13 | rules = { 'X': '^>XFX&F->>XFX+F>X+>' } 14 | 15 | count = 0 16 | 17 | def go(): 18 | global count 19 | # seven segments per basic unit 20 | if count % 7 == 0: 21 | t.penblock(Block(WOOL.id, (count/7)%16)) 22 | count += 1 23 | t.go(4) 24 | 25 | dictionary = { 26 | 'F': go, 27 | '+': lambda: t.yaw(90), 28 | '-': lambda: t.yaw(-90), 29 | '^': lambda: t.pitch(90), 30 | '&': lambda: t.pitch(-90), 31 | '>': lambda: t.roll(90), 32 | '<': lambda: t.roll(-90) 33 | } 34 | 35 | lsystem.lsystem('X', rules, dictionary, 3 if len(argv)<2 else int(argv[1])) 36 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/dragoncurve.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | import lsystem 7 | 8 | t = Turtle() 9 | t.pendelay(0) 10 | t.turtle(None) 11 | t.penblock(BRICK_BLOCK) 12 | # ensure angles are always integral multiples of 90 degrees 13 | t.gridalign() 14 | 15 | rules = {'X':'X+YF+', 'Y':'-FX-Y'} 16 | 17 | def go(): 18 | # draw a wall segment with a door 19 | t.pendown() 20 | t.penblock(BRICK_BLOCK) 21 | t.startface() 22 | for i in range(4): 23 | t.go(4) 24 | t.pitch(90) 25 | t.endface() 26 | t.penup() 27 | t.go(2) 28 | t.pendown() 29 | t.penblock(AIR) 30 | t.pitch(90) 31 | t.go(1) 32 | t.penup() 33 | t.pitch(180) 34 | t.go(1) 35 | t.pitch(90) 36 | t.go(2) 37 | 38 | dictionary = { '+': lambda: t.yaw(90), 39 | '-': lambda: t.yaw(-90), 40 | 'F': lambda: go() } 41 | lsystem.lsystem('FX', rules, dictionary, 14) 42 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/donut.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | # 6 | # Draw a water-filled donut 7 | # 8 | 9 | from mc import * 10 | 11 | def draw_donut(mcx,mcy,mcz,R,r,mcblock): 12 | for x in range(-R-r,R+r): 13 | for y in range(-R-r,R+r): 14 | xy_dist = sqrt(x**2 + y**2) 15 | if (xy_dist > 0): 16 | ringx = x / xy_dist * R # nearest point on major ring 17 | ringy = y / xy_dist * R 18 | ring_dist_sq = (x-ringx)**2 + (y-ringy)**2 19 | 20 | for z in range(-R-r,R+r): 21 | if (ring_dist_sq + z**2 <= r**2): 22 | mc.setBlock(mcx+x, mcy+z, mcz+y, mcblock) 23 | 24 | mc = Minecraft() 25 | 26 | playerPos = mc.player.getPos() 27 | 28 | draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 9, GLASS) 29 | mc.postToChat("Glass donut done") 30 | draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 6, WATER_STATIONARY) 31 | mc.postToChat("Water donut done") 32 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/fancytree.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mcturtle import * 6 | import random 7 | 8 | def tree(depth,thickness,branchLen): 9 | if depth <= 0: 10 | return 11 | if random.random() < 0.2: 12 | return 13 | if branchLen < 4: 14 | t.penblock(LEAVES_OAK_PERMANENT) 15 | else: 16 | t.penblock(WOOD) 17 | t.penwidth(thickness) 18 | t.go(branchLen) 19 | newThickness = thickness / 2 20 | if newThickness < 1: 21 | newThickness = 1 22 | newBranchLen = branchLen * 0.75 23 | if branchLen < 1: 24 | branchLen = 1 25 | for i in range(4): 26 | t.pitch(30) 27 | tree(depth-1,newThickness,newBranchLen) 28 | t.pitch(-30) 29 | t.roll(90) 30 | t.penup() 31 | t.back(branchLen) 32 | t.pendown() 33 | 34 | t = Turtle() 35 | t.turtle(None) 36 | t.pendelay(0) 37 | t.penup() 38 | t.go(10) 39 | t.verticalangle(90) 40 | t.pendown() 41 | tree(8,8,20) 42 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/trefoil.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Code under the MIT license by Alexander Pruss 5 | # 6 | 7 | # 8 | # Draw a trefoil 9 | # 10 | 11 | from mc import * 12 | 13 | def ball(x0,y0,z0,r,block_type,done): 14 | for x in range(-r,r): 15 | for y in range(-r,r): 16 | for z in range(-r,r): 17 | if (x**2 + y**2 + z**2 <= r**2): 18 | if not (x0+x,y0+y,z0+z) in done: 19 | mc.setBlock(x0+x,y0+y,z0+z,block_type) 20 | done.add((x0+x,y0+y,z0+z)) 21 | 22 | 23 | mc = Minecraft() 24 | playerPos = mc.player.getPos() 25 | 26 | scale = 12 27 | x0 = int(playerPos.x) 28 | y0 = int(playerPos.y + 3.5 * scale) 29 | z0 = int(playerPos.z) 30 | 31 | done = set() 32 | t = 0 33 | while t < 2*pi: 34 | # trefoil from http://en.wikipedia.org/wiki/Trefoil_knot 35 | x = x0+int( scale * (sin(t) + 2 * sin(2*t)) ) 36 | y = y0+int( scale * (cos(t) - 2 * cos(2*t)) ) 37 | z = z0+int( scale * -sin(3*t) ) 38 | ball(x,y,z,5,GOLD_BLOCK,done) 39 | t += 2*pi / 10000 40 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/brooksc_findpos.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #import the minecraft.py module from the minecraft directory 4 | import mcpi.minecraft as minecraft 5 | #import minecraft block module 6 | import mcpi.block as block 7 | #import time, so delays can be used 8 | import time 9 | import server 10 | 11 | if __name__ == "__main__": 12 | mc = minecraft.Minecraft.create(server.address) 13 | # mc.postToChat("Flattening surface") 14 | # mc.setBlocks(-128,0,-128,128,64,128,0) 15 | # mc.setBlocks(-128,0,-128,128,-64,128,block.SANDSTONE.id) 16 | # mc.postToChat("Putting a diamong block at 0,0,0") 17 | # mc.setBlock(0,0,0,block.DIAMOND_BLOCK.id) 18 | 19 | while True: 20 | #Find out your players position 21 | playerPos = mc.player.getPos() 22 | mc.postToChat("Find your position - its x=%s y=%s z=%s" % (int(playerPos.x), int(playerPos.y), int(playerPos.z))) 23 | # mc.postToChat("Find your position - its x=%.2f y=%.2f z=%.2f" % (playerPos.x, playerPos.y, playerPos.z)) 24 | time.sleep(1) 25 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/knot2.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | # 6 | # Draw a knot 7 | # 8 | 9 | from mc import * 10 | 11 | def ball(x0,y0,z0,r,block_type,done): 12 | for x in range(-r,r): 13 | for y in range(-r,r): 14 | for z in range(-r,r): 15 | if (x**2 + y**2 + z**2 <= r**2): 16 | if not (x0+x,y0+y,z0+z) in done: 17 | mc.setBlock(x0+x,y0+y,z0+z,block_type) 18 | done.add((x0+x,y0+y,z0+z)) 19 | 20 | mc = Minecraft() 21 | playerPos = mc.player.getPos() 22 | 23 | scale = 10 24 | x0 = int(playerPos.x) 25 | y0 = int(playerPos.y + 5*scale) 26 | z0 = int(playerPos.z) 27 | 28 | done = set() 29 | t = 0 30 | while t < 2*pi: 31 | # cinquefoil from http://www.maa.org/sites/default/files/images/upload_library/23/stemkoski/knots/page6.html 32 | x = playerPos.x+int( scale * cos(2*t) * (3 + cos(5*t)) ) 33 | y = playerPos.y+int( scale * sin(2*t) * (3 + cos(5*t)) ) 34 | z = playerPos.z+int( scale * sin(5*t) ) 35 | ball(x,y,z,4,GLOWSTONE_BLOCK,done) 36 | t += 2*pi / 10000 37 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/README.md: -------------------------------------------------------------------------------- 1 | mcpipy 2 | ====== 3 | 4 | Python scripts for controlling Minecraft Pi Edition on Raspberry Pi, as highlighted at mcpipy.com 5 | 6 | This is a collection of python scripts that can be used to control Minecraft Pi Edition running on Raspberry Pi, or alternatively on a CraftBukkit server using the RaspberryJuice plugin. 7 | 8 | Most (if not all) of the scripts are NOT of my own creation, but rather were created by others and collected to make it easy for others to enjoy them. The scripts are unmodified with a few exceptions: 9 | 10 | 1. A comment was added near the top of each file noting the author and original URL where it was posted. 11 | 2. The mcpi python libraries are assumed to be in the "mcpi" folder and require this as a prefix to import. As needed, scripts are updated to comply with this. 12 | 3. Minor formatting/bug fixing may be done to make the script run. 13 | 14 | Thanks to everyone who has written with the scripts and I hope you enjoy it! 15 | 16 | If you have questions or comments, email me at mcpipy at mcpipy.com or via twitter @mcpipy 17 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/server.py: -------------------------------------------------------------------------------- 1 | # this file is intended to be edited by the user running the script. 2 | # 3 | # by editing this file you can easily change whether the scripts are run from the local machine 4 | # that is, on the raspberry pi itself 5 | # or from another computer on the network 6 | # 7 | 8 | # if you are running the scripts on the raspberry pi, then set address to 127.0.0.1 9 | # 127.0.0.1 is a special address that means connect to the same machine I'm running this on 10 | # so this is useful when you are runnning the script and minecraft on the same machine 11 | address = "127.0.0.1" 12 | # If you are running the scripts on a machine other than the raspberry pi, then put the rasberry pi's 13 | # ip address here 14 | #address = "192.168.1.100" 15 | 16 | # If you are developing/testing against the RaspberyJuice Bukkit server, you may find that certain APIs are not 17 | # implemented like GetBlockWithData. 18 | # By setting the flag below to true or false, a script can use conditional logic on which features to use. 19 | # the default is set to True meaning the server is running Minecraft PI or on a Rasperbby PI. 20 | 21 | is_pi = False 22 | #is_pi = False -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpipy.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "mcpipy", "mcpipy.pyproj", "{AD0B690C-A698-4CE0-9B50-3069E7E8660D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7CD6D1CE-4B00-4E16-94F0-FB3BF4F0D6F8}" 9 | ProjectSection(SolutionItems) = preProject 10 | render.py = render.py 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {AD0B690C-A698-4CE0-9B50-3069E7E8660D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {AD0B690C-A698-4CE0-9B50-3069E7E8660D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/spiral.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import mcpi.minecraft as minecraft 4 | import mcpi.block as block 5 | import server 6 | import math 7 | 8 | def draw_horizontal_disc(cx, cy, cz, radius, block_type, meta): 9 | for x in range(-radius, radius): 10 | for z in range(-radius, radius): 11 | if (x**2 + z**2 <= radius**2): 12 | mc.setBlock(cx + x, cy, cz + z, block_type, meta) 13 | 14 | def draw_spiral(mcx,mcy,mcz,major_radius,minor_radius,height,period,phase,block_type,meta): 15 | for y in range(0,height - 1): 16 | theta = math.pi * 2 * y/period + phase 17 | circle_center_x = mcx + major_radius*math.cos(theta) 18 | circle_center_z = mcz + major_radius*math.sin(theta) 19 | draw_horizontal_disc(circle_center_x, mcy + y, circle_center_z, minor_radius, block_type, meta) 20 | 21 | mc = minecraft.Minecraft.create(server.address) 22 | 23 | playerPos = mc.player.getPos() 24 | 25 | draw_spiral(playerPos.x, playerPos.y, playerPos.z, 18, 10, 200, 30, 0, block.GOLD_BLOCK, 0) 26 | draw_spiral(playerPos.x, playerPos.y, playerPos.z, 18, 10, 200, 30, math.pi, block.GOLD_BLOCK, 0) 27 | mc.postToChat("Spiral done") 28 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcdragoncurve.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | import mcpi.minecraft as minecraft 6 | import mcpi.block as block 7 | import lsystem 8 | 9 | mc = minecraft.Minecraft() 10 | playerPos = mc.player.getPos() 11 | 12 | DIRECTIONS = ((1,0),(0,1),(-1,0),(0,-1)) 13 | 14 | pos = (int(playerPos.x),int(playerPos.y),int(playerPos.z)) 15 | direction = 0 16 | 17 | def go(): 18 | global pos 19 | dx = DIRECTIONS[direction][0] 20 | dz = DIRECTIONS[direction][1] 21 | # draw a wall 22 | mc.setBlocks(pos,pos[0]+dx*4,pos[1]+4,pos[2]+dz*4,block.BRICK_BLOCK) 23 | # draw a door in it 24 | mc.setBlocks(pos[0]+dx*2,pos[1],pos[2]+dz*2,pos[0]+dx*2,pos[1]+1,pos[2]+dz*2,block.AIR) 25 | pos = (pos[0]+dx*4, pos[1], pos[2]+dz*4) 26 | 27 | def left(): 28 | global direction 29 | direction -= 1 30 | if direction == -1: 31 | direction = 3 32 | 33 | def right(): 34 | global direction 35 | direction += 1 36 | if direction == 4: 37 | direction = 0 38 | 39 | rules = {'X':'X+YF+', 'Y':'-FX-Y'} 40 | dictionary = { '+': left, 41 | '-': right, 42 | 'F': go } 43 | 44 | lsystem.lsystem('FX', rules, dictionary, 14) 45 | 46 | #go() 47 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/console.py: -------------------------------------------------------------------------------- 1 | # 2 | # WARNING: If you're running RJM on a server, do NOT include this script server-side for security reasons. 3 | # 4 | 5 | # 6 | # Code under the MIT license by Alexander Pruss 7 | # 8 | # This script only works on Raspberry Jam 9 | # 10 | 11 | import mcpi.minecraft as minecraft 12 | import time 13 | from math import * 14 | from mcpi.block import * 15 | import code 16 | import sys 17 | 18 | 19 | def quit(): 20 | sys.exit() 21 | 22 | def inputLine(prompt): 23 | mc.events.clearAll() 24 | while True: 25 | chats = mc.events.pollChatPosts() 26 | for c in chats: 27 | if c.entityId == playerId: 28 | print c.message 29 | if c.message == 'quit': 30 | return 'quit()' 31 | elif c.message == ' ': 32 | return '' 33 | elif "__" in c.message: 34 | sys.exit(); 35 | else: 36 | return c.message 37 | time.sleep(0.2) 38 | 39 | mc = minecraft.Minecraft() 40 | playerPos = mc.player.getPos() 41 | playerId = mc.getPlayerId() 42 | 43 | mc.postToChat("Enter python code into chat, type 'quit' to quit.") 44 | i = code.interact(banner="Minecraft Python ready", readfunc=inputLine, local=locals()) 45 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mobius.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import sys 7 | 8 | def draw_surface(xf,yf,zf,a0,a1,asteps,b0,b1,bsteps,ox,oy,oz,scalex,scaley,scalez,mcblock,mcmeta): 9 | cfx = compile(xf,'','eval') 10 | cfy = compile(yf,'','eval') 11 | cfz = compile(zf,'','eval') 12 | 13 | for i in xrange(asteps): 14 | a = (a0 * (asteps-1-i) + a1 * i) / asteps 15 | for j in xrange(bsteps): 16 | b = (b0 * (bsteps-1-j) + b1 * j) / bsteps 17 | x = eval(cfx) 18 | y = eval(cfy) 19 | z = eval(cfz) 20 | # print a,b,ox+x * scalex, oy+y * scaley, oz+z * scalez 21 | mc.setBlock(ox+x * scalex, oy+y * scaley, oz+z * scalez, mcblock, mcmeta) 22 | 23 | mc = Minecraft() 24 | playerPos = mc.player.getPos() 25 | 26 | xformula = '(3 + a * cos(b/2)) * cos(b)' 27 | yformula = 'a * sin(b/2)' 28 | zformula = '(3 + a * cos(b/2)) * sin(b)' 29 | 30 | scale = 15 31 | 32 | b = STONE 33 | m = 0 34 | 35 | if (len(sys.argv)>1): 36 | b = int(sys.argv[1]) 37 | if (len(sys.argv)>2): 38 | m = int(sys.argv[2]) 39 | 40 | draw_surface(xformula,yformula,zformula,-1.,1.,10*scale,0,2*pi,30*scale,playerPos.x,playerPos.y+scale,playerPos.z,scale,scale,scale,b, m) 41 | mc.postToChat("Formula done") 42 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/turtleconsole.py: -------------------------------------------------------------------------------- 1 | # 2 | # WARNING: If you're running RJM on a server, do NOT include this script server-side for security reasons. 3 | # 4 | 5 | # 6 | # Code under the MIT license by Alexander Pruss 7 | # 8 | # 9 | # Requires Raspberry Jam 10 | # 11 | 12 | 13 | import mcpi.minecraft as minecraft 14 | import time 15 | from math import * 16 | from mcpi.block import * 17 | from mcturtle import * 18 | import code 19 | import sys 20 | 21 | def quit(): 22 | sys.exit() 23 | 24 | def inputLine(prompt): 25 | mc.events.clearAll() 26 | while True: 27 | chats = mc.events.pollChatPosts() 28 | for c in chats: 29 | if c.entityId == playerId: 30 | print c.message 31 | if c.message == 'quit': 32 | return 'quit()' 33 | elif c.message == ' ': 34 | return '' 35 | elif "__" in c.message: 36 | sys.exit(); 37 | else: 38 | return c.message 39 | time.sleep(0.2) 40 | 41 | mc = minecraft.Minecraft() 42 | playerPos = mc.player.getPos() 43 | playerId = mc.getPlayerId() 44 | t = Turtle(mc) 45 | 46 | mc.postToChat("Enter python code into chat, type 'quit' to quit.") 47 | i = code.interact(banner="", readfunc=inputLine, local=locals()) 48 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/digitalclock.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import text 7 | import datetime 8 | import time 9 | import sys 10 | import fonts 11 | import ast 12 | 13 | foreground = SEA_LANTERN # this needs Minecraft 1.8 14 | background = AIR 15 | 16 | def parseBlock(s): 17 | try: 18 | return ast.literal_eval(s) 19 | except: 20 | return globals()[s.upper()] 21 | 22 | try: 23 | foreground = parseBlock(sys.argv[1]) 24 | except: 25 | pass 26 | 27 | try: 28 | background = parseBlock(sys.argv[2]) 29 | except: 30 | pass 31 | 32 | mc = Minecraft() 33 | pos = mc.player.getTilePos() 34 | forward = text.angleToTextDirection(mc.player.getRotation()) 35 | 36 | prevTime = "" 37 | 38 | while True: 39 | curTime = datetime.datetime.now().strftime("%I:%M:%S %p") 40 | if curTime[0]=='0': 41 | curTime = ' ' + curTime[1:] 42 | if prevTime != curTime: 43 | for i in range(len(curTime)): 44 | if i >= len(prevTime) or prevTime[i] != curTime[i]: 45 | text.drawText(mc, fonts.FONTS['8x8'], pos + forward * (8*i), forward, Vec3(0,1,0), curTime[i:], foreground, background) 46 | break 47 | prevTime = curTime 48 | time.sleep(0.1) 49 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/neurosky.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import sys 7 | import time 8 | from NeuroPy.NeuroPy import NeuroPy 9 | 10 | mc = Minecraft() 11 | 12 | # 13 | # the True argument is needed for a BrainFlex unit hacked to work 14 | # at 57600 using 15 | # http://www.instructables.com/id/Mindflex-EEG-with-raw-data-over-Bluetooth/ 16 | # 17 | eeg = NeuroPy("COM11",57600,True) 18 | 19 | meditation = len(sys.argv) > 1 and sys.argv[1].startswith("m") 20 | 21 | up = 60 22 | down = 40 23 | 24 | def callback(a): 25 | mc.postToChat(a) 26 | if a > up: 27 | pos = mc.player.getPos() 28 | pos.y = pos.y + 1 29 | if mc.getBlock(pos.x,pos.y,pos.z) == AIR.id: 30 | mc.player.setPos(pos) 31 | elif a < down: 32 | pos = mc.player.getPos() 33 | pos.y = pos.y - 1 34 | if mc.getBlock(pos.x,pos.y,pos.z) == AIR.id: 35 | mc.player.setPos(pos) 36 | 37 | if meditation: 38 | eeg.setCallBack("meditation", callback) 39 | else: 40 | eeg.setCallBack("attention", callback) 41 | 42 | 43 | mc.postToChat("Connecting to EEG") 44 | eeg.start() 45 | 46 | if meditation: 47 | mc.postToChat("To fly up, be meditative") 48 | else: 49 | mc.postToChat("To fly up, be attentive") 50 | 51 | while True: 52 | time.sleep(10) 53 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/egg.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | import sys 3 | from ast import literal_eval 4 | 5 | def parseBlock(s): 6 | try: 7 | return literal_eval(s) 8 | except: 9 | return globals()[s.upper()] 10 | 11 | def egg(block=GOLD_BLOCK, h=40, a=2.5, b=1, c=0.1): 12 | for y in range(0,h+1): 13 | l = y / float(h) 14 | # Formula from: http://www.jolyon.co.uk/myresearch/image-analysis/egg-shape-modelling/ 15 | r = h*a*exp((-0.5*l*l+c*l-.5*c*c)/(b*b))*sqrt(1-l)*sqrt(l)/(pi*b) 16 | r2 = r*r 17 | for x in range(-h,h+1): 18 | for z in range(-h,h+1): 19 | myr2 = x*x + z*z 20 | if myr2 <= r2: 21 | if x==0 and z==0: 22 | theta = 0 23 | else: 24 | theta = atan2(z,x) 25 | yield (x,y,z,block,theta) 26 | 27 | mc = Minecraft() 28 | 29 | if len(sys.argv) >= 2: 30 | height = int(sys.argv[1]) 31 | else: 32 | height = 50 33 | 34 | if len(sys.argv) >= 3: 35 | material = parseBlock(sys.argv[2]) 36 | else: 37 | material = GOLD_BLOCK 38 | 39 | pos = mc.player.getPos() 40 | 41 | for (x,y,z,block,theta) in egg(h=height,block=material): 42 | mc.setBlock(x+pos.x,y+pos.y,z+pos.z,block) 43 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/trefoil2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Code under the MIT license by Alexander Pruss 5 | # 6 | 7 | # 8 | # Draw a trefoil filled with lava 9 | # 10 | 11 | from mc import * 12 | 13 | def ball(x0,y0,z0,r,block_type,done): 14 | for x in range(-r,r): 15 | for y in range(-r,r): 16 | for z in range(-r,r): 17 | if (x**2 + y**2 + z**2 <= r**2): 18 | if not (x0+x,y0+y,z0+z) in done: 19 | mc.setBlock(x0+x,y0+y,z0+z,block_type) 20 | done.add((x0+x,y0+y,z0+z)) 21 | 22 | 23 | mc = Minecraft() 24 | playerPos = mc.player.getPos() 25 | scale = 12 26 | 27 | x0 = int(playerPos.x) 28 | y0 = int(playerPos.y + 3.5 * scale) 29 | z0 = int(playerPos.z) 30 | 31 | t = 0 32 | done = set() 33 | while t < 2*pi: 34 | # trefoil from http://en.wikipedia.org/wiki/Trefoil_knot 35 | x = x0+int( scale * (sin(t) + 2 * sin(2*t)) ) 36 | y = y0+int( scale * (cos(t) - 2 * cos(2*t)) ) 37 | z = z0+int( scale * -sin(3*t) ) 38 | ball(x,y,z,5,GLASS,done) 39 | t += 2*pi / 10000 40 | 41 | t = 0 42 | done = set() 43 | while t < 2*pi: 44 | # trefoil from http://en.wikipedia.org/wiki/Trefoil_knot 45 | x = x0+int( scale * (sin(t) + 2 * sin(2*t)) ) 46 | y = y0+int( scale * (cos(t) - 2 * cos(2*t)) ) 47 | z = z0+int( scale * -sin(3*t) ) 48 | ball(x,y,z,3,LAVA_FLOWING,done) 49 | t += 2*pi / 10000 50 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/event.py: -------------------------------------------------------------------------------- 1 | from vec3 import Vec3 2 | 3 | class BlockEvent: 4 | """An Event related to blocks (e.g. placed, removed, hit)""" 5 | HIT = 0 6 | 7 | def __init__(self, type, x, y, z, face, entityId): 8 | self.type = type 9 | self.pos = Vec3(x, y, z) 10 | self.face = face 11 | self.entityId = entityId 12 | 13 | def __repr__(self): 14 | sType = { 15 | BlockEvent.HIT: "BlockEvent.HIT" 16 | }.get(self.type, "???") 17 | 18 | return "BlockEvent(%s, %d, %d, %d, %d, %d)"%( 19 | sType,self.pos.x,self.pos.y,self.pos.z,self.face,self.entityId); 20 | 21 | @staticmethod 22 | def Hit(x, y, z, face, entityId): 23 | return BlockEvent(BlockEvent.HIT, x, y, z, face, entityId) 24 | 25 | class ChatEvent: 26 | """An Event related to chat (e.g. posts)""" 27 | POST = 0 28 | 29 | def __init__(self, type, entityId, message): 30 | self.type = type 31 | self.entityId = entityId 32 | self.message = message 33 | 34 | def __repr__(self): 35 | sType = { 36 | ChatEvent.POST: "ChatEvent.POST" 37 | }.get(self.type, "???") 38 | 39 | return "ChatEvent(%s, %d, %s)"%( 40 | sType,self.entityId,self.message); 41 | 42 | @staticmethod 43 | def Post(entityId, message): 44 | return ChatEvent(ChatEvent.POST, entityId, message) 45 | 46 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/borromean.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | # 6 | # Draw Borromean rings 7 | # 8 | 9 | from mc import * 10 | 11 | def ball(x0,y0,z0,r,block_type,done): 12 | for x in range(-r,r): 13 | for y in range(-r,r): 14 | for z in range(-r,r): 15 | if (x**2 + y**2 + z**2 <= r**2): 16 | if not (x0+x,y0+y,z0+z) in done: 17 | mc.setBlock(x0+x,y0+y,z0+z,block_type) 18 | done.add((x0+x,y0+y,z0+z)) 19 | 20 | mc = Minecraft() 21 | playerPos = mc.player.getPos() 22 | 23 | scale = 30 24 | r = sqrt(3)/3 25 | 26 | 27 | x0 = int(playerPos.x) 28 | y0 = int(playerPos.y + 4 + (r/2+1) * scale) 29 | z0 = int(playerPos.z) 30 | 31 | 32 | # parametrization by I.J.McGee 33 | done = set() 34 | t = 0 35 | while t < 2*pi: 36 | x = x0+int( scale * cos(t) ) 37 | y = y0+int( scale * ( sin(t) + r) ) 38 | z = z0+int( scale * - cos(3*t)/3 ) 39 | ball(x,y,z,4,GOLD_BLOCK,done) 40 | t += 2*pi / 10000 41 | 42 | done = set() 43 | t = 0 44 | while t < 2*pi: 45 | x = x0+int( scale * (cos(t) + 0.5) ) 46 | y = y0+int( scale * ( sin(t) - r/2) ) 47 | z = z0+int( scale * - cos(3*t)/3 ) 48 | ball(x,y,z,4,LAPIS_LAZULI_BLOCK,done) 49 | t += 2*pi / 10000 50 | 51 | done = set() 52 | t = 0 53 | while t < 2*pi: 54 | x = x0+int( scale * ( cos(t) - 0.5 ) ) 55 | y = y0+int( scale * ( sin(t) - r/2) ) 56 | z = z0+int( scale * - cos(3*t)/3 ) 57 | ball(x,y,z,4,DIAMOND_BLOCK,done) 58 | t += 2*pi / 10000 59 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/klein.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import sys 7 | 8 | def draw_surface(xf,yf,zf,a0,a1,asteps,b0,b1,bsteps,ox,oy,oz,scalex,scaley,scalez,mcblock,mcmeta): 9 | cfx = compile(xf,'','eval') 10 | cfy = compile(yf,'','eval') 11 | cfz = compile(zf,'','eval') 12 | 13 | for i in xrange(asteps): 14 | a = (a0 * (asteps-1-i) + a1 * i) / asteps 15 | for j in xrange(bsteps): 16 | b = (b0 * (bsteps-1-j) + b1 * j) / bsteps 17 | x = eval(cfx) 18 | y = eval(cfy) 19 | z = eval(cfz) 20 | mc.setBlock(ox+x * scalex, oy+y * scaley, oz+z * scalez, mcblock, mcmeta) 21 | 22 | mc = Minecraft() 23 | playerPos = mc.player.getPos() 24 | 25 | # formula from http://paulbourke.net/geometry/klein/ 26 | 27 | xformula = '(6 * cos(a) * (1 + sin(a)) + 4 * (1 - cos(a) / 2) * cos(a) * cos(b)) if (a <= pi) else (6 * cos(a) * (1 + sin(a)) + 4 * (1 - cos(a) / 2) * cos(b + pi))' 28 | yformula = '16 * sin(a) + 4 * (1-cos(a)) * sin(a) * cos(b) if a <= pi else 16 * sin(a)' 29 | zformula = '4 * (1- cos(a)/2) * sin(b)' 30 | 31 | scale = 3 32 | 33 | b = STAINED_GLASS.id 34 | m = 5 35 | 36 | if (len(sys.argv)>1): 37 | b = int(sys.argv[1]) 38 | if (len(sys.argv)>2): 39 | m = int(sys.argv[2]) 40 | 41 | draw_surface(xformula,yformula,zformula,0,2*pi,150*scale,0,2*pi,150*scale,playerPos.x,playerPos.y+16*scale,playerPos.z,scale,scale,scale,b, m) 42 | #mc.postToChat("Formula done") 43 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/globe.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | 3 | def globe(center, radius=40, spacing_degrees=10, block=STAINED_GLASS_YELLOW): 4 | quality = int(radius * 2*pi * 2) 5 | 6 | # longitude lines 7 | longitude_degrees = 0 8 | while longitude_degrees < 360: 9 | theta = longitude_degrees * 2 * pi / 360 10 | xmult = radius * cos(theta) 11 | zmult = radius * sin(theta) 12 | for i in range(quality): 13 | phi = 2 * pi * i / quality 14 | y = radius * sin(phi) 15 | x = xmult * cos(phi) 16 | z = zmult * cos(phi) 17 | mc.setBlock(center[0]+x,center[1]+y,center[2]+z,block) 18 | longitude_degrees += spacing_degrees 19 | 20 | # latitude lines 21 | latitude_degrees = -90 22 | while latitude_degrees <= 90: 23 | phi = latitude_degrees * 2 * pi / 360 24 | y = radius * sin(phi) 25 | r = radius * cos(phi) 26 | for i in range(quality): 27 | theta = 2 * pi * i / quality 28 | x = r * cos(theta) 29 | z = r * sin(theta) 30 | mc.setBlock(center[0]+x,center[1]+y,center[2]+z,block) 31 | latitude_degrees += spacing_degrees 32 | 33 | if __name__ == "__main__": 34 | mc = Minecraft() 35 | center = mc.player.getPos() 36 | radius = 40 37 | globe((center.x,center.y+radius,center.z), radius-1, 360./(2*pi*2*radius), STAINED_GLASS_BLUE) 38 | globe((center.x,center.y+radius,center.z), radius, 10, STAINED_GLASS_YELLOW) 39 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/spacefill.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | import lsystem 6 | from mcturtle import * 7 | from sys import argv 8 | COLORS = (WOOL_WHITE,HARDENED_CLAY_STAINED_WHITE,WOOL_PINK,WOOL_MAGENTA,WOOL_PURPLE,HARDENED_CLAY_STAINED_LIGHT_BLUE,HARDENED_CLAY_STAINED_CYAN,HARDENED_CLAY_STAINED_PURPLE,HARDENED_CLAY_STAINED_LIGHT_GRAY,HARDENED_CLAY_STAINED_MAGENTA,HARDENED_CLAY_STAINED_PINK,HARDENED_CLAY_STAINED_RED,WOOL_RED,REDSTONE_BLOCK,HARDENED_CLAY_STAINED_ORANGE,WOOL_ORANGE,HARDENED_CLAY_STAINED_YELLOW,WOOL_YELLOW,WOOL_LIME,HARDENED_CLAY_STAINED_LIME,HARDENED_CLAY_STAINED_GREEN,WOOL_GREEN,HARDENED_CLAY_STAINED_GRAY,WOOL_BROWN,HARDENED_CLAY_STAINED_BROWN,WOOL_GRAY,HARDENED_CLAY_STAINED_BLUE,WOOL_BLUE,WOOL_CYAN,WOOL_LIGHT_BLUE,WOOL_LIGHT_GRAY) 9 | t = Turtle() 10 | t.pendelay(0) 11 | t.turtle(None) 12 | t.penblock(STAINED_GLASS_PURPLE) 13 | t.gridalign() 14 | 15 | # rules from 16 | # http://kanga.nu/~claw/blog/2008/11/16/game-design-tools/inkscape-l-systems-svg-penrose-and-other-tilings/ 17 | rules = { 'W': '+++X--F--ZFX+', 18 | 'X': '---W++F++YFW-', 19 | 'Y': '+ZFX--F--Z+++', 20 | 'Z': '-YFW++F++Y---', 21 | } 22 | axiom = 'W' 23 | 24 | colorIndex = 0 25 | def go(): 26 | global colorIndex 27 | t.penblock(COLORS[colorIndex % len(COLORS)]) 28 | colorIndex += 1 29 | t.go(6) 30 | 31 | 32 | 33 | dictionary = { 34 | 'F': go, 35 | '+': lambda: t.yaw(-30), 36 | '-': lambda: t.yaw(30), 37 | '[': lambda: t.push(), 38 | ']': lambda: t.pop() 39 | } 40 | 41 | lsystem.lsystem(axiom, rules, dictionary, 6) 42 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/shuttle.txt: -------------------------------------------------------------------------------- 1 | file shuttle.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/shuttle.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | swapyz 1 5 | size 100 6 | default WOOL 7 | materials 8 | glass GLASS 9 | bone WOOL 10 | fldkdkgrey WOOL.id 7 11 | redbrick WOOL.id 14 12 | black WOOL.id 15 13 | brass WOOL.id 1 14 | dkdkgrey WOOL.id 7 15 | end 16 | 17 | I do not know the credits for the .obj original mesh. 18 | 19 | License for material selection only: 20 | Copyright (c) Martin O'Hanlon 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of 23 | this software and associated documentation files (the "Software"), to deal in 24 | the Software without restriction, including without limitation the rights to 25 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 26 | of the Software, and to permit persons to whom the Software is furnished to do 27 | so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all 30 | copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 | SOFTWARE. 39 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/neghvar.txt: -------------------------------------------------------------------------------- 1 | file 'neghvar.3ds' 2 | swapyz 1 3 | credits Klingon Negh'Var Flagship by William Burningham, 3DS conversion by Erik Timmermans. trekmeshes.ch. Star Trek is copyright Paramount Pictures. Non-commercial use only. 4 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/neghvar.3ds.gz 5 | yaw 180 6 | pitch 0 7 | roll 0 8 | size 100 9 | default WOOL_GREEN 10 | order red-glow 1 11 | order warp-glow 1 12 | order window 1 13 | order flat-yelow 1 14 | materials 15 | default#1 default 16 | metal2 IRON_BLOCK 17 | negh'bar1 default 18 | negh'bar2 default 19 | negh'bar3 default 20 | negh'bar4 default 21 | negh'bar5 default 22 | negh'bar6 default 23 | dullred default 24 | flat-black WOOL_BLACK 25 | flat-yelow WOOL_YELLOW 26 | grey1 IRON_BLOCK 27 | gun-metal IRON_BLOCK 28 | main-hull default 29 | marker-light SEA_LANTERN 30 | metal3 IRON_BLOCK 31 | raised default 32 | red-glow STAINED_GLASS_RED 33 | warp-glow STAINED_GLASS_RED 34 | window SEA_LANTERN 35 | end 36 | 37 | Mesh history: 38 | 39 | Klingon Negh'Var LWO object by William Burningham. (http://www.burninghamstudios.com) 40 | 41 | Conversion from LWO to MAX by Erik Timmermans 42 | 43 | Texture conversion by Admiral Corrigan <> David Bishop 44 | 45 | Conversion to 3DS by Erik Timmermans 46 | 47 | You can get the textures for this mesh at the Star Trek Meshes Collection (http://trekmeshes.starfleet.ch) 48 | 49 | You'll have to rename shinimap2.jpg to shinimap.jpg 50 | 51 | Please credit the original author (William Burningham) and preferably David Bishop as well when you use this mesh. 52 | 53 | Erik Timmermans 54 | The Star Trek Meshes collection -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/entity.py: -------------------------------------------------------------------------------- 1 | ITEM = "Item" 2 | XPORB = "XPOrb" 3 | LEASHKNOT = "LeashKnot" 4 | PAINTING = "Painting" 5 | ARROW = "Arrow" 6 | SNOWBALL = "Snowball" 7 | FIREBALL = "Fireball" 8 | SMALLFIREBALL = "SmallFireball" 9 | THROWNENDERPEARL = "ThrownEnderpearl" 10 | EYEOFENDERSIGNAL = "EyeOfEnderSignal" 11 | THROWNPOTION = "ThrownPotion" 12 | THROWNEXPBOTTLE = "ThrownExpBottle" 13 | ITEMFRAME = "ItemFrame" 14 | WITHERSKULL = "WitherSkull" 15 | PRIMEDTNT = "PrimedTnt" 16 | FALLINGSAND = "FallingSand" 17 | FIREWORKSROCKETENTITY = "FireworksRocketEntity" 18 | ARMORSTAND = "ArmorStand" 19 | BOAT = "Boat" 20 | MINECARTRIDEABLE = "MinecartRideable" 21 | MINECARTCHEST = "MinecartChest" 22 | MINECARTFURNACE = "MinecartFurnace" 23 | MINECARTTNT = "MinecartTNT" 24 | MINECARTHOPPER = "MinecartHopper" 25 | MINECARTSPAWNER = "MinecartSpawner" 26 | MINECARTCOMMANDBLOCK = "MinecartCommandBlock" 27 | MOB = "Mob" 28 | MONSTER = "Monster" 29 | CREEPER = "Creeper" 30 | SKELETON = "Skeleton" 31 | SPIDER = "Spider" 32 | GIANT = "Giant" 33 | ZOMBIE = "Zombie" 34 | SLIME = "Slime" 35 | GHAST = "Ghast" 36 | PIGZOMBIE = "PigZombie" 37 | ENDERMAN = "Enderman" 38 | CAVESPIDER = "CaveSpider" 39 | SILVERFISH = "Silverfish" 40 | BLAZE = "Blaze" 41 | LAVASLIME = "LavaSlime" 42 | ENDERDRAGON = "EnderDragon" 43 | WITHERBOSS = "WitherBoss" 44 | BAT = "Bat" 45 | WITCH = "Witch" 46 | ENDERMITE = "Endermite" 47 | GUARDIAN = "Guardian" 48 | PIG = "Pig" 49 | SHEEP = "Sheep" 50 | COW = "Cow" 51 | CHICKEN = "Chicken" 52 | SQUID = "Squid" 53 | WOLF = "Wolf" 54 | MUSHROOMCOW = "MushroomCow" 55 | SNOWMAN = "SnowMan" 56 | OZELOT = "Ozelot" 57 | VILLAGERGOLEM = "VillagerGolem" 58 | HORSE = "EntityHorse" 59 | RABBIT = "Rabbit" 60 | VILLAGER = "Villager" 61 | ENDERCRYSTAL = "EnderCrystal" 62 | PLAYER = "(ThePlayer)" 63 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/stardestroyer.txt: -------------------------------------------------------------------------------- 1 | file stardestroyer.obj 2 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/stardestroyer.obj.gz 3 | swapyz 0 4 | size 200 5 | default IRON_BLOCK 6 | credits Model and Maps by Alex Lukachuk chimaera@club-internet.fr. Source: scifi3d.com. Star Wars is copyright (c) Lucasfilm. Noncommercial use only. 7 | 8 | materials 9 | sml_lights default 10 | wire_213154229 default 11 | wire_008061138 default 12 | wire_088177026 default 13 | wire_108008136 default 14 | wire_006134113 default 15 | wire_153228153 default 16 | wire_006134006 default 17 | wire_176026026 default 18 | wire_008008136 default 19 | Material__1 default 20 | wire_087224143 default 21 | sml_lights_3 default 22 | wire_087224198 default 23 | wire_088088225 default 24 | wire_214228153 default 25 | wire_166229229 default 26 | Lights_1a default 27 | wire_154154229 default 28 | wire_229166215 default 29 | wire_224198087 default 30 | sml_lights_2 default 31 | wire_177028149 default 32 | wire_061134006 default 33 | wire_006134058 default 34 | wire_177148026 default 35 | wire_196088225 default 36 | wire_229154215 default 37 | wire_153228214 default 38 | wire_028149177 default 39 | wire_224086086 default 40 | wire_057008136 default 41 | wire_134059008 default 42 | wire_177088026 default 43 | wire_228153184 default 44 | wire_148177026 default 45 | wire_198224087 default 46 | wire_138008110 default 47 | wire_228214153 default 48 | wire_134110008 default 49 | wire_088143225 default 50 | wire_227152152 default 51 | wire_026177148 default 52 | wire_177026088 default 53 | wire_000169000 default 54 | wire_028028177 default 55 | wire_134006006 default 56 | wire_154185229 default 57 | wire_255000112 default 58 | wire_141007058 default 59 | wire_228184153 default 60 | wire_153228184 default 61 | wire_236255169 default 62 | wire_000083055 default 63 | wire_255255169 default 64 | wire_169000000 default 65 | end 66 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/gf_drawbuilding.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python 2 | import mcpi.minecraft as minecraft 3 | import mcpi.block as block 4 | import server 5 | import random 6 | 7 | """ draw a building 8 | 9 | @author: goldfish""" 10 | 11 | def drawBuilding( locx, locy, locz, floors, width, depth, floorheight, wallmaterial, floormaterial ): 12 | topx = locx+width 13 | topy = locy+((floorheight+1)*floors) 14 | topz = locz+depth 15 | #draw building shell 16 | mc.setBlocks( locx, locy, locz, topx, topy, topz, wallmaterial ) 17 | mc.setBlocks( locx+1, locy+1, locz+1, topx-1, topy-1, topz-1, block.AIR ) 18 | #draw floors 19 | if( floors > 1 ): 20 | for i in range( floors -1 ): 21 | floorYloc = locy+( (floorheight+1)*(i+1) ) 22 | mc.setBlocks( locx+1, floorYloc, locz+1, topx-1, floorYloc, topz-1, floormaterial ) 23 | #draw door 24 | doorloc = random.randint( 1, width-2 ) 25 | mc.setBlock( locx, locy+1, locz+doorloc, block.AIR ) 26 | mc.setBlock( locx, locy+2, locz+doorloc, block.AIR ) 27 | #draw front windows 28 | if( floors > 1 ): 29 | for i in range( floors-1 ): 30 | windowYloc = locy+2+( (floorheight+1)*(i+1) ) 31 | for j in range( floorheight-1 ): 32 | mc.setBlocks( locx, windowYloc+j , locz+1, locx, windowYloc+j, locz+(width-1), block.GLASS_PANE ) 33 | #draw back windows 34 | if( floors > 1 ): 35 | for i in range( floors-1 ): 36 | windowYloc = locy+2+( (floorheight+1)*(i+1) ) 37 | for j in range( floorheight-1 ): 38 | mc.setBlocks( locx+depth, windowYloc+j , locz+1, locx+depth, windowYloc+j, locz+(width-1), block.GLASS_PANE ) 39 | #connect levels with ladder 40 | #mc.setBlocks( topx-1, locy+1, topz-1, topx-1, topy-1, topz-1, block.LADDER ) 41 | 42 | if __name__ == "__main__": 43 | mc = minecraft.Minecraft.create( server.address ) 44 | drawBuilding( 0, 0, 0, 5, 5, 5, 3, block.STONE, block.WOOD_PLANKS ) 45 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/RaspberryPi.txt: -------------------------------------------------------------------------------- 1 | file RaspberryPi.obj 2 | swapyz 0 3 | size 100 4 | default DIRT 5 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/RaspberryPi.obj 6 | credits Downloaded from Martin O'Hanlon's repository 7 | materials 8 | Default_Material WOOL.id 0 9 | Material1 WOOL.id 5 10 | Goldenrod WOOL.id 1 11 | 0136_Charcoal WOOL.id 7 12 | Gray61 WOOL.id 7 13 | Charcoal WOOL.id 7 14 | Color_002 WOOL.id 8 15 | Color_008 WOOL.id 4 16 | Plastic_Green WOOL.id 5 17 | MB_Pastic_White WOOL.id 0 18 | IO_Shiny IRON_BLOCK 19 | Material4 GRASS 20 | Gainsboro3 WOOL.id 5 21 | CorrogateShiny1 IRON_BLOCK 22 | Gold GOLD_BLOCK 23 | 0129_WhiteSmoke WOOL 24 | Color_005 WOOL 25 | USB_IO WOOL.id 11 26 | _Metal IRON_BLOCK 27 | 0132_LightGray WOOL.id 8 28 | 29 | end 30 | I do not know the credits for the .obj original mesh. 31 | 32 | License for material selection only: 33 | Copyright (c) Martin O'Hanlon 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy of 36 | this software and associated documentation files (the "Software"), to deal in 37 | the Software without restriction, including without limitation the rights to 38 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 39 | of the Software, and to permit persons to whom the Software is furnished to do 40 | so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in all 43 | copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 51 | SOFTWARE. 52 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/mcpi_protocol_spec.txt: -------------------------------------------------------------------------------- 1 | MCPI-PROTOCOL 0.1 2 | 3 | OVERVIEW 4 | The mcpi-protocol enables an external process (program) to interact with a 5 | running instance of Minecraft Pi Edition. 6 | 7 | The protocol can easily be implemented and used from any programming language 8 | that has network socket support. The mcpi release includes api libraries (with 9 | source) for Python and Java. 10 | 11 | * Tcp-socket, port 4711 12 | * Commands are clear text lines (ASCII, LF terminated) 13 | 14 | 15 | DEFINITIONS 16 | x,y,z -- vector of three integers. 17 | xf,yf,zf -- vector of three floats. 18 | blockTypeId -- integer 0-108. 0 is air. 19 | blockData -- integer 0-15. Block data beyond the type, for example wool color. 20 | 21 | See: http://www.minecraftwiki.net/wiki/Data_values_(Pocket_Edition) 22 | 23 | 24 | COORDINATE SYSTEM 25 | Most coordinates are in the form of a three integer vector (x,y,z) which 26 | address a specific tile in the game world. (0,0,0) is the spawn point sea 27 | level. (X,Z) is the ground plane and Y is towards the sky. 28 | 29 | 30 | COMMANDS 31 | -- World -- 32 | world.getBlock(x,y,z) --> blockTypeId 33 | 34 | world.setBlock(x,y,z,blockTypeId) 35 | world.setBlock(x,y,z,blockTypeId,blockData) 36 | 37 | world.setBlocks(x1,y1,z1,x2,y2,z2,blockTypeId) 38 | world.setBlocks(x1,y1,z1,x2,y2,z2,blockTypeId,blockData) 39 | 40 | world.getHeight(x,z) --> Integer 41 | 42 | world.checkpoint.save() 43 | world.checkpoint.restore() 44 | 45 | TODO: skriva ut KEYs 46 | world.setting(KEY,0/1) 47 | 48 | chat.post(message) 49 | 50 | -- Camera -- 51 | camera.mode.setNormal() 52 | camera.mode.setThirdPerson() 53 | camera.mode.setFixed() 54 | camera.mode.setPos(x,y,z) 55 | 56 | -- Player -- 57 | player.getTile() --> x,y,z 58 | player.setTile(x,y,z) 59 | 60 | player.getPos() --> xf,yf,zf 61 | player.setPos(xf,yf,zf) 62 | 63 | -- Entities -- 64 | TBD 65 | 66 | 67 | -- Events -- 68 | events.block.hits() --> pos,surface,entityId|pos,surface,entityId|... (pos is x,y,z surface is x,y,z, entityId is int) 69 | events.clear 70 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/fleap_railgen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #import the minecraft.py module from the minecraft directory 4 | import mcpi.minecraft as minecraft 5 | #import minecraft block module 6 | import mcpi.block as block 7 | #import time, so delays can be used 8 | import server 9 | 10 | def main(): 11 | mc = minecraft.Minecraft.create(server.address) 12 | # an abbrieviated flatmap 13 | # mc.setBlocks(-50,-10,-50,50,10,50,block.AIR.id) 14 | # mc.setBlocks(-50,0,-50,50,-10,50,block.SANDSTONE.id) 15 | # The original flatmap 16 | mc.setBlocks(-128,0,-128,128,64,128,0) 17 | mc.setBlocks(-128,0,-128,128,-64,128,block.SANDSTONE.id) 18 | 19 | # exit() 20 | mc.postToChat("Hello you have successfully ran Rail Gen :).") 21 | # create the station 22 | mc.setBlock(1,3,0,block.GLOWSTONE_BLOCK.id) 23 | mc.setBlock(0,0,0,block.STONE_SLAB.id) 24 | mc.setBlock(-1,1,0,block.DOOR_WOOD.id,0) 25 | mc.setBlock(-1,2,0,block.DOOR_WOOD.id,8) 26 | mc.setBlock(0,1,1,block.STONE.id) 27 | mc.setBlock(0,2,1,block.STONE.id) 28 | mc.setBlock(0,1,-1,block.STONE.id) 29 | mc.setBlock(0,2,-1,block.STONE.id) 30 | mc.setBlock(1,1,1,block.STONE.id) 31 | mc.setBlock(-1,1,1,block.STONE.id) 32 | mc.setBlock(0,1,1,block.STONE.id) 33 | mc.setBlock(1,1,-1,block.STONE.id) 34 | mc.setBlock(-1,1,-1,block.STONE.id) 35 | mc.setBlock(-1,2,-1,block.GLOWSTONE_BLOCK.id) 36 | mc.setBlock(1,2,-1,block.STONE.id) 37 | mc.setBlock(1,2,1,block.STONE.id) 38 | mc.setBlock(-1,2,1,block.GLOWSTONE_BLOCK.id) 39 | mc.setBlock(-1,3,0,block.STONE_SLAB.id) 40 | mc.setBlock(0,3,0,block.STONE_SLAB.id) 41 | # Create the path one direction 42 | mc.setBlocks(129,0,1,0,0,-1,block.STONE_SLAB) 43 | mc.setBlocks(0,1,2,128,1,2,block.STONE.id) 44 | mc.setBlocks(128,1,-2,0,1,-2,block.STONE.id) 45 | mc.setBlocks(128,0,2,0,0,2,block.GLOWSTONE_BLOCK.id) 46 | mc.setBlocks(128,0,-2,0,0,-2,block.GLOWSTONE_BLOCK.id) 47 | 48 | 49 | 50 | 51 | 52 | if __name__ == "__main__": 53 | main() -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/City_Ground-Notts.txt: -------------------------------------------------------------------------------- 1 | file City_Ground-Notts.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/City_Ground-Notts.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | size 200 5 | default DIRT 6 | materials 7 | Default_Material STONE.id 8 | Black WOOL.id 15 9 | Asphalt_Old WOOL.id 7 10 | GhostWhite WOOL 11 | Brick_Flemish_Bond BRICK_BLOCK 12 | Concrete_Brushed STONE.id 13 | Metal_Brushed IRON_BLOCK 14 | Roofing_Metal_Standing_Seam_Blue WOOL.id 8 15 | White WOOL 16 | Metal_Brushed1 IRON_BLOCK 17 | Rouge3141 WOOL.id 14 18 | roof WOOL.id 8 19 | Metal_Aluminum_Anodized IRON_BLOCK 20 | Translucent_Glass_Safety GLASS.id 21 | Translucent_Glass_Safety1 GLASS.id 22 | Safety_Glass2 GLASS.id 23 | Red WOOL.id 14 24 | goal_net1 WOOL 25 | Black WOOL.id 15 26 | 27 | end 28 | I do not know the credits for the .obj original mesh. 29 | 30 | License for material selection only: 31 | Copyright (c) Martin O'Hanlon 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy of 34 | this software and associated documentation files (the "Software"), to deal in 35 | the Software without restriction, including without limitation the rights to 36 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 37 | of the Software, and to permit persons to whom the Software is furnished to do 38 | so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all 41 | copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 49 | SOFTWARE. 50 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/clock.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from drawing import * 6 | import time 7 | 8 | d = Drawing() 9 | 10 | class Hand: 11 | def __init__(self, center, scale, length, width, material, backMaterial): 12 | self.center = center 13 | self.length = length 14 | self.width = width 15 | self.scale = scale 16 | self.previousValue = None 17 | self.material = material 18 | self.backMaterial = backMaterial 19 | 20 | def update(self, value): 21 | d.penwidth(self.width) 22 | if self.previousValue != None and self.previousValue != value: 23 | self.drawLine(self.previousValue, self.backMaterial) 24 | self.drawLine(value, self.material) 25 | self.previousValue = value 26 | 27 | def drawLine(self, value, block): 28 | angle = pi / 2 - (value % self.scale) * 2 * pi / self.scale 29 | d.line(self.center[0],self.center[1],self.center[2], 30 | self.center[0] + self.length * cos(angle), 31 | self.center[1] + self.length * sin(angle), 32 | self.center[2], block) 33 | 34 | radius = 20 35 | 36 | playerPos = d.mc.player.getPos(); 37 | 38 | center = (playerPos.x, playerPos.y + radius, playerPos.z - radius) 39 | 40 | for x in range(-radius, radius+1): 41 | for y in range(-radius, radius+1): 42 | if x**2+y**2 <= radius**2: 43 | d.point(center[0]+x, center[1]+y, center[2]-3, WOOL_BLACK) 44 | 45 | d.penwidth(1) 46 | for tick in range(0,12): 47 | d.line(center[0]+0.85*radius*cos(tick * 2 * pi / 12),center[1]+0.85*radius*sin(tick * 2 * pi / 12), center[2]-3, 48 | center[0]+radius*cos(tick * 2 * pi / 12),center[1]+radius*sin(tick * 2 * pi / 12), center[2]-3, 49 | WOOL_BLUE) 50 | 51 | hourHand = Hand(center, 12, radius * 0.5, 3, GOLD_BLOCK, AIR) 52 | minuteHand = Hand(center, 60, radius * 0.8, 2, GOLD_BLOCK, AIR) 53 | secondHand = Hand((center[0],center[1],center[2]+1), 60, radius * 0.8, 1, WOOL_RED, AIR) 54 | 55 | while True: 56 | t = time.localtime() 57 | hourHand.update(t[3]) 58 | minuteHand.update(t[4]) 59 | secondHand.update(t[5]) 60 | time.sleep(1) 61 | 62 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/NY_LIL.txt: -------------------------------------------------------------------------------- 1 | obj NY_LIL.obj 2 | url https://raw.githubusercontent.com/martinohanlon/minecraft-renderObj/master/NY_LIL.obj 3 | credits Downloaded from Martin O'Hanlon's repository 4 | swapyz 0 5 | size 200 6 | default IRON_BLOCK 7 | materials 8 | Default_Material WOOL.id 0 9 | Color_A01 WOOL.id 14 10 | 0131_Silver IRON_BLOCK 11 | 0075_ForestGreen WOOL.id 13 12 | 0137_Black WOOL.id 15 13 | Black WOOL.id 15 14 | Medium_Brown WOOL.id 12 15 | 0056_Yellow WOOL.id 4 16 | 0020_Red WOOL.id 14 17 | 0102_RoyalBlue WOOL.id 11 18 | Color_E01 WOOL.id 4 19 | Color_E02 WOOL.id 4 20 | Color_B01 WOOL.id 1 21 | Charcoal WOOL.id 7 22 | Material2 WOOL.id 0 23 | Beige2 SANDSTONE 24 | DarkGoldenrod GOLD_BLOCK 25 | Beige1 SANDSTONE 26 | jean_blue WOOL.id 3 27 | Gold1 GOLD_BLOCK 28 | WhiteSmoke WOOL.id 8 29 | 0118_Thistle WOOL.id 6 30 | Color_D23 WOOL.id 7 31 | Color_B23 WOOL.id 12 32 | Color_009 WOOL.id 15 33 | Color_D01 WOOL.id 1 34 | Color_A06 WOOL.id 14 35 | Color_D03 WOOL.id 4 36 | 0063_GreenYellow WOOL.id 5 37 | 38 | end 39 | I do not know the credits for the .obj original mesh. 40 | 41 | License for material selection only: 42 | Copyright (c) Martin O'Hanlon 43 | 44 | Permission is hereby granted, free of charge, to any person obtaining a copy of 45 | this software and associated documentation files (the "Software"), to deal in 46 | the Software without restriction, including without limitation the rights to 47 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 48 | of the Software, and to permit persons to whom the Software is furnished to do 49 | so, subject to the following conditions: 50 | 51 | The above copyright notice and this permission notice shall be included in all 52 | copies or substantial portions of the Software. 53 | 54 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 60 | SOFTWARE. 61 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/win32move.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | from time import sleep 3 | from sys import argv 4 | import input 5 | 6 | mc = Minecraft() 7 | 8 | player = True 9 | 10 | if len(argv)>=2 and argv[1] != "me": 11 | playerPos = mc.player.getPos() 12 | playerYaw = mc.player.getRotation() 13 | entity = mc.spawnEntity(argv[1], playerPos.x - sin(radians(playerYaw)), playerPos.z, 14 | playerPos.z + cos(radians(playerYaw)), "{NoAI:1}") 15 | player = False 16 | else: 17 | entity = mc.getPlayerId() 18 | 19 | lastPlatform = None 20 | lastPlatformBlock = None 21 | 22 | UNSOLID = set([WATER_FLOWING.id,WATER_STATIONARY.id,AIR.id,LAVA_FLOWING.id,LAVA_STATIONARY.id]) 23 | 24 | while True: 25 | pos = mc.entity.getPos(entity) 26 | yaw = mc.entity.getRotation(entity) 27 | move = False 28 | if input.wasPressedSinceLast(input.NEXT): 29 | pos.y -= 1 30 | move = True 31 | if input.wasPressedSinceLast(input.PRIOR): 32 | pos.y += 1 33 | move = True 34 | if input.wasPressedSinceLast(input.LEFT): 35 | yaw -= 15 36 | mc.entity.setRotation(entity,yaw) 37 | if input.wasPressedSinceLast(input.RIGHT): 38 | yaw += 15 39 | mc.entity.setRotation(entity,yaw) 40 | if input.wasPressedSinceLast(input.UP): 41 | pos.x += .5 * -sin(radians(yaw)) 42 | pos.z += .5 * cos(radians(yaw)) 43 | move = True 44 | if input.wasPressedSinceLast(input.DOWN): 45 | pos.x -= .5 * -sin(radians(yaw)) 46 | pos.z -= .5 * cos(radians(yaw)) 47 | move = True 48 | if move: 49 | if player: 50 | under = (int(floor(pos.x)),int(floor(pos.y))-1,int(floor(pos.z))) 51 | block = mc.getBlock(under) 52 | if block in UNSOLID: 53 | drew = under 54 | mc.setBlock(drew,GLASS) 55 | else: 56 | drew = None 57 | mc.entity.setPos(entity,pos) 58 | if lastPlatform is not None and lastPlatform != under: 59 | mc.setBlock(lastPlatform,AIR) 60 | lastPlatform = None 61 | if drew: 62 | lastPlatform = drew 63 | lastPlatformBlock = block 64 | else: 65 | mc.entity.setPos(entity,pos) 66 | sleep(0.2) 67 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mengersponge.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | # mengersponge [levels [options]] 5 | # levels is a level count, up to 5 6 | # options is a string of characters containing possibly the options 's' for 'slice' (cut off a diagonal slice) and 'c' for 'color' 7 | # 8 | from mc import * 9 | import mcpi.settings as settings 10 | import sys 11 | 12 | RAINBOW = (STAINED_GLASS_RED,STAINED_GLASS_ORANGE,STAINED_GLASS_YELLOW,STAINED_GLASS_GREEN,STAINED_GLASS_BLUE,STAINED_GLASS_PURPLE) 13 | 14 | def deleteCubes(x0,y0,z0,length,colorIndex=None): 15 | nextColorIndex = colorIndex + 1 if colorIndex is not None else None 16 | length /= 3 17 | if length < 1: 18 | return 19 | for x in range(3): 20 | for y in range(3): 21 | for z in range(3): 22 | posX = x0+x*length 23 | posY = y0+y*length 24 | posZ = z0+z*length 25 | if (x == 1 and y == 1) or (x == 1 and z == 1) or (y == 1 and z == 1): 26 | if colorIndex is not None: 27 | mc.setBlocks(posX,posY,posZ, 28 | posX+length-1,posY+length-1,posZ+length-1,RAINBOW[colorIndex]) 29 | else: 30 | mc.setBlocks(posX,posY,posZ, 31 | posX+length-1,posY+length-1,posZ+length-1,AIR) 32 | else: 33 | deleteCubes(posX,posY,posZ,length,nextColorIndex) 34 | 35 | def slice(x0,y0,z0,length): 36 | for x in range(0,length): 37 | for y in range(0,length): 38 | for z in range(0,length): 39 | if x+y+z >= 1.5*length: 40 | mc.setBlock(x0+x,y0+y,z0+z,AIR) 41 | 42 | mc = Minecraft() 43 | playerPos = mc.player.getPos() 44 | if settings.isPE: 45 | length = 3*3*3 46 | else: 47 | length = 3*3*3*3 48 | if len(sys.argv) > 1: 49 | length = 3**int(sys.argv[1]) 50 | colorIndex = None 51 | if len(sys.argv) > 2: 52 | colorIndex = 0 if 'c' in sys.argv[2] else None 53 | mc.setBlocks(playerPos.x,playerPos.y,playerPos.z, 54 | playerPos.x+length-1,playerPos.y+length-1,playerPos.z+length-1,WOOL_PURPLE) 55 | deleteCubes(playerPos.x,playerPos.y,playerPos.z,length,colorIndex=colorIndex) 56 | if len(sys.argv)>2 and 's' in sys.argv[2]: 57 | mc.postToChat("Slicing") 58 | slice(playerPos.x,playerPos.y,playerPos.z,length) 59 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/bop.txt: -------------------------------------------------------------------------------- 1 | file 'bop.3ds' 2 | swapyz 1 3 | credits Klingon Bird of Prey by William Burningham, 3DS conversion by Erik Timmermans. trekmeshes.ch. Star Trek is copyright Paramount Pictures. Non-commercial use only. 4 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/bop.3ds.gz 5 | yaw 180 6 | pitch 0 7 | roll 0 8 | size 100 9 | default WOOL_GREEN 10 | order photon-red 1 11 | order photon-red2 1 12 | order marker-light_#2 1 13 | order wht-light_#2 1 14 | order marker-light 1 15 | order red-glow 1 16 | order red-windo-glow 1 17 | order red-window 1 18 | order wht-light 1 19 | order yellow-glow 1 20 | 21 | materials 22 | inner-cooler-2_# default 23 | radiator1_#2 default 24 | radiator2_#2 default 25 | Metal2_#4 default 26 | bop-green_#4 default 27 | bop-green3_#4 default 28 | bop-green4_#4 default 29 | bop-green5_#4 default 30 | metal3_#4 default 31 | photon-red STAINED_GLASS_RED 32 | photon-red2 STAINED_GLASS_RED 33 | rust_#4 default 34 | BOP-flat-red WOOL_RED 35 | BOP-flat-red1 WOOL_RED 36 | Metal2_#3 default 37 | bop-cut default 38 | bop-green_#3 default 39 | bop-green2_#3 default 40 | bop-green3_#3 default 41 | bop-green4_#3 default 42 | bop-green5_#3 default 43 | cut-2 default 44 | gun-metal_#3 IRON_BLOCK 45 | inner-cooler-2 default 46 | inner-cooler1 default 47 | inner-cooler3 default 48 | metal3_#3 IRON_BLOCK 49 | radiator1 default 50 | radiator2 default 51 | red-glow_#2 default 52 | rust_#3 default 53 | vent-grey IRON_BLOCK 54 | wing-rear-edge default 55 | Metal2_#2 IRON_BLOCK 56 | black WOOL_BLACK 57 | bop-green_#2 default 58 | bop-green2_#2 default 59 | bop-green3_#2 default 60 | bop-green4_#2 default 61 | bop-green5_#2 default 62 | gun-metal_#2 default 63 | marker-light_#2 SEA_LANTERN 64 | metal3_#2 IRON_BLOCK 65 | rust_#2 default 66 | wht-light_#2 SEA_LANTERN 67 | Metal2 IRON_BLOCK 68 | bop-green default 69 | bop-green2 default 70 | bop-green3 default 71 | bop-green4 default 72 | bop-green5 default 73 | flat-blk default 74 | gun-metal IRON_BLOCK 75 | gunshipgry IRON_BLOCK 76 | gunshipgry2 IRON_BLOCK 77 | lt-grey IRON_BLOCK 78 | marker-light SEA_LANTERN 79 | metal3 default 80 | red-glow STAINED_GLASS_RED 81 | red-windo-glow STAINED_GLASS_RED 82 | red-window STAINED_GLASS_RED 83 | rust default 84 | sidegrn default 85 | sidegrncut default 86 | wht-light SEA_LANTERN 87 | yellow-glow STAINED_GLASS_YELLOW 88 | end 89 | 90 | [Insert any detailed licensing information here] -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/sierpinski3d.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import drawing 7 | from sys import argv 8 | import mcpi.settings as settings 9 | import ast 10 | 11 | RAINBOW = (WOOL_RED,WOOL_PINK,WOOL_ORANGE,WOOL_YELLOW,WOOL_GREEN,WOOL_BLUE,WOOL_LIGHT_BLUE,WOOL_PURPLE) 12 | 13 | TAN30 = sqrt(3.)/3 14 | SQRT32 = sqrt(3./2) 15 | 16 | def parseBlock(s): 17 | try: 18 | return ast.literal_eval(s) 19 | except: 20 | return globals()[s.upper()] 21 | 22 | def distance(a,b): 23 | return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2) 24 | 25 | def tetrahedronBottom(height, apex): 26 | side = SQRT32*height 27 | return ( (apex[0]-0.5*TAN30*side,apex[1]-height,apex[2]-0.5*side), 28 | (apex[0]-0.5*TAN30*side,apex[1]-height,apex[2]+0.5*side), 29 | (apex[0]+TAN30*side,apex[1]-height,apex[2]) ) 30 | 31 | def drawTetrahedron(height, apex, block): 32 | bottom = tetrahedronBottom(height, apex) 33 | for i in range(int(round(height))+1): 34 | triangle = [] 35 | for point in bottom: 36 | a = float(i)/height 37 | triangle.append(((1-a)*apex[0]+a*point[0],apex[1]-i,(1-a)*apex[2]+a*point[2])) 38 | d.face(triangle,block) 39 | return triangle 40 | 41 | def average(a,b): 42 | return tuple(0.5*(a[i]+b[i]) for i in range(len(a))) 43 | 44 | def transform(tet): 45 | level, height, apex = tet[0],tet[1],tet[2] 46 | bottom = tetrahedronBottom(height,apex) 47 | yield (level,height/2.,apex) 48 | for p in bottom: 49 | yield (level+1,height/2.,average(apex,p)) 50 | 51 | def sierpinski(height, x,y,z, level): 52 | tetrahedra = [(0,height,(x,y,z))] 53 | for i in range(level): 54 | out = [] 55 | for tet in tetrahedra: 56 | out += transform(tet) 57 | tetrahedra = out 58 | return tetrahedra 59 | 60 | mc = Minecraft() 61 | d = drawing.Drawing(mc) 62 | pos = mc.player.getPos() 63 | height = 240 if not settings.isPE else 128 64 | levels = 7 65 | mc.player.setPos(tetrahedronBottom(height,(pos.x,pos.y+height,pos.z))[0]) 66 | tetrahedra = sierpinski(height,pos.x,pos.y+height,pos.z,levels) 67 | mc.postToChat("Drawing") 68 | if len(argv) >= 2 and '__' not in argv[1]: 69 | specifiedBlock = parseBlock(argv[1]) 70 | block = lambda level : specifiedBlock 71 | else: 72 | block = lambda level : RAINBOW[level % len(RAINBOW)] 73 | for tet in tetrahedra: 74 | drawTetrahedron(tet[1],tet[2],block(tet[0])) 75 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/lforest.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | # L-system with turtle graphics 5 | # 6 | 7 | import lsystem 8 | import random 9 | from mcturtle import * 10 | 11 | t = Turtle() 12 | t.pendelay(0) 13 | t.turtle(None) 14 | t.verticalangle(90) 15 | 16 | def tree(): 17 | global angle 18 | global thickness 19 | global length 20 | 21 | angle = 15 22 | thickness = 8 23 | length = 10 24 | 25 | t.pendown() 26 | t.penblock(WOOD) 27 | rules = {'A': [(0.55,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'), 28 | (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]} 29 | 30 | axiom = 'fA' 31 | material = WOOD 32 | 33 | t.penwidth(thickness) 34 | t.penblock(material) 35 | 36 | stack = [] 37 | def push(): 38 | global length 39 | global thickness 40 | stack.append((length,thickness)) 41 | t.push() 42 | thickness = thickness * 0.6 43 | if length == 10: 44 | length = 9 45 | elif length == 9: 46 | length = 8.4 47 | else: 48 | length = length * 0.75 49 | if thickness < 1: 50 | thickness = 1 51 | if length <= 1.6: 52 | t.penblock(LEAVES_OAK_PERMANENT) 53 | t.penwidth(thickness) 54 | 55 | def pop(): 56 | global length 57 | global thickness 58 | length,thickness = stack.pop() 59 | t.pop() 60 | 61 | dictionary = { 62 | '[': push, 63 | ']': pop, 64 | '^': lambda: t.pitch(angle), 65 | '>': lambda: t.roll(angle), 66 | 'f': lambda: t.go(length) 67 | 68 | } 69 | 70 | lsystem.lsystem(axiom, rules, dictionary, 11) 71 | #tree() 72 | 73 | MIN_DISTANCE = 30 74 | MAX_TRIES = 100 75 | SIZE = MIN_DISTANCE * 10 76 | OVALITY = 1.5 77 | cx = t.position.x 78 | cy = t.position.y 79 | cz = t.position.z 80 | tryCount = 0 81 | positions = [] 82 | 83 | while tryCount < MAX_TRIES: 84 | x = random.uniform(-1,1) 85 | z = random.uniform(-1,1) 86 | if x**2 + z**2 > 1: 87 | continue 88 | x = cx + SIZE/2 * x 89 | z = cz + SIZE/2 * OVALITY * z 90 | ok = True 91 | for x0,z0 in positions: 92 | if (x-x0)**2 + (z-z0)**2 < MIN_DISTANCE**2: 93 | ok = False 94 | break 95 | if not ok: 96 | tryCount += 1 97 | continue 98 | positions.append((x,z)) 99 | tryCount = 0 100 | t.goto(x,cy,z) 101 | print x,cy,z 102 | t.push() 103 | t.roll(random.uniform(0,30)) 104 | tree() 105 | t.pop() 106 | 107 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/models/1701d.txt: -------------------------------------------------------------------------------- 1 | file 1701d.obj 2 | swapyz 0 3 | urlgz https://raw.githubusercontent.com/arpruss/raspberryjammod/master/models/1701d.obj.gz 4 | size 200 5 | default QUARTZ_BLOCK 6 | order entdnacelle -1 7 | order phaserstrips 1 8 | order bluethingies 1 9 | order warpblue 1 10 | credits Enterprise-D by David Metlesits. Not for profit. Star Trek is copyright Paramount Pictures. 11 | 12 | materials 13 | boosters default 14 | phaserstrips SEA_LANTERN 15 | entdsaucbot default 16 | grey WOOL_LIGHT_GRAY 17 | entdhangarmod default 18 | lum GLOWSTONE_BLOCK 19 | entdbasichull default 20 | thrusters default 21 | coil default 22 | entdnacelle default 23 | warpblue SEA_LANTERN 24 | Material__21 default 25 | winoff default 26 | bluethingies SEA_LANTERN 27 | defring default 28 | impulseengines default 29 | entdstripes default 30 | redmarkings WOOL_RED 31 | blackmarkings WOOL_BLACK 32 | greenlight default 33 | redlight default 34 | whitelight default 35 | Material__22 default 36 | entdsauctop default 37 | yellowlet default 38 | windows default 39 | entdmainhulltop default 40 | lifeboats default 41 | entdmainhullbot default 42 | end 43 | 44 | Copyright information: 45 | 46 | Non-commercial use only. 47 | 48 | Star Trek (including but not limited to Star Trek: Deep Space Nine, Star Trek: 49 | The Next Generation, Star Trek: Voyager, Star Trek: Enterprise), and the 50 | various logo devices used in them, are copyright Paramount Pictures, as are the 51 | characters, related images, and sound from the productions. None of these web 52 | pages are either endorsed or supported by Paramount Pictures. Star Trek ( 53 | including but not limited to Star Trek: Deep Space Nine, Star Trek: The Next 54 | Generation, Star Trek: Voyager, Star Trek: Enterprise), and the various logo 55 | devices used in them, are copyright Paramount Pictures, as are the characters, 56 | related images, and sound from the productions. None of these web pages are 57 | either endorsed or supported by Paramount Pictures. 58 | 59 | Mesh converted by Alexander Pruss from 3DS MAX mesh: 60 | http://www.trekmeshes.ch/meshes/meshesdetails.php?Name=1701DMETLESITS 61 | 62 | --Information from original mesh-- 63 | 64 | USS ENTERPRISE NCC-1701-D 65 | 66 | Galaxy class starship, under the command of Jean-Luc Picard. 67 | 68 | Conditions of use: 69 | 70 | Please put credits on the images made with this mesh, something like "Enterprise-D by David Metlesits", or similar. 71 | You may use this mesh for any non-profit work. 72 | You may edit, kitbash or do anything with this mesh. Just have fun with it :D 73 | 74 | Live long and prosper! 75 | 76 | 77 | David "KnightRider" Metlesits 78 | 79 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/klein2.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import sys 7 | 8 | def draw_surface(xf,yf,zf,a0,a1,asteps,b0,b1,bsteps,ox,oy,oz,scalex,scaley,scalez,mcblock,mcmeta): 9 | cfx = compile(xf,'','eval') 10 | cfy = compile(yf,'','eval') 11 | cfz = compile(zf,'','eval') 12 | 13 | for i in xrange(asteps): 14 | u = (a0 * (asteps-1-i) + a1 * i) / asteps 15 | for j in xrange(bsteps): 16 | v = (b0 * (bsteps-1-j) + b1 * j) / bsteps 17 | x = eval(cfx) 18 | y = eval(cfy) 19 | z = eval(cfz) 20 | mc.setBlock(ox+x * scalex, oy+y * scaley, oz+z * scalez, mcblock, mcmeta) 21 | 22 | mc = Minecraft() 23 | playerPos = mc.player.getPos() 24 | 25 | scale = 3 26 | 27 | b = STAINED_GLASS.id 28 | m = 5 29 | 30 | arg = 1 31 | 32 | if (len(sys.argv)>arg): 33 | b = int(sys.argv[arg]) 34 | arg += 1 35 | if (len(sys.argv)>arg): 36 | m = int(sys.argv[arg]) 37 | arg += 1 38 | 39 | # http://www.gnuplotting.org/klein-bottle/ 40 | 41 | xformula = '(2.5-1.5*cos(v))*cos(u)' 42 | zformula = '(2.5-1.5*cos(v))*sin(u)' 43 | yformula = '-2.5*sin(v)' 44 | 45 | draw_surface(xformula,yformula,zformula,0,2*pi,50*scale,0,pi,50*scale,playerPos.x,playerPos.y+2.5*scale,playerPos.z,scale,scale,scale,b, m) 46 | mc.postToChat("Part 1 done") 47 | 48 | if (len(sys.argv)>arg): 49 | b = int(sys.argv[arg]) 50 | arg += 1 51 | if (len(sys.argv)>arg): 52 | m = int(sys.argv[arg]) 53 | arg += 1 54 | 55 | xformula = '(2.5-1.5*cos(v))*cos(u)' 56 | zformula = '(2.5-1.5*cos(v))*sin(u)' 57 | yformula = '3*v - 3*pi' 58 | 59 | draw_surface(xformula,yformula,zformula,0,2*pi,50*scale,pi,2*pi,50*scale,playerPos.x,playerPos.y+2.5*scale,playerPos.z,scale,scale,scale,b,m) 60 | mc.postToChat("Part 2 done") 61 | 62 | if (len(sys.argv)>arg): 63 | b = int(sys.argv[arg]) 64 | arg += 1 65 | if (len(sys.argv)>arg): 66 | m = int(sys.argv[arg]) 67 | arg += 1 68 | 69 | xformula = '-2+2*cos(v)-cos(u)' 70 | zformula = 'sin(u)' 71 | yformula = '(2+cos(u))*sin(v)+3*pi' 72 | 73 | draw_surface(xformula,yformula,zformula,0,2*pi,50*scale,2*pi,3*pi,50*scale,playerPos.x,playerPos.y+2.5*scale,playerPos.z,scale,scale,scale,b,m) 74 | mc.postToChat("Part 3 done") 75 | 76 | if (len(sys.argv)>arg): 77 | b = int(sys.argv[arg]) 78 | arg += 1 79 | if (len(sys.argv)>arg): 80 | m = int(sys.argv[arg]) 81 | arg += 1 82 | 83 | xformula = '-2+2*cos(v)-cos(u)' 84 | zformula = 'sin(u)' 85 | yformula = '-3*v+12*pi' 86 | 87 | draw_surface(xformula,yformula,zformula,0,2*pi,50*scale,3*pi,4*pi,50*scale,playerPos.x,playerPos.y+2.5*scale,playerPos.z,scale,scale,scale,b,m) 88 | 89 | mc.postToChat("Formula done") 90 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/stuffaboutcode_bridge.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #www.stuffaboutcode.com 4 | #Raspberry Pi, Minecraft - auto bridge 5 | 6 | # mcpipy.com retrieved from URL below, written by stuffaboutcode 7 | # http://www.stuffaboutcode.com/2013/02/raspberry-pi-minecraft-auto-bridge.html 8 | 9 | #import the minecraft.py module from the minecraft directory 10 | import mcpi.minecraft as minecraft 11 | #import minecraft block module 12 | import mcpi.block as block 13 | #import time, so delays can be used 14 | import time 15 | import server 16 | 17 | 18 | #function to round players float position to integer position 19 | def roundVec3(vec3): 20 | return minecraft.Vec3(int(vec3.x), int(vec3.y), int(vec3.z)) 21 | 22 | if __name__ == "__main__": 23 | 24 | time.sleep(2) 25 | 26 | #Connect to minecraft by creating the minecraft object 27 | # - minecraft needs to be running and in a game 28 | mc = minecraft.Minecraft.create(server.address) 29 | 30 | #Post a message to the minecraft chat window 31 | mc.postToChat("Hi, Minecraft - Auto Bridge Active") 32 | mc.postToChat("www.stuffaboutcode.com") 33 | 34 | #Get the players position 35 | lastPlayerPos = mc.player.getPos() 36 | 37 | while (True): 38 | 39 | #Get the players position 40 | playerPos = mc.player.getPos() 41 | 42 | #Find the difference between the player's position and the last position 43 | movementX = lastPlayerPos.x - playerPos.x 44 | movementZ = lastPlayerPos.z - playerPos.z 45 | 46 | #Has the player moved more than 0.2 in any horizontal (x,z) direction 47 | 48 | if ((movementX < -0.2) or (movementX > 0.2) or (movementZ < -0.2) or (movementZ > 0.2)): 49 | 50 | #Project players direction forward to the next square 51 | nextPlayerPos = playerPos 52 | # keep adding the movement to the players location till the next block is found 53 | while ((int(playerPos.x) == int(nextPlayerPos.x)) and (int(playerPos.z) == int(nextPlayerPos.z))): 54 | nextPlayerPos = minecraft.Vec3(nextPlayerPos.x - movementX, nextPlayerPos.y, nextPlayerPos.z - movementZ) 55 | 56 | #Is the block below the next player pos air, if so fill it in with DIAMOND 57 | blockBelowPos = roundVec3(nextPlayerPos) 58 | blockBelowPos.z = blockBelowPos.z - 1 59 | blockBelowPos.y = blockBelowPos.y - 1 60 | if mc.getBlock(blockBelowPos) == block.AIR: 61 | mc.setBlock(blockBelowPos.x, blockBelowPos.y, blockBelowPos.z, block.DIAMOND_BLOCK) 62 | 63 | #Store players last position 64 | lastPlayerPos = playerPos 65 | 66 | #Delay 67 | time.sleep(0.01) -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/vehicles/TIE_Fighter.py: -------------------------------------------------------------------------------- 1 | baseAngle,highWater,baseVehicle=(-91.205322265625, -9223372036854775808L, {(-2, -5, 1): Block(35, 7), (-2, -2, 4): Block(35, 7), (1, -3, 1): Block(95, 15), (-2, -3, -2): Block(35, 7), (-1, -1, -1): Block(35, 7), (-1, -5, 4): Block(35, 7), (-2, -3, -4): Block(35, 7), (-1, -1, -4): Block(35, 7), (0, -2, -4): Block(35, 7), (1, -4, -1): Block(35, 7), (0, -3, 2): Block(35, 7), (-3, -4, 0): Block(35, 7), (-1, -1, 4): Block(35, 7), (1, -4, -4): Block(35, 7), (1, -2, 4): Block(35, 7), (0, -2, 4): Block(35, 7), (-3, -4, 4): Block(35, 7), (-3, -3, -4): Block(35, 7), (0, -1, -4): Block(35, 7), (-3, -3, -1): Block(35, 7), (-1, -3, -2): Block(35, 7), (1, -2, 0): Block(95, 15), (-2, -2, -2): Block(35, 7), (-2, -4, -4): Block(35, 7), (0, -4, -2): Block(35, 7), (-2, -1, -1): Block(35, 7), (-2, -5, 4): Block(35, 7), (0, -4, -4): Block(35, 7), (-1, -2, -2): Block(35, 7), (-3, -3, 1): Block(35, 7), (-1, -4, -4): Block(35, 7), (-1, -4, -2): Block(35, 7), (-1, -3, 4): Block(35, 7), (0, -1, 4): Block(35, 7), (-1, -6, -4): Block(35, 7), (-1, -3, -4): Block(35, 7), (0, -3, 4): Block(35, 7), (1, -4, 1): Block(35, 7), (-1, -4, 4): Block(35, 7), (-1, -2, -4): Block(35, 7), (-1, 0, 4): Block(35, 7), (-1, -3, 3): Block(35, 7), (0, -5, 0): Block(35, 7), (1, -3, -4): Block(35, 7), (0, -2, 2): Block(35, 7), (-1, -1, 1): Block(35, 7), (1, -3, -1): Block(95, 15), (-3, -2, 0): Block(35, 7), (-2, -3, 4): Block(35, 7), (-3, -2, -4): Block(35, 7), (1, -3, 4): Block(35, 7), (0, -5, 4): Block(35, 7), (0, -1, 0): Block(35, 7), (-1, -5, 1): Block(35, 7), (-3, -2, -1): Block(35, 7), (-2, -3, 2): Block(35, 7), (-3, -2, 4): Block(35, 7), (-1, -2, 4): Block(35, 7), (1, -3, 0): Block(95, 15), (0, -5, -1): Block(35, 7), (0, -1, -1): Block(35, 7), (-2, -4, 4): Block(35, 7), (0, -5, -4): Block(35, 7), (-1, -3, -3): Block(35, 7), (0, -2, -2): Block(35, 7), (-1, -6, 4): Block(35, 7), (-1, 0, -4): Block(35, 7), (-3, -4, 1): Block(35, 7), (-1, -4, 2): Block(35, 7), (-2, -1, 1): Block(35, 7), (1, -2, 1): Block(95, 15), (0, -4, 2): Block(35, 7), (1, -2, -4): Block(35, 7), (1, -2, -1): Block(95, 15), (-1, -5, -4): Block(35, 7), (-3, -3, 0): Block(35, 7), (-1, -1, 0): Block(35, 7), (1, -4, 4): Block(35, 7), (0, -4, 4): Block(35, 7), (-1, -2, 2): Block(35, 7), (-3, -3, 4): Block(35, 7), (-3, -4, -1): Block(35, 7), (0, -3, -4): Block(35, 7), (1, -4, 0): Block(35, 7), (-2, -1, 4): Block(35, 7), (-2, -1, -4): Block(35, 7), (-2, -4, 2): Block(35, 7), (-3, -4, -4): Block(35, 7), (0, -3, -2): Block(35, 7), (0, -1, 1): Block(35, 7), (-1, -3, 2): Block(35, 7), (-1, -5, 0): Block(35, 7), (-2, -4, -2): Block(35, 7), (-2, -2, 2): Block(35, 7), (-2, -2, -4): Block(35, 7), (0, -5, 1): Block(35, 7), (-2, -5, -1): Block(35, 7), (-2, -5, -4): Block(35, 7), (-2, -1, 0): Block(35, 7), (-3, -2, 1): Block(35, 7), (-2, -5, 0): Block(35, 7), (-1, -5, -1): Block(35, 7)}) 2 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/grenade.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | # 6 | # python grenade.py [speed [gravity]] 7 | # 8 | # Throws a grenade with the specified speed in m/s (default: 15) and specified 9 | # gravitational acceleration (default: earth) in m/s^2 or given by listing a planet, 10 | # sun, moon or pluto. 11 | # 12 | 13 | from mc import * 14 | from vehicle import * 15 | import time 16 | import sys 17 | 18 | GRAVITIES = { 19 | 'sun':274, 20 | 'mercury':3.59, 21 | 'venus':8.87, 22 | 'earth':9.81, 23 | 'moon':1.62, 24 | 'mars':3.77, 25 | 'jupiter':25.95, 26 | 'saturn':11.08, 27 | 'uranus':10.67, 28 | 'neptune':14.07, 29 | 'pluto':0.42 30 | } 31 | 32 | def getPath(center, azi, alt, v0): 33 | vx = v0 * cos(alt) * sin(-azi) 34 | vy = v0 * sin(alt) 35 | vz = v0 * cos(alt) * cos(-azi) 36 | t = 0 37 | x = center.x + cos(alt) * sin(-azi) * 2 38 | y = center.y + sin(alt) * 2 + 2 39 | z = center.z + cos(alt) * cos(-azi) * 2 40 | path = [(t,Vec3(round(x),round(y),round(z)))] 41 | while not mc.getBlock(x,y,z): 42 | v = sqrt(vx*vx+vy*vy+vz*vz) 43 | if v < 1: 44 | dt = 0.5 45 | else: 46 | dt = 0.5/v 47 | v1x = vx 48 | v1y = vy - g * dt 49 | v1z = vz 50 | x += (vx+v1x)/2 * dt 51 | y += (vy+v1y)/2 * dt 52 | z += (vz+v1z)/2 * dt 53 | vx = v1x 54 | vy = v1y 55 | vz = v1z 56 | t += dt 57 | path.append( ( t,Vec3(round(x),round(y),round(z)) ) ) 58 | return path 59 | 60 | def getXYZ(path, t1): 61 | for t,xyz in path: 62 | if t1<=t: 63 | return xyz 64 | return path[-1][1] 65 | 66 | mc = Minecraft() 67 | 68 | try: 69 | v0 = int(sys.argv[1]) 70 | except: 71 | v0 = 15 72 | 73 | if 3 <= len(sys.argv): 74 | try: 75 | g = float(sys.argv[2]) 76 | except: 77 | g = GRAVITIES[sys.argv[2].lower()] 78 | else: 79 | g = GRAVITIES['earth'] 80 | 81 | center = mc.player.getPos() 82 | azi = mc.player.getRotation() * pi/180. 83 | alt = -mc.player.getPitch() * pi/180. 84 | 85 | GRENADE = { (-1,0,0):TNT, (1,0,0):TNT, (0,-1,0):TNT, (0,1,0):TNT, (0,0,1):TNT, (0,0,-1):TNT } 86 | 87 | grenade = Vehicle(mc, False) 88 | grenade.setVehicle(GRENADE) 89 | 90 | path = getPath(center, azi, alt, v0) 91 | 92 | dictionary = {} 93 | prev = path[0][1] 94 | 95 | grenade.draw(prev.x,prev.y,prev.z) 96 | 97 | t0 = time.time() 98 | 99 | while True: 100 | t = time.time() - t0 101 | pos = getXYZ(path,t) 102 | grenade.moveTo(pos.x,pos.y,pos.z) 103 | prev=pos 104 | time.sleep(0.1) 105 | if t > path[-1][0]: 106 | break 107 | 108 | mc.setBlock(path[-1][1],FIRE) 109 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/jjinux_sierpinski_triangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # mcpipy.com retrieved from URL below, written by jjinux 4 | # http://jjinux.blogspot.com/2013/05/drawing-sierpinskis-triangle-in.html 5 | 6 | """Draw Sierpinski's triangle in Minecraft. 7 | 8 | See: http://jjinux.blogspot.com/2013/05/drawing-sierpinskis-triangle-in.html 9 | 10 | """ 11 | 12 | import random 13 | 14 | import mcpi.minecraft 15 | import mcpi.block as block 16 | import server 17 | 18 | # It goes from -MAX_XZ to MAX_XZ. 19 | MAX_XZ = 128 20 | MAX_Y = 64 21 | 22 | # These are the vertices of the triangle. It's a list of points. Each point 23 | # is an (X, Y, X) tuple. 24 | TRIANGLE_HEIGHT = MAX_Y - 1 25 | TOP = (-MAX_XZ, TRIANGLE_HEIGHT, 0) 26 | BOTTOM_LEFT = (MAX_XZ, TRIANGLE_HEIGHT, MAX_XZ) 27 | BOTTOM_RIGHT = (MAX_XZ, TRIANGLE_HEIGHT, -MAX_XZ) 28 | TRIANGLE_VERTICES = [TOP, BOTTOM_LEFT, BOTTOM_RIGHT] 29 | 30 | BASE_BLOCK_ID = block.SANDSTONE.id 31 | TRIANGLE_BLOCK_ID = block.SNOW.id 32 | 33 | # This is the maximum number of iterations to let the algorithm run. The 34 | # algorithm relies on randomness, so I'm just picking a sensible value. 35 | MAX_ITERATIONS = MAX_XZ ** 2 36 | 37 | PRINT_FREQ = 1000 38 | 39 | 40 | def clear_board(minecraft): 41 | minecraft.setBlocks(-MAX_XZ, 0, -MAX_XZ, MAX_XZ, MAX_Y, MAX_XZ, 0) 42 | minecraft.setBlocks(-MAX_XZ, 0, -MAX_XZ, MAX_XZ, -MAX_Y, MAX_XZ, BASE_BLOCK_ID) 43 | 44 | 45 | def draw_sierpinski_triangle(minecraft): 46 | 47 | def random_in_range(): 48 | return random.randint(-MAX_XZ, MAX_XZ) 49 | 50 | def int_average(a, b): 51 | return int(round((a + b) / 2.0)) 52 | 53 | # Draw the triangle vertices. 54 | 55 | for (x, y, z) in TRIANGLE_VERTICES: 56 | minecraft.setBlock(x, y, z, TRIANGLE_BLOCK_ID) 57 | 58 | # Pick a random point to start at. 59 | 60 | current = (random_in_range(), 61 | TRIANGLE_HEIGHT, 62 | random_in_range()) 63 | 64 | for i in xrange(MAX_ITERATIONS): 65 | 66 | if i % PRINT_FREQ == 0: 67 | print("Drew %s blocks" % i) 68 | 69 | # Pick a random vertex to "walk" toward. 70 | 71 | destination = random.choice(TRIANGLE_VERTICES) 72 | 73 | # Draw a block in the middle of the current location and the 74 | # destination. 75 | 76 | (c_x, c_y, c_z) = current 77 | (d_x, d_y, d_z) = destination 78 | current = ( 79 | int_average(c_x, d_x), 80 | TRIANGLE_HEIGHT, 81 | int_average(c_z, d_z) 82 | ) 83 | (x, y, z) = current 84 | minecraft.setBlock(x, y, z, TRIANGLE_BLOCK_ID) 85 | 86 | 87 | if __name__ == "__main__": 88 | minecraft = mcpi.minecraft.Minecraft.create(server.address) 89 | 90 | # Uncomment this if you need it. 91 | # clear_board(minecraft) 92 | 93 | draw_sierpinski_triangle(minecraft) -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/blocks_to_bombs.py: -------------------------------------------------------------------------------- 1 | #www.stuffaboutcode.com 2 | #Raspberry Pi, Minecraft Bombs - Turn any block into a bomb! 3 | 4 | #import the minecraft.py module from the minecraft directory 5 | import mcpi.minecraft as minecraft 6 | #import minecraft block module 7 | import mcpi.block as block 8 | #import time, so delays can be used 9 | import time 10 | #import threading, so threads can be used 11 | import threading 12 | 13 | class ExplodingBlock(threading.Thread): 14 | 15 | def __init__(self, pos, fuseInSecs, blastRadius): 16 | #Setup object 17 | threading.Thread.__init__(self) 18 | self.pos = pos 19 | self.fuseInSecs = fuseInSecs 20 | self.blastRadius = blastRadius 21 | 22 | def run(self): 23 | #Open connect to minecraft 24 | mc = minecraft.Minecraft.create() 25 | 26 | #Get values 27 | pos = self.pos 28 | blastRadius = self.blastRadius 29 | 30 | #Explode the block! 31 | # get block type 32 | blockType = mc.getBlock(pos.x, pos.y, pos.z) 33 | # flash the block 34 | for fuse in range(0, self.fuseInSecs): 35 | mc.setBlock(pos.x, pos.y, pos.z, block.AIR) 36 | time.sleep(0.5) 37 | mc.setBlock(pos.x, pos.y, pos.z, blockType) 38 | time.sleep(0.5) 39 | # create sphere of air 40 | for x in range(blastRadius*-1,blastRadius): 41 | for y in range(blastRadius*-1, blastRadius): 42 | for z in range(blastRadius*-1,blastRadius): 43 | if x**2 + y**2 + z**2 < blastRadius**2: 44 | mc.setBlock(pos.x + x, pos.y + y, pos.z + z, block.AIR) 45 | 46 | if __name__ == "__main__": 47 | 48 | time.sleep(5) 49 | #Connect to minecraft by creating the minecraft object 50 | # - minecraft needs to be running and in a game 51 | mc = minecraft.Minecraft.create() 52 | 53 | #Post a message to the minecraft chat window 54 | mc.postToChat("Minecraft Bombs, Hit (Right Click) a Block, www.stuffaboutcode.com") 55 | 56 | #loop until Ctrl C 57 | try: 58 | while True: 59 | #Get the block hit events 60 | blockHits = mc.events.pollBlockHits() 61 | # if a block has been hit 62 | if blockHits: 63 | # for each block that has been hit 64 | for blockHit in blockHits: 65 | #Create and run the exploding block class in its own thread 66 | # pass the position of the block, fuse time in seconds and blast radius 67 | # threads are used so multiple exploding blocks can be created 68 | explodingBlock = ExplodingBlock(blockHit.pos, 3, 3) 69 | explodingBlock.daemon 70 | explodingBlock.start() 71 | time.sleep(0.1) 72 | except KeyboardInterrupt: 73 | print("stopped") 74 | -------------------------------------------------------------------------------- /raspberryjammod/slowbit32.lua: -------------------------------------------------------------------------------- 1 | -- These are super slow 32-bit operations -- 2 | 3 | local two31 = 2^31 4 | local two32 = 2^32 5 | 6 | local to_binary = function(x) 7 | local pos = two31 8 | local a = "" 9 | if x < 0 then 10 | x = x + two32 11 | end 12 | x = x % two32 13 | for i=1,32 do 14 | if x >= pos then 15 | a = a .. "1" 16 | x = x - pos 17 | else 18 | a = a .. "0" 19 | end 20 | pos = pos / 2 21 | end 22 | return a 23 | end 24 | 25 | local from_binary = function(x) 26 | local z = tonumber(x,2) 27 | if z >= two31 then 28 | return z - two32 29 | else 30 | return z 31 | end 32 | end 33 | 34 | 35 | local band = function(...) 36 | local a = {} 37 | local arg = {...} 38 | for i = 1,#arg do 39 | a[i] = to_binary(arg[i]) 40 | end 41 | local c = "" 42 | for i = 1,32 do 43 | local value = true 44 | for j = 1,#arg do 45 | if a[j]:sub(i,i) == "0" then 46 | value = false 47 | break 48 | end 49 | end 50 | 51 | if value then 52 | c = c .. "1" 53 | else 54 | c = c .. "0" 55 | end 56 | end 57 | return from_binary(c) 58 | end 59 | 60 | local bor = function(...) 61 | local a = {} 62 | local arg = {...} 63 | for i = 1,#arg do 64 | a[i] = to_binary(arg[i]) 65 | end 66 | local c = "" 67 | for i = 1,32 do 68 | local value = false 69 | for j = 1,#arg do 70 | if a[j]:sub(i,i) == "1" then 71 | value = true 72 | break 73 | end 74 | end 75 | 76 | if value then 77 | c = c .. "1" 78 | else 79 | c = c .. "0" 80 | end 81 | end 82 | return from_binary(c) 83 | end 84 | 85 | local bxor = function(...) 86 | local a = {} 87 | local arg = {...} 88 | for i = 1,#arg do 89 | a[i] = to_binary(arg[i]) 90 | end 91 | local c = "" 92 | for i = 1,32 do 93 | local value = false 94 | for j = 1,#arg do 95 | if a[j]:sub(i,i) == "1" then 96 | value = not value 97 | end 98 | end 99 | 100 | if value then 101 | c = c .. "1" 102 | else 103 | c = c .. "0" 104 | end 105 | end 106 | return from_binary(c) 107 | end 108 | 109 | 110 | local bnot = function(x) 111 | local a = to_binary(x) 112 | local c = "" 113 | for i = 1,32 do 114 | if a:sub(i,i) == "0" then 115 | c = c .. "1" 116 | else 117 | c = c .. "0" 118 | end 119 | end 120 | return from_binary(c) 121 | end 122 | 123 | local lshift = function(x,n) 124 | return (x * 2^n) % two32 125 | end 126 | 127 | local rshift = function(x,n) 128 | return math.floor(x / 2^n) 129 | end 130 | 131 | local rol = function(x,n) 132 | local a = to_binary(x) 133 | for i = 1,n do 134 | a = a:sub(2,32) .. a:sub(1,1) 135 | end 136 | return from_binary(a) 137 | end 138 | 139 | return {rol=rol, bxor=bxor, bor=bor, band=band, bnot=bnot, lshift=lshift, rshift=rshift} 140 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/stuffaboutcode_basics.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #www.stuffaboutcode.com 4 | #Raspberry Pi, Minecraft API - the basics 5 | 6 | # mcpipy.com retrieved from URL below, written by stuffaboutcode 7 | # http://www.stuffaboutcode.com/2013/01/raspberry-pi-minecraft-api-basics.html 8 | 9 | #import the minecraft.py module from the minecraft directory 10 | import mcpi.minecraft as minecraft 11 | #import minecraft block module 12 | import mcpi.block as block 13 | #import time, so delays can be used 14 | import time 15 | import server 16 | 17 | 18 | if __name__ == "__main__": 19 | 20 | time.sleep(2) 21 | 22 | #Connect to minecraft by creating the minecraft object 23 | # - minecraft needs to be running and in a game 24 | mc = minecraft.Minecraft.create(server.address) 25 | 26 | #Post a message to the minecraft chat window 27 | mc.postToChat("Hi, Minecraft API, the basics, what can you do? ") 28 | 29 | time.sleep(5) 30 | 31 | #Find out your players position 32 | playerPos = mc.player.getPos() 33 | mc.postToChat("Find your position - its x=" + str(playerPos.x) + ", y=" + str(playerPos.y) + ", z=" + str(playerPos.z)) 34 | 35 | time.sleep(5) 36 | 37 | #Using your players position 38 | # - the players position is an x,y,z coordinate of floats (e.g. 23.59,12.00,-45.32) 39 | # - in order to use the players position in other commands we need integers (e.g. 23,12,-45) 40 | # - so round the players position 41 | # - the Vec3 object is part of the minecraft class library 42 | playerPos = minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z)) 43 | 44 | #Changing your players position 45 | mc.postToChat("Move your player - 30 blocks UP!") 46 | time.sleep(2) 47 | mc.player.setPos(playerPos.x,playerPos.y + 30,playerPos.z) 48 | # - wait for you to fall! 49 | time.sleep(5) 50 | 51 | #Interacting with a block 52 | # - get the type block directly below you 53 | blockType = mc.getBlock(playerPos.x,playerPos.y - 1,playerPos.z) 54 | mc.postToChat("Interact with blocks - the block below you is of type - " + str(blockType)) 55 | 56 | time.sleep(5) 57 | 58 | # - change the block below you to wood planks 59 | mc.setBlock(playerPos.x,playerPos.y-1,playerPos.z,block.WOOD_PLANKS) 60 | mc.postToChat("Change blocks - the block below you is now wood planks") 61 | 62 | time.sleep(5) 63 | 64 | #Creating many blocks 65 | mc.postToChat("Create blocks - making a diamond tower") 66 | 67 | # - loop 20 times 68 | for up in range(0, 20): 69 | mc.setBlock(playerPos.x + 1, playerPos.y + up, playerPos.z, block.DIAMOND_BLOCK) 70 | 71 | time.sleep(2) 72 | 73 | # - put you on top of the tower 74 | mc.postToChat("Dont look down, because Im putting you on top of it!") 75 | time.sleep(1) 76 | mc.player.setPos(playerPos.x + 1, playerPos.y + 20, playerPos.z) 77 | 78 | time.sleep(5) 79 | 80 | mc.postToChat("www.stuffaboutcode.com") -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/vec3.py: -------------------------------------------------------------------------------- 1 | class Vec3: 2 | def __init__(self, x=0, y=0, z=0): 3 | self.x = x 4 | self.y = y 5 | self.z = z 6 | 7 | def __add__(self, rhs): 8 | c = self.clone() 9 | c += rhs 10 | return c 11 | 12 | def __iadd__(self, rhs): 13 | self.x += rhs.x 14 | self.y += rhs.y 15 | self.z += rhs.z 16 | return self 17 | 18 | def length(self): 19 | return self.lengthSqr ** .5 20 | 21 | def lengthSqr(self): 22 | return self.x * self.x + self.y * self.y + self.z * self.z 23 | 24 | def __mul__(self, k): 25 | c = self.clone() 26 | c *= k 27 | return c 28 | 29 | def __imul__(self, k): 30 | self.x *= k 31 | self.y *= k 32 | self.z *= k 33 | return self 34 | 35 | def clone(self): 36 | return Vec3(self.x, self.y, self.z) 37 | 38 | def __neg__(self): 39 | return Vec3(-self.x, -self.y, -self.z) 40 | 41 | def __sub__(self, rhs): 42 | return self.__add__(-rhs) 43 | 44 | def __isub__(self, rhs): 45 | return self.__iadd__(-rhs) 46 | 47 | def __repr__(self): 48 | return "Vec3(%s,%s,%s)"%(self.x,self.y,self.z) 49 | 50 | def __iter__(self): 51 | return iter((self.x, self.y, self.z)) 52 | 53 | def _map(self, func): 54 | self.x = func(self.x) 55 | self.y = func(self.y) 56 | self.z = func(self.z) 57 | 58 | def __cmp__(self, rhs): 59 | dx = self.x - rhs.x 60 | if dx != 0: return dx 61 | dy = self.y - rhs.y 62 | if dy != 0: return dy 63 | dz = self.z - rhs.z 64 | if dz != 0: return dz 65 | return 0 66 | 67 | def iround(self): self._map(lambda v:int(v+0.5)) 68 | def ifloor(self): self._map(int) 69 | 70 | def rotateLeft(self): self.x, self.z = self.z, -self.x 71 | def rotateRight(self): self.x, self.z = -self.z, self.x 72 | 73 | def testVec3(): 74 | # Note: It's not testing everything 75 | 76 | # 1.1 Test initialization 77 | it = Vec3(1, -2, 3) 78 | assert it.x == 1 79 | assert it.y == -2 80 | assert it.z == 3 81 | 82 | assert it.x != -1 83 | assert it.y != +2 84 | assert it.z != -3 85 | 86 | # 2.1 Test cloning and equality 87 | clone = it.clone() 88 | assert it == clone 89 | it.x += 1 90 | assert it != clone 91 | 92 | # 3.1 Arithmetic 93 | a = Vec3(10, -3, 4) 94 | b = Vec3(-7, 1, 2) 95 | c = a + b 96 | assert c - a == b 97 | assert c - b == a 98 | assert a + a == a * 2 99 | 100 | assert a - a == Vec3(0,0,0) 101 | assert a + (-a) == Vec3(0,0,0) 102 | 103 | # Test repr 104 | e = eval(repr(it)) 105 | assert e == it 106 | 107 | if __name__ == "__main__": 108 | testVec3() 109 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/toschematic.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | from ast import literal_eval 3 | import os 4 | import sys 5 | import re 6 | import mcpi.nbt as nbt 7 | from struct import pack 8 | from vehicle import getLoadPath 9 | 10 | def load(filename): 11 | with open(filename) as f: 12 | data = ''.join(f.readlines()) 13 | result = re.search("=\\s*(.*)",data) 14 | if result is None: 15 | raise ValueError 16 | 17 | # Check to ensure only function called is Block() by getting literal_eval to 18 | # raise an exception when "Block" is removed and the result isn't a literal. 19 | # This SHOULD make the eval call safe, though USE AT YOUR OWN RISK. Ideally, 20 | # one would walk the ast parse tree and use a whitelist. 21 | literal_eval(result.group(1).replace("Block","")) 22 | 23 | return eval(result.group(1)) 24 | 25 | def toSchematic(vehicle): 26 | x0 = min(x for (x,y,z) in vehicle) 27 | y0 = min(y for (x,y,z) in vehicle) 28 | z0 = min(z for (x,y,z) in vehicle) 29 | x1 = max(x for (x,y,z) in vehicle) 30 | y1 = max(y for (x,y,z) in vehicle) 31 | z1 = max(z for (x,y,z) in vehicle) 32 | schematic = nbt.NBTFile() 33 | schematic.name = "Schematic" 34 | schematic.tags.append(nbt.TAG_Short(name="Width", value = x1-x0+1)) 35 | schematic.tags.append(nbt.TAG_Short(name="Height", value = y1-y0+1)) 36 | schematic.tags.append(nbt.TAG_Short(name="Length", value = z1-z0+1)) 37 | schematic.tags.append(nbt.TAG_String(name="Materials", value="Alpha")) 38 | ids = b'' 39 | metas = b'' 40 | 41 | for y in range(y0,y1+1): 42 | for z in range(z0,z1+1): 43 | for x in range(x0,x1+1): 44 | try: 45 | b = vehicle[(x,y,z)] 46 | except: 47 | b = Block(0) 48 | ids += pack("B", b.id) 49 | metas += pack("B", b.data) 50 | 51 | blocks = nbt.TAG_Byte_Array(name="Blocks") 52 | blocks.value = ids 53 | schematic.tags.append(blocks) 54 | data = nbt.TAG_Byte_Array(name="Data") 55 | data.value = metas 56 | schematic.tags.append(data) 57 | schematic.tags.append(nbt.TAG_List(name="Entities", type=nbt.TAG_Compound)) 58 | schematic.tags.append(nbt.TAG_List(name="TileEntities", type=nbt.TAG_Compound)) 59 | 60 | return schematic 61 | 62 | def vehicleToSchematic(vehiclePath, schematicPath): 63 | angle,highWater,vehicle = load(vehiclePath) 64 | nbt = toSchematic(vehicle) 65 | nbt.write_file(schematicPath) 66 | 67 | if __name__ == '__main__': 68 | directory = os.path.join(os.path.dirname(sys.argv[0]),"vehicles") 69 | if len(sys.argv) >= 2: 70 | if sys.argv[1].endswith(".py"): 71 | name = directory + "/" + sys.argv[1] 72 | else: 73 | name = directory + "/" + sys.argv[1] + ".py" 74 | else: 75 | name = getLoadPath(directory, "py") 76 | 77 | out = name 78 | 79 | if out.endswith(".py"): 80 | out = name[:-2] + "schematic" 81 | else: 82 | out += ".schematic" 83 | 84 | vehicleToSchematic(name, out) 85 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/stuffaboutcode_hideandseek.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #www.stuffaboutcode.com 4 | #Raspberry Pi, Minecraft - hide and seek 5 | 6 | # mcpipy.com retrieved from URL below, written by stuffaboutcode 7 | # http://www.stuffaboutcode.com/2013/01/raspberry-pi-minecraft-hide-and-seek.html 8 | 9 | #import the minecraft.py module from the minecraft directory 10 | import mcpi.minecraft as minecraft 11 | #import minecraft block module 12 | import mcpi.block as block 13 | #import time, so delays can be used 14 | import time 15 | #import random module to create random number 16 | import random 17 | #import math module to use square root function 18 | import math 19 | import server 20 | 21 | 22 | #function to round players float position to integer position 23 | def roundVec3(vec3): 24 | return minecraft.Vec3(int(vec3.x), int(vec3.y), int(vec3.z)) 25 | 26 | def distanceBetweenPoints(point1, point2): 27 | xd = point2.x - point1.x 28 | yd = point2.y - point1.y 29 | zd = point2.z - point1.z 30 | return math.sqrt((xd*xd) + (yd*yd) + (zd*zd)) 31 | 32 | if __name__ == "__main__": 33 | 34 | #Connect to minecraft by creating the minecraft object 35 | # - minecraft needs to be running and in a game 36 | mc = minecraft.Minecraft.create(server.address) 37 | 38 | #Post a message to the minecraft chat window 39 | mc.postToChat("Hi, Minecraft Hide & Seek") 40 | 41 | time.sleep(2) 42 | 43 | #Find the players position 44 | playerPos = mc.player.getPos() 45 | 46 | #Create random position within 50 blocks from the player, our hidden block will go there 47 | randomBlockPos = roundVec3(playerPos) 48 | randomBlockPos.x = random.randrange(randomBlockPos.x - 50, randomBlockPos.x + 50) 49 | randomBlockPos.y = random.randrange(randomBlockPos.y - 5, randomBlockPos.y + 5) 50 | randomBlockPos.z = random.randrange(randomBlockPos.z - 50, randomBlockPos.z + 50) 51 | print randomBlockPos 52 | 53 | #Create hidden diamond block 54 | mc.setBlock(randomBlockPos.x, randomBlockPos.y, randomBlockPos.z, block.DIAMOND_BLOCK) 55 | mc.postToChat("A diamond has been hidden - go find!") 56 | 57 | #Start hide and seek 58 | seeking = True 59 | lastPlayerPos = playerPos 60 | lastDistanceFromBlock = distanceBetweenPoints(randomBlockPos, lastPlayerPos) 61 | timeStarted = time.time() 62 | while (seeking == True): 63 | #Get players position 64 | playerPos = mc.player.getPos() 65 | #Has the player moved 66 | if lastPlayerPos != playerPos: 67 | #print "lastDistanceFromBlock = " + str(lastDistanceFromBlock) 68 | distanceFromBlock = distanceBetweenPoints(randomBlockPos, playerPos) 69 | #print "distanceFromBlock = " + str(distanceFromBlock) 70 | if distanceFromBlock < 2: 71 | #found it! 72 | seeking = False 73 | else: 74 | if distanceFromBlock < lastDistanceFromBlock: 75 | mc.postToChat("Warmer " + str(int(distanceFromBlock)) + " blocks away") 76 | if distanceFromBlock > lastDistanceFromBlock: 77 | mc.postToChat("Colder " + str(int(distanceFromBlock)) + " blocks away") 78 | 79 | lastDistanceFromBlock = distanceFromBlock 80 | 81 | time.sleep(2) 82 | timeTaken = time.time() - timeStarted 83 | mc.postToChat("Well done - " + str(int(timeTaken)) + " seconds to find the diamond") 84 | 85 | time.sleep(5) 86 | 87 | mc.postToChat("www.stuffaboutcode.com") -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/camera.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | import pygame.camera 3 | from time import sleep 4 | from sys import argv 5 | 6 | COLORS = ( (35,0, 222,222,222), 7 | (35,1, 219,125,63), 8 | (35,2, 180,81,189), 9 | (35,3, 107,138,201), 10 | (35,4, 177,166,39), 11 | (35,5, 66,174,57), 12 | (35,6, 208,132,153), 13 | (35,7, 64,64,64), 14 | (35,8, 155,161,161), 15 | (35,9, 47,111,137), 16 | (35,10, 127,62,182), 17 | (35,11, 46,57,142), 18 | (35,12, 79,50,31), 19 | (35,13, 53,71,27), 20 | (35,14, 151,52,49), 21 | (35,15, 26,22,22), 22 | (159,0,210,178,161), 23 | (159,1,162,84,38), 24 | (159,2,150,88,109), 25 | (159,3,113,109,138), 26 | (159,4,186,133,35), 27 | (159,5,104,118,53), 28 | (159,6,162,78,79), 29 | (159,7,58,42,36), 30 | (159,8,135,107,98), 31 | (159,9,87,91,91), 32 | (159,10,118,70,86), 33 | (159,11,74,60,91), 34 | (159,12,77,51,36), 35 | (159,13,76,83,42), 36 | (159,14,143,61,47), 37 | (159,15,37,23,16), 38 | (155,0,232,228,220), 39 | (152,0,164,26,9), 40 | (41,0,250,239,80), 41 | (173,0,19,19,19) ) 42 | 43 | def colorDist(a,b): 44 | return (a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])+(a[2]-b[2])*(a[2]-b[2]) 45 | 46 | def getBestColor(rgb): 47 | bestColor = COLORS[0] 48 | bestDist = 255*255*3 49 | for c in COLORS: 50 | d = colorDist(c[2:],rgb) 51 | if d < bestDist: 52 | bestDist = d 53 | bestColor = c 54 | return bestColor 55 | 56 | mc = Minecraft() 57 | pos = mc.player.getTilePos() 58 | 59 | dither = True 60 | width = 80 61 | if len(argv) >= 2: 62 | width = int(argv[1]) 63 | height = width * 3 // 4 64 | 65 | pygame.camera.init() 66 | camlist = pygame.camera.list_cameras() 67 | if camlist: 68 | cam = pygame.camera.Camera(camlist[0],(640,480)) 69 | current = [[(-1,-1) for y in range(height)] for x in range(width)] 70 | while True: 71 | image = pygame.transform.scale(cam.get_image(), (width,height)) 72 | if not dither: 73 | for x in range(width): 74 | for y in range(height): 75 | block = getBestColor(image.get_at((x,y)))[0:2] 76 | if current[x][y] != block: 77 | mc.setBlock(pos.x+x,pos.y+height-1-y,pos.z,block) 78 | current[x][y] = block 79 | else: 80 | pixels = [[list(image.get_at((x,y))[0:3]) for y in range(height)] for x in range(width)] 81 | for x in range(width): 82 | for y in range(height): 83 | color = getBestColor(pixels[x][y]) 84 | block = color[0:2] 85 | if current[x][y] != block: 86 | mc.setBlock(pos.x+x,pos.y+height-1-y,pos.z,block) 87 | current[x][y] = block 88 | for i in range(3): 89 | err = pixels[x][y][i] - color[2+i] 90 | if x + 1 < width: 91 | pixels[x+1][y][i] += err * 7 // 16 92 | if y + 1 < height: 93 | if 0 < x: 94 | pixels[x-1][y+1][i] += err * 3 // 16 95 | pixels[x][y+1][i] += err * 5 // 16 96 | if x + 1 < width: 97 | pixels[x+1][y+1][i] += err // 16 98 | 99 | else: 100 | mc.postToChat('Camera not found') 101 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/life.py: -------------------------------------------------------------------------------- 1 | # 2 | # Conway's Game of Life 3 | # Copyright (c) 2015 Alexander R. Pruss 4 | # MIT License 5 | # 6 | # life.py [[size [fraction]] 7 | # 8 | # Default size: 50 9 | # If fraction is omitted, you can draw whatever you like. Otherwise, the specified fraction is used. 10 | # E.g., 11 | # life.py 100 0.2 12 | # will draw a 100x100 square, and fill in 20% of the cells. 13 | 14 | from mc import * 15 | from time import sleep 16 | from random import random 17 | import sys 18 | 19 | def evolve(board): 20 | height = len(board) 21 | width = len(board[0]) 22 | newBoard = [[False for i in range(width)] for j in range(height)] 23 | for row in range(height): 24 | for col in range(width): 25 | liveNeighbors = 0 26 | for i in range(-1,2): 27 | for j in range(-1,2): 28 | if row+i >= 0 and row+i < height and col+j >= 0 and col+j < width and (i != 0 or j != 0) and board[row+i][col+j]: 29 | liveNeighbors += 1 30 | if liveNeighbors == 3: 31 | newBoard[row][col] = True 32 | elif board[row][col] and liveNeighbors == 2: 33 | newBoard[row][col] = True 34 | return newBoard 35 | 36 | def border(mc,x0,y0,z0,width,height,block=STONE): 37 | mc.setBlocks(x0-1,y0,z0-1,x0+width,y0,z0-1,block) 38 | mc.setBlocks(x0-1,y0,z0+height,x0+width,y0,z0+height,block) 39 | mc.setBlocks(x0-1,y0,z0,x0-1,y0,z0+height-1,block) 40 | mc.setBlocks(x0+width,y0,z0,x0+width,y0,z0+height-1,block) 41 | 42 | def draw(mc,x0,y0,z0,width,height,oldBoard,newBoard,full,empty): 43 | for row in range(height): 44 | for col in range(width): 45 | if oldBoard == None or oldBoard[row][col] != newBoard[row][col]: 46 | mc.setBlock(x0+col,y0,z0+row,full if newBoard[row][col] else empty) 47 | 48 | 49 | def life(mc,x0,y0,z0,width,height,empty=AIR,full=GOLD_BLOCK,delay=0.5,board=None): 50 | generation = 0 51 | if board == None: 52 | board = [[False for i in range(width)] for j in range(height)] 53 | blocks = mc.getBlocks(x0,y0,z0,x0+width-1,y0,z0+height-1) 54 | for row in range(height): 55 | for col in range(width): 56 | if blocks[col*width+row] != AIR.id: 57 | board[row][col] = True 58 | draw(mc,x0,y0,z0,width,height,None,board,full,empty) 59 | 60 | while True: 61 | if generation % 10 == 0: 62 | mc.postToChat("Generation %d" % generation) 63 | sleep(delay) 64 | newBoard = evolve(board) 65 | draw(mc,x0,y0,z0,width,height,board,newBoard,full,empty) 66 | board = newBoard 67 | generation += 1 68 | 69 | if __name__=='__main__': 70 | mc = Minecraft() 71 | pos = mc.player.getTilePos(); 72 | x0 = pos.x-25 73 | y0 = pos.y 74 | z0 = pos.z-25 75 | if len(sys.argv) >= 2: 76 | width = int(sys.argv[1]) 77 | height = width 78 | else: 79 | width = 50 80 | height = 50 81 | border(mc,x0,y0,z0,width,height) 82 | if len(sys.argv) >= 3: 83 | p = float(sys.argv[2]) 84 | mc.postToChat("Occupied fraction: %.3f" % p) 85 | for row in range(height): 86 | for col in range(width): 87 | mc.setBlock(x0+col,y0,z0+row,GOLD_BLOCK if random() < p else AIR) 88 | else: 89 | mc.postToChat("Set up board and right click with sword when ready to go") 90 | mc.events.clearAll() 91 | while not mc.events.pollBlockHits(): 92 | sleep(0.1) 93 | life(mc,x0,y0,z0,width,height) 94 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/lsystem.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | # L-system with turtle graphics 5 | # 6 | 7 | import collections 8 | import random 9 | import mcpi.settings 10 | from mcturtle import * 11 | 12 | def playProgram(s, dictionary): 13 | for c in s: 14 | if c in dictionary: 15 | dictionary[c]() 16 | 17 | 18 | def transform(c, t): 19 | if isinstance(t, basestring): 20 | return t 21 | else: 22 | r = random.random() 23 | for p,out in t: 24 | if rF][+&F]'} 58 | # 59 | # angle = 22.5 60 | # 61 | # dictionary = { 62 | # '[': t.push, 63 | # ']': t.pop, 64 | # 'F': lambda: t.go(5), 65 | # '-': lambda: t.yaw(-angle), 66 | # '+': lambda: t.yaw(angle), 67 | # '&': lambda: t.pitch(angle), 68 | # '^': lambda: t.pitch(-angle), 69 | # '<': lambda: t.roll(-angle), 70 | # '>': lambda: t.roll(angle), 71 | # '|': lambda: t.pitch(180) 72 | # } 73 | # 74 | # lsystem('F', rules, dictionary, 3) 75 | 76 | 77 | # 78 | # A more complex example with 79 | # rules based on http://www.geekyblogger.com/2008/04/tree-and-l-system.html 80 | # 81 | rules = {'A': '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'} 82 | 83 | #randomized version: 84 | # rules = {'A': [(0.75,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'), 85 | # (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]} 86 | 87 | axiom = 'fA' 88 | angle = 15 89 | thickness = 8 90 | length = 10 if mcpi.settings.isPE else 15; 91 | material = WOOD 92 | t.penwidth(thickness) 93 | t.penblock(material) 94 | 95 | stack = [] 96 | def push(): 97 | global length 98 | global thickness 99 | stack.append((length,thickness)) 100 | t.push() 101 | thickness = thickness * 0.6 102 | length = length * 0.75 103 | if thickness < 1: 104 | thickness = 1 105 | if length <= 1: 106 | t.penblock(LEAVES_OAK_PERMANENT) 107 | t.penwidth(thickness) 108 | 109 | def pop(): 110 | global length 111 | global thickness 112 | length,thickness = stack.pop() 113 | t.pop() 114 | 115 | dictionary = { 116 | '[': push, 117 | ']': pop, 118 | '^': lambda: t.pitch(angle), 119 | '>': lambda: t.roll(angle), 120 | 'f': lambda: t.go(length) 121 | } 122 | 123 | lsystem(axiom, rules, dictionary, 9 if mcpi.settings.isPE else 11) 124 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/input.py: -------------------------------------------------------------------------------- 1 | # 2 | # Windows-only (right now) 3 | # Copyright (c) 2016 Alexander Pruss. MIT License 4 | # 5 | 6 | from platform import system 7 | 8 | if system() == 'Windows': 9 | from ctypes import windll 10 | 11 | LBUTTON = 1 12 | RBUTTON = 2 13 | CANCEL = 3 14 | MBUTTON = 4 15 | BACK = 8 16 | TAB = 9 17 | CLEAR = 12 18 | RETURN = 13 19 | SHIFT = 16 20 | CONTROL = 17 21 | MENU = 18 22 | PAUSE = 19 23 | CAPITAL = 20 24 | KANA = 21 25 | HANGUL = 21 26 | JUNJA = 23 27 | FINAL = 24 28 | HANJA = 25 29 | KANJI = 25 30 | ESCAPE = 27 31 | CONVERT = 28 32 | NONCONVERT = 29 33 | ACCEPT = 30 34 | MODECHANGE = 31 35 | SPACE = 32 36 | PRIOR = 33 37 | NEXT = 34 38 | END = 35 39 | HOME = 36 40 | LEFT = 37 41 | UP = 38 42 | RIGHT = 39 43 | DOWN = 40 44 | SELECT = 41 45 | PRINT = 42 46 | EXECUTE = 43 47 | SNAPSHOT = 44 48 | INSERT = 45 49 | DELETE = 46 50 | HELP = 47 51 | LWIN = 91 52 | RWIN = 92 53 | APPS = 93 54 | NUMPAD0 = 96 55 | NUMPAD1 = 97 56 | NUMPAD2 = 98 57 | NUMPAD3 = 99 58 | NUMPAD4 = 100 59 | NUMPAD5 = 101 60 | NUMPAD6 = 102 61 | NUMPAD7 = 103 62 | NUMPAD8 = 104 63 | NUMPAD9 = 105 64 | MULTIPLY = 106 65 | ADD = 107 66 | SEPARATOR = 108 67 | SUBTRACT = 109 68 | DECIMAL = 110 69 | DIVIDE = 111 70 | F1 = 112 71 | F2 = 113 72 | F3 = 114 73 | F4 = 115 74 | F5 = 116 75 | F6 = 117 76 | F7 = 118 77 | F8 = 119 78 | F9 = 120 79 | F10 = 121 80 | F11 = 122 81 | F12 = 123 82 | F13 = 124 83 | F14 = 125 84 | F15 = 126 85 | F16 = 127 86 | F17 = 128 87 | F18 = 129 88 | F19 = 130 89 | F20 = 131 90 | F21 = 132 91 | F22 = 133 92 | F23 = 134 93 | F24 = 135 94 | NUMLOCK = 144 95 | SCROLL = 145 96 | LSHIFT = 160 97 | RSHIFT = 161 98 | LCONTROL = 162 99 | RCONTROL = 163 100 | LMENU = 164 101 | RMENU = 165 102 | PROCESSKEY = 229 103 | ATTN = 246 104 | CRSEL = 247 105 | EXSEL = 248 106 | EREOF = 249 107 | PLAY = 250 108 | ZOOM = 251 109 | NONAME = 252 110 | PA1 = 253 111 | OEM_CLEAR = 254 112 | XBUTTON1 = 0x05 113 | XBUTTON2 = 0x06 114 | VOLUME_MUTE = 0xAD 115 | VOLUME_DOWN = 0xAE 116 | VOLUME_UP = 0xAF 117 | MEDIA_NEXT_TRACK = 0xB0 118 | MEDIA_PREV_TRACK = 0xB1 119 | MEDIA_PLAY_PAUSE = 0xB3 120 | BROWSER_BACK = 0xA6 121 | BROWSER_FORWARD = 0xA7 122 | 123 | def getPressState(key): 124 | v = windll.user32.GetAsyncKeyState(int(key)) 125 | return bool(0x8000 & v), bool(0x0001 & v) 126 | 127 | def isPressedNow(key): 128 | return bool(0x8000 & windll.user32.GetAsyncKeyState(int(key))) 129 | 130 | def wasPressedSinceLast(key): 131 | return bool(0x0001 & windll.user32.GetAsyncKeyState(int(key))) 132 | 133 | def clearPressBuffer(key): 134 | while wasPressedSinceLast(key): 135 | pass 136 | else: 137 | raise Exception('Platform '+system()+' not supported.') 138 | 139 | if __name__ == '__main__': 140 | from time import sleep 141 | print("Press ESC to exit. Testing spacebar.") 142 | while True: 143 | if wasPressedSinceLast(ESCAPE): 144 | print("Done") 145 | break 146 | now,last = getPressState(ord(' ')) 147 | if now or last: 148 | print now, last 149 | sleep(0.01) 150 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/text.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander R. Pruss 3 | # 4 | 5 | import sys 6 | import time 7 | import mcpi.minecraft as minecraft 8 | 9 | ALIGN_LEFT = 0 10 | ALIGN_RIGHT = 1 11 | ALIGN_CENTER = 2 12 | 13 | # vectors must be minecraft.Vec3 14 | def drawGlyph(mc, pos, forwardVec, upVec, glyph, foreground, background=None, buffer=None): 15 | bitmap = glyph[3] 16 | height = len(bitmap) 17 | width = glyph[0] 18 | offset = glyph[1] 19 | delta = glyph[2] 20 | 21 | for i in range(height): 22 | pixelPos = pos + upVec*(height-1-i) + forwardVec*offset 23 | for j in range(width): 24 | if foreground is not None and 0 != bitmap[i] & (1 << (width-1-j)): 25 | if buffer is not None: 26 | buffer[(pixelPos.x,pixelPos.y,pixelPos.z)] = foreground 27 | else: 28 | mc.setBlock(pixelPos, foreground) 29 | elif background is not None and 0 == bitmap[i] & (1 << (width-1-j)): 30 | if buffer is not None: 31 | buffer[(pixelPos.x,pixelPos.y,pixelPos.z)] = background 32 | else: 33 | mc.setBlock(pixelPos, background) 34 | pixelPos += forwardVec 35 | return pos + forwardVec*delta 36 | 37 | def textLength(font, text): 38 | l = 0 39 | for value in text: 40 | try: 41 | glyph = font[value] 42 | except: 43 | glyph = font[32] 44 | l += glyph[2] 45 | return l 46 | 47 | def drawText(mc, font, pos, forwardVec, upVec, text, foreground=None, background=None, align=ALIGN_LEFT, buffer=None): 48 | try: 49 | text = bytearray(text.encode("cp1252")) 50 | except: 51 | text = bytearray(text.encode("iso8859_1")) 52 | pixelPos = pos.clone() 53 | height = len(font[32][3]) 54 | lines = text.split(b'\n') 55 | pixelPos += upVec * ((len(lines)-1)* height) 56 | lineStart = pixelPos.clone() 57 | for line in lines: 58 | pixelPos = lineStart.clone() 59 | if align == ALIGN_RIGHT: 60 | pixelPos -= forwardVec * textLength(font, line) 61 | elif align == ALIGN_CENTER: 62 | pixelPos -= forwardVec * (0.5 * textLength(font, line)) 63 | 64 | for value in line: 65 | try: 66 | glyph = font[value] 67 | except: 68 | glyph = font[32] 69 | pixelPos = drawGlyph(mc, pixelPos, forwardVec, upVec, glyph, foreground, background, buffer) 70 | 71 | lineStart += upVec * (-height) 72 | return pixelPos 73 | 74 | def angleToTextDirectionCardinal(angle): 75 | return angleToTextDirection(90 * round(angle/90)) 76 | 77 | def angleToTextDirection(angle): 78 | direction = int(round((angle % 360) / 45)) 79 | if direction == 0: 80 | return minecraft.Vec3(-1,0,0) 81 | elif direction == 1: 82 | return minecraft.Vec3(-1,0,-1) 83 | elif direction == 2: 84 | return minecraft.Vec3(0,0,-1) 85 | elif direction == 3: 86 | return minecraft.Vec3(1,0,-1) 87 | elif direction == 4: 88 | return minecraft.Vec3(1,0,0) 89 | elif direction == 5: 90 | return minecraft.Vec3(1,0,1) 91 | elif direction == 6: 92 | return minecraft.Vec3(0,0,1) 93 | else: 94 | return minecraft.Vec3(-1,0,1) 95 | 96 | if __name__ == '__main__': 97 | import fonts 98 | import mcpi.block as block 99 | 100 | mc = minecraft.Minecraft() 101 | pos = mc.player.getPos() 102 | forward = angleToTextDirection(mc.player.getRotation()) 103 | foreground = 169 # sea lantern 104 | background = block.OBSIDIAN 105 | 106 | if len(sys.argv) <= 1: 107 | text = "Hello, world!\nWelcome to Minecraft." 108 | else: 109 | del sys.argv[0] 110 | text = " ".join(sys.argv) 111 | 112 | drawText(mc, fonts.FONTS['metrix7pt'], pos, forward, minecraft.Vec3(0,1,0), text, foreground, background, align=ALIGN_RIGHT) 113 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/scan.py: -------------------------------------------------------------------------------- 1 | from vehicle import Vehicle,getSavePath,getLoadPath 2 | import sys 3 | from mc import * 4 | from time import sleep 5 | import os 6 | 7 | # 8 | # Either:len 9 | # scan name x0 y0 z0 x1 y1 z1 : scan from (x0,y0,z0) relative to player to (x1,y1,z1) relative to player 10 | # scan name y0 : scan from y0 to sky in sword-right-click specified rectangle 11 | # scan name : scan from player feet to sky in sword-right-click specified rectangle 12 | # scan name r : restore scan 13 | # Put a - for the name to be asked. 14 | # 15 | 16 | def getArea(basePos,depth): 17 | mc.postToChat("Sword-right-click other corner of rectangle") 18 | mc.events.clearAll() 19 | while True: 20 | hits = mc.events.pollBlockHits() 21 | if len(hits) > 0: 22 | c1 = (min(basePos.x,hits[0].pos.x),min(basePos.y-depth,hits[0].pos.y),min(basePos.z,hits[0].pos.z)) 23 | c2 = (max(basePos.x,hits[0].pos.x),None,max(basePos.z,hits[0].pos.z)) 24 | break 25 | sleep(0.25) 26 | maxY = c1[1] 27 | for x in range(c1[0],c2[0]+1): 28 | for z in range(c1[2],c2[2]+1): 29 | y = mc.getHeight(x,z) 30 | if y > maxY: 31 | maxY = y 32 | return (c1[0]-basePos.x,c1[1]-basePos.y,c1[2]-basePos.z),(c2[0]-basePos.x,maxY-basePos.y,c2[2]-basePos.z) 33 | 34 | 35 | def save(vehicle,name): 36 | directory = os.path.join(os.path.dirname(sys.argv[0]),"vehicles") 37 | try: 38 | os.mkdir(directory) 39 | except: 40 | pass 41 | if name and name != '-': 42 | path = os.path.join(directory,name+".py") 43 | else: 44 | path = getSavePath('vehicles', 'py') 45 | if not path: 46 | mc.postToChat('Canceled') 47 | return 48 | vehicle.save(path) 49 | mc.postToChat('Saved in '+path) 50 | 51 | def restore(vehicle,name,pos): 52 | directory = os.path.join(os.path.dirname(sys.argv[0]),"vehicles") 53 | if name and name != '-': 54 | path = os.path.join(directory,name+".py") 55 | else: 56 | path = getLoadPath('vehicles', 'py') 57 | if not path: 58 | mc.postToChat('Canceled') 59 | return 60 | vehicle.load(path) 61 | mc.postToChat('Loaded from '+path) 62 | minX = min(x for (x,y,z) in vehicle.baseVehicle) 63 | minY = min(y for (x,y,z) in vehicle.baseVehicle) 64 | minZ = min(z for (x,y,z) in vehicle.baseVehicle) 65 | maxX = max(x for (x,y,z) in vehicle.baseVehicle) 66 | maxY = max(y for (x,y,z) in vehicle.baseVehicle) 67 | maxZ = max(z for (x,y,z) in vehicle.baseVehicle) 68 | mc.postToChat('Erasing') 69 | mc.setBlocks(pos.x+minX,pos.y+minY,pos.z+minZ,pos.x+maxX,pos.y+maxY,pos.z+maxZ,AIR) 70 | mc.postToChat('Drawing') 71 | vehicle.draw(pos.x,pos.y,pos.z,vehicle.baseAngle) 72 | mc.postToChat('Done') 73 | 74 | mc = Minecraft() 75 | basePos = mc.player.getTilePos() 76 | rot = mc.player.getRotation() 77 | vehicle = Vehicle(mc) 78 | #restore(vehicle, "cottage", basePos) 79 | #exit() 80 | 81 | if len(sys.argv) == 8: 82 | corner1 = int(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4]) 83 | corner2 = int(sys.argv[5]),int(sys.argv[6]),int(sys.argv[7]) 84 | elif len(sys.argv) == 2: 85 | corner1,corner2 = getArea(basePos,0) 86 | elif len(sys.argv) == 3: 87 | if sys.argv[2].startswith('r'): 88 | restore(vehicle,sys.argv[1],basePos) 89 | exit() 90 | corner1,corner2 = getArea(basePos,int(sys.argv[2])) 91 | else: 92 | mc.postToChat("scan vehiclename x1 y1 z1 x2 y2 z2") 93 | mc.postToChat("scan vehiclename depth [then right-click with sword on other corner]") 94 | mc.postToChat("scan vehiclename restore") 95 | mc.postToChat("scan vehiclename [then right-click with sword on other corner]") 96 | mc.postToChat("All coordinates are relative to player") 97 | exit() 98 | 99 | mc.postToChat("Scanning region "+str(corner1)+"-"+str(corner2)) 100 | dict = {} 101 | for x in range(corner1[0],corner2[0]+1): 102 | for y in range(corner1[1],corner2[1]+1): 103 | for z in range(corner1[2],corner2[2]+1): 104 | block = vehicle.getBlockWithData(basePos.x+x,basePos.y+y,basePos.z+z) 105 | if block.id != AIR.id: 106 | dict[(x,y,z)] = block 107 | mc.postToChat("Scanned "+str(len(dict))+" blocks") 108 | vehicle.setVehicle(dict, rot) 109 | save(vehicle,sys.argv[1]) 110 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/NeuroPy/README.txt: -------------------------------------------------------------------------------- 1 | NeuroPy 2 | ======= 3 | 4 | 5 | 6 | NeuroPy library written in python to connect, interact and get data from __neurosky's MindWave__ EEG headset. 7 | 8 | This library is based on the minwave mindset communication protocol published by [Neurosky](http:://neurosky.com) and is tested 9 | with Neurosky Mindwave EEG headset. 10 | 11 | ##Installation## 12 | 13 | 1. Download the source distribution (zip file) from [dist directory](https://github.com/lihas/NeuroPy/tree/master/dist) 14 | 2. unzip and navigate to the folder containing _setup.py_ and other files 15 | 3. run the following command: 16 | `python setup.py install` 17 | 18 | ##Usage## 19 | 20 | 1. Importing the module: `from NeuroPy import NeuroPy` 21 | 22 | 2. Initialising: `object1=NeuroPy("COM6",57600)` _#windows_
`object1=NeuroPy("/dev/rfcomm0",57600)` _#linux_ 23 | 24 | Note: Add a True argument to emit the magic hex sequence for a MindFlex toy set up to run at 57600 baud 25 | using the hack described here: http://www.instructables.com/id/Mindflex-EEG-with-raw-data-over-Bluetooth/ 26 | 27 | 3. After initialising , if required the callbacks must be set 28 | then using the start method the library will start fetching data from mindwave 29 | i.e. `object1.start()` 30 | similarly stop method can be called to stop fetching the data 31 | i.e. `object1.stop()` 32 | 33 | ###The data from the device can be obtained using either of the following methods or bot of them together:### 34 | 35 | * Obtaining value: `variable1=object1.attention` _\#to get value of attention_ 36 | >__\#other variables:__ attention,meditation,rawValue,delta,theta,lowAlpha,highAlpha,lowBeta,highBeta,lowGamma,midGamma, poorSignal and blinkStrength 37 | 38 | * Setting callback:a call back can be associated with all the above variables so that a function is called when the variable is updated. Syntax: `setCallBack("variable",callback_function)`
39 | __for eg.__ to set a callback for attention data the syntax will be `setCallBack("attention",callback_function)` 40 | 41 | >__\#other variables:__ attention,meditation,rawValue,delta,theta,lowAlpha,highAlpha,lowBeta,highBeta,lowGamma,midGamma, poorSignal and blinkStrength 42 | 43 | ##Sample Program## 44 | 45 | from NeuroPy import NeuroPy 46 | object1=NeuroPy("COM6") #If port not given 57600 is automatically assumed 47 | #object1=NeuroPy("/dev/rfcomm0") for linux 48 | def attention_callback(attention_value): 49 | "this function will be called everytime NeuroPy has a new value for attention" 50 | print "Value of attention is",attention_value 51 | #do other stuff (fire a rocket), based on the obtained value of attention_value 52 | #do some more stuff 53 | return None 54 | 55 | #set call back: 56 | object1.setCallBack("attention",attention_callback) 57 | 58 | #call start method 59 | object1.start() 60 | 61 | while True: 62 | if(object1.meditation>70): #another way of accessing data provided by headset (1st being call backs) 63 | object1.stop() #if meditation level reaches above 70, stop fetching data from the headset 64 | 65 | 66 | 67 | Copyright (c) sahil singh 68 | All rights reserved. 69 | 70 | Redistribution and use in source and binary forms, with or without modification, 71 | are permitted provided that the following conditions are met: 72 | 73 | 1. Redistributions of source code must retain the above copyright notice, this 74 | list of conditions and the following disclaimer. 75 | 76 | 2. Redistributions in binary form must reproduce the above copyright notice, 77 | this list of conditions and the following disclaimer in the documentation and/ 78 | or other materials provided with the distribution. 79 | 80 | 3. Neither the name of the copyright holder nor the names of its contributors 81 | may be used to endorse or promote products derived from this software without 82 | specific prior written permission. 83 | 84 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 85 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 86 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 87 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 88 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 89 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 90 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 91 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 92 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 93 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 94 | 95 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/import.py: -------------------------------------------------------------------------------- 1 | # 2 | # Import .schematic file 3 | # Copyright (c) 2015 Alexander Pruss 4 | # 5 | # Under MIT License 6 | # 7 | 8 | from mc import * 9 | from sys import argv 10 | import mcpi.nbt as nbt 11 | import json 12 | 13 | NEED_SUPPORT = set((SAPLING.id,WATER_FLOWING.id,LAVA_FLOWING.id,GRASS_TALL.id,34,FLOWER_YELLOW.id, 14 | FLOWER_CYAN.id,MUSHROOM_BROWN.id,MUSHROOM_RED.id,TORCH.id,63,DOOR_WOOD.id,LADDER.id, 15 | 66,68,69,70,DOOR_IRON.id,72,75,76,77,SUGAR_CANE.id,93,94,96,104,105,106,108,111, 16 | 113,115,116,117,122,127,131,132,141,142,143,145,147,148,149,150,151,154,157, 17 | 167,SUNFLOWER.id,176,177,178,183,184,185,186,187,188,189,190,191,192, 18 | 193,194,195,196,197)) 19 | 20 | def getValue(v): 21 | if isinstance(v,nbt.TAG_Compound): 22 | return getCompound(v) 23 | elif isinstance(v,nbt.TAG_List): 24 | out = [] 25 | for a in v: 26 | out.append(getValue(a)) 27 | return out 28 | else: 29 | return v.value 30 | 31 | def getCompound(nbt): 32 | out = {} 33 | for key in nbt: 34 | out[key] = getValue(nbt[key]) 35 | return out 36 | 37 | def nbtToJson(nbt): 38 | return json.dumps(getCompound(nbt)) 39 | 40 | def importSchematic(mc,path,x0,y0,z0,centerX=False,centerY=False,centerZ=False,clear=False,movePlayer=True): 41 | mc.postToChat("Reading "+path); 42 | schematic = nbt.NBTFile(path, "rb") 43 | sizeX = schematic["Width"].value 44 | sizeY = schematic["Height"].value 45 | sizeZ = schematic["Length"].value 46 | 47 | def offset(x,y,z): 48 | return x + (y*sizeZ + z)*sizeX 49 | 50 | px,pz = x0,z0 51 | 52 | if centerX: 53 | x0 -= sizeX // 2 54 | if centerY: 55 | y0 -= sizeY // 2 56 | if centerZ: 57 | z0 -= sizeZ // 2 58 | 59 | corner1 = (x0,y0,z0) 60 | corner2 = (x0+sizeX-1,y0+sizeY-1,z0+sizeZ-1) 61 | 62 | if clear: 63 | mc.setBlocks(corner1,corner2,AIR) 64 | 65 | blocks = schematic["Blocks"].value 66 | data = schematic["Data"].value 67 | tileEntities = schematic["TileEntities"] 68 | tileEntityDict = {} 69 | if not isPE: 70 | for e in tileEntities: 71 | origCoords = e['x'].value,e['y'].value,e['z'].value 72 | e['x'].value += x0 73 | e['y'].value += y0 74 | e['z'].value += z0 75 | tileEntityDict[origCoords] = nbtToJson(e) 76 | check1 = lambda b : b != CARPET.id and b not in NEED_SUPPORT 77 | check2 = lambda b : b in NEED_SUPPORT 78 | check3 = lambda b : b == CARPET.id 79 | mc.postToChat("Rendering"); 80 | for check in (check1,check2,check3): 81 | for y in range(sizeY): 82 | if check == check1 and movePlayer: 83 | mc.player.setTilePos(px,y0+y,pz) 84 | for x in range(sizeX): 85 | for z in range(sizeZ): 86 | i = offset(x,y,z) 87 | b = blocks[i] 88 | if b == AIR.id: 89 | continue 90 | d = data[i] 91 | if not check(b): 92 | if check == check1: 93 | b = AIR.id 94 | d = 0 95 | else: 96 | continue 97 | if b==33 and (d&7)==7: 98 | d = (d&8) 99 | if (x,y,z) in tileEntityDict: 100 | # if b==33: \print x0+x,y0+y,z0+z,x,y,z,b,d,e 101 | mc.setBlockWithNBT(x0+x,y0+y,z0+z,b,d,tileEntityDict[(x,y,z)]) 102 | else: 103 | # if b==33: print x0+x,y0+y,z0+z,x,y,z,b,d 104 | mc.setBlock(x0+x,y0+y,z0+z,b,d) 105 | 106 | print "done" 107 | # TODO: entities 108 | return corner1,corner2 109 | 110 | if __name__=='__main__': 111 | if len(argv) >= 2: 112 | path = argv[1] 113 | else: 114 | import Tkinter 115 | from tkFileDialog import askopenfilename 116 | master = Tkinter.Tk() 117 | master.attributes("-topmost", True) 118 | path = askopenfilename(filetypes=['schematic {*.schematic}'],title="Open") 119 | master.destroy() 120 | if not path: 121 | exit() 122 | 123 | mc = Minecraft() 124 | pos = mc.player.getTilePos() 125 | (corner0,corner1)=importSchematic(mc,path,pos.x,pos.y,pos.z,centerX=True,centerZ=True) 126 | mc.postToChat("Done drawing, putting player on top") 127 | y = corner1[1] 128 | while y > -256 and mc.getBlock(pos.x,y-1,pos.z) == AIR.id: 129 | y -= 1 130 | mc.player.setTilePos(pos.x,y,pos.z) -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpipy.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | 2.0 6 | {ad0b690c-a698-4ce0-9b50-3069e7e8660d} 7 | 8 | scan.py 9 | 10 | . 11 | . 12 | {888888a0-9f3d-457c-b088-3a5042f75d52} 13 | Standard Python launcher 14 | 15 | 16 | False 17 | 18 | 19 | 20 | 21 | 10.0 22 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Code 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | Code 73 | 74 | 75 | 76 | 77 | 78 | 79 | Code 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/castle.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import random 7 | import sys 8 | 9 | def getHeightBelow(x,y,z): 10 | if isPE: 11 | return min(mc.getHeight(x,z),y) 12 | else: 13 | y0 = y - 255 14 | while y > y0: 15 | if mc.getBlock(x,y,z) != AIR.id: 16 | return y 17 | y -= 1 18 | return min(mc.getHeight(x,z),y) 19 | 20 | def rectangularPrism(x1,y1,z1, x2,y2,z2, distribution): 21 | x1 = int(round(x1)) 22 | y1 = int(round(y1)) 23 | z1 = int(round(z1)) 24 | x2 = int(round(x2)) 25 | y2 = int(round(y2)) 26 | z2 = int(round(z2)) 27 | for x in range(min(x1,x2),max(x1,x2)+1): 28 | for y in range(min(y1,y2),max(y1,y2)+1): 29 | for z in range(min(z1,z2),max(z1,z2)+1): 30 | if isinstance(distribution, Block): 31 | mc.setBlock(x,y,z,distribution) 32 | else: 33 | r = random.random() 34 | for p,b in distribution: 35 | r -= p 36 | if r<0: 37 | mc.setBlock(x,y,z,b) 38 | break 39 | 40 | # Note: the first set of coordinates must be smaller than the second 41 | def wall(x1,y1,z1, x2,y2,z2, baseHeight, altHeight, distribution): 42 | x = x1 43 | z = z1 44 | 45 | while True: 46 | if (x-x1+z-z1) % 2 == 0: 47 | height = altHeight 48 | else: 49 | height = baseHeight 50 | y0 = getHeightBelow(x,y1,z) 51 | rectangularPrism(x,y0,z,x,y1+height,z,distribution) 52 | if x >= x2 and z >= z2: 53 | return 54 | if x < x2: 55 | x = x + 1 56 | if z < z2: 57 | z = z + 1 58 | 59 | # Note: the first set of coordinates must be smaller than the second 60 | def moatSide(x1,y1,z1, x2,y2,z2, depth): 61 | x = x1 62 | z = z1 63 | 64 | while True: 65 | y0 = getHeightBelow(x,y1,z) 66 | mc.setBlocks(x,y0-depth+1,z,x,y0,z,WATER_STATIONARY) 67 | if x >= x2 and z >= z2: 68 | return 69 | if x < x2: 70 | x = x + 1 71 | if z < z2: 72 | z = z + 1 73 | 74 | def crenellatedSquare(x1,y1,z1,width,height,altHeight,distribution): 75 | wall(x1, y1, z1, x1+width-1, y1, z1, height, altHeight,distribution) 76 | wall(x1, y1, z1, x1, y1, z1+width-1, height, altHeight,distribution) 77 | wall(x1+width-1, y1, z1, x1+width-1, y1, z1+width-1, height, altHeight,distribution) 78 | wall(x1, y1, z1+width-1, x1+width-1, y1, z1+width-1, height, altHeight,distribution) 79 | 80 | def square(x,y,z,width,height,distribution): 81 | crenellatedSquare(x,y,z,width,height,height,distribution) 82 | 83 | def moatSquare(x1,y1,z1,width,depth): 84 | moatSide(x1, y1, z1, x1+width-1, y1, z1, depth) 85 | moatSide(x1, y1, z1, x1, y1, z1+width-1, depth) 86 | moatSide(x1+width-1, y1, z1, x1+width-1, y1, z1+width-1, depth) 87 | moatSide(x1, y1, z1+width-1, x1+width-1, y1, z1+width-1, depth) 88 | 89 | def crenellatedSquareWithInnerWall(x,y,z,width,baseHeight,altHeight,distribution): 90 | crenellatedSquare(x,y,z,width,baseHeight,altHeight,distribution) 91 | square(x+1,y,z+1,width-2,baseHeight-1,distribution) 92 | 93 | def tower(x,y,z,width,baseHeight,altHeight,innerHeight,distribution): 94 | crenellatedSquareWithInnerWall(x,y,z,width,baseHeight,altHeight,distribution) 95 | rectangularPrism(x+2,y+innerHeight-1,z+2, x+width-3,y+innerHeight-1,z+width-3, distribution) 96 | 97 | mc = Minecraft() 98 | pos = mc.player.getTilePos() 99 | 100 | distribution = ((.05,MOSS_STONE), (.1,Block(STONE_BRICK.id, 1)), (.2,Block(STONE_BRICK.id, 2)), 101 | (.651,Block(STONE_BRICK.id, 0))) 102 | 103 | wallSize = 51 104 | groundY = 1+getHeightBelow(pos.x, pos.y, pos.z) 105 | 106 | # outer walls 107 | mc.postToChat("Outer walls") 108 | crenellatedSquareWithInnerWall(pos.x,groundY,pos.z, wallSize, 9, 10, distribution) 109 | 110 | # towers 111 | mc.postToChat("Towers") 112 | tower(pos.x-7,groundY,pos.z-7, 9, 12, 13, 11, distribution) 113 | tower(pos.x+wallSize-2,groundY,pos.z+wallSize-2, 9, 12, 13, 11, distribution) 114 | tower(pos.x-7,groundY,pos.z+wallSize-2, 9, 12, 13, 11, distribution) 115 | tower(pos.x+wallSize-1,groundY,pos.z-7, 9, 12, 13, 11, distribution) 116 | 117 | # keep 118 | mc.postToChat("Keep") 119 | keepStartX = pos.x+wallSize/4 120 | keepStartZ = pos.z+wallSize/4 121 | keepWidth = wallSize / 6 * 3 122 | tower(keepStartX,groundY, keepStartZ,keepWidth, 16, 17, 15, distribution) 123 | 124 | # moat 125 | if len(sys.argv) <= 1 or sys.argv[1][0] != 'n': 126 | mc.postToChat("Moat") 127 | moatStartX = pos.x - 12 128 | moatStartZ = pos.z - 12 129 | moatInnerSize = wallSize+24 130 | 131 | for i in range(6): 132 | moatSquare(moatStartX-i,groundY-1,moatStartZ-i,moatInnerSize+2*i,2) 133 | 134 | mc.postToChat("Castle done") 135 | -------------------------------------------------------------------------------- /raspberryjammod/socket.lua: -------------------------------------------------------------------------------- 1 | if minetest.request_insecure_environment then 2 | ie = minetest.request_insecure_environment() 3 | else 4 | ie = _G 5 | end 6 | ----------------------------------------------------------------------------- 7 | -- LuaSocket helper module 8 | -- Author: Diego Nehab 9 | -- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $ 10 | ----------------------------------------------------------------------------- 11 | 12 | ----------------------------------------------------------------------------- 13 | -- Declare module and import dependencies 14 | ----------------------------------------------------------------------------- 15 | local base = _G 16 | local string = ie.require("string") 17 | local math = ie.require("math") 18 | local socket 19 | local status,err = pcall(function() socket = ie.require("socket.core") end) 20 | if not status then 21 | socket = ie.require("socket.cx64") 22 | end 23 | 24 | ----------------------------------------------------------------------------- 25 | -- Exported auxiliar functions 26 | ----------------------------------------------------------------------------- 27 | function connect(address, port, laddress, lport) 28 | local sock, err = socket.tcp() 29 | if not sock then return nil, err end 30 | if laddress then 31 | local res, err = sock:bind(laddress, lport, -1) 32 | if not res then return nil, err end 33 | end 34 | local res, err = sock:connect(address, port) 35 | if not res then return nil, err end 36 | return sock 37 | end 38 | 39 | function bind(host, port, backlog) 40 | local sock, err = socket.tcp() 41 | if not sock then return nil, err end 42 | sock:setoption("reuseaddr", true) 43 | local res, err = sock:bind(host, port) 44 | if not res then return nil, err end 45 | res, err = sock:listen(backlog) 46 | if not res then return nil, err end 47 | return sock 48 | end 49 | 50 | -- try = newtry() 51 | 52 | function choose(table) 53 | return function(name, opt1, opt2) 54 | if base.type(name) ~= "string" then 55 | name, opt1, opt2 = "default", name, opt1 56 | end 57 | local f = table[name or "nil"] 58 | if not f then base.error("unknown key (".. base.tostring(name) ..")", 3) 59 | else return f(opt1, opt2) end 60 | end 61 | end 62 | 63 | ----------------------------------------------------------------------------- 64 | -- Socket sources and sinks, conforming to LTN12 65 | ----------------------------------------------------------------------------- 66 | -- create namespaces inside LuaSocket namespace 67 | sourcet = {} 68 | sinkt = {} 69 | 70 | BLOCKSIZE = 2048 71 | 72 | sinkt["close-when-done"] = function(sock) 73 | return base.setmetatable({ 74 | getfd = function() return sock:getfd() end, 75 | dirty = function() return sock:dirty() end 76 | }, { 77 | __call = function(self, chunk, err) 78 | if not chunk then 79 | sock:close() 80 | return 1 81 | else return sock:send(chunk) end 82 | end 83 | }) 84 | end 85 | 86 | sinkt["keep-open"] = function(sock) 87 | return base.setmetatable({ 88 | getfd = function() return sock:getfd() end, 89 | dirty = function() return sock:dirty() end 90 | }, { 91 | __call = function(self, chunk, err) 92 | if chunk then return sock:send(chunk) 93 | else return 1 end 94 | end 95 | }) 96 | end 97 | 98 | sinkt["default"] = sinkt["keep-open"] 99 | 100 | sink = choose(sinkt) 101 | 102 | sourcet["by-length"] = function(sock, length) 103 | return base.setmetatable({ 104 | getfd = function() return sock:getfd() end, 105 | dirty = function() return sock:dirty() end 106 | }, { 107 | __call = function() 108 | if length <= 0 then return nil end 109 | local size = math.min(socket.BLOCKSIZE, length) 110 | local chunk, err = sock:receive(size) 111 | if err then return nil, err end 112 | length = length - string.len(chunk) 113 | return chunk 114 | end 115 | }) 116 | end 117 | 118 | sourcet["until-closed"] = function(sock) 119 | local done 120 | return base.setmetatable({ 121 | getfd = function() return sock:getfd() end, 122 | dirty = function() return sock:dirty() end 123 | }, { 124 | __call = function() 125 | if done then return nil end 126 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) 127 | if not err then return chunk 128 | elseif err == "closed" then 129 | sock:close() 130 | done = 1 131 | return partial 132 | else return nil, err end 133 | end 134 | }) 135 | end 136 | 137 | 138 | sourcet["default"] = sourcet["until-closed"] 139 | 140 | source = choose(sourcet) 141 | 142 | return { connect=connect, bind=bind, choose=choose, source=source } 143 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/brooksc_tntsnake.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Posted to mcpipy.com, created by brooksc and fleap3 aka mrfleap :) 4 | 5 | # This script will: 6 | # 1. Create a snake that will pick a random direction. 7 | # if max_direction is set to 3, it will go backward/forward/left/right. Set to 5 and it goes up/down. 8 | # 2. Head in that direction for a random # of blocks from min_distance and max_distance 9 | # leave a 5 block "plus" of TNT in it's path 10 | # 3. Pick a new direction and go in that direction 11 | # It should not double back on itself or go the same direction... 12 | 13 | 14 | 15 | 16 | #import the minecraft.py module from the minecraft directory 17 | import mcpi.minecraft as minecraft 18 | #import minecraft block module 19 | import mcpi.block as block 20 | #import time, so delays can be used 21 | import time 22 | import random 23 | import math 24 | import server 25 | 26 | def new_direction(old_direction): 27 | max_direction = 5 28 | # max_direction = 3 29 | 30 | directions = ["Forward", "Left", "Right", "Backward", "Up", "Down"] 31 | direction_opposite = [3,2,1,0,5,4] 32 | direction = old_direction 33 | while direction == old_direction and direction != direction_opposite[direction]: 34 | direction = random.randint(0, max_direction) 35 | print "changing direction from %s to %s" % (directions[old_direction], directions[direction]) 36 | return direction 37 | 38 | if __name__ == "__main__": 39 | 40 | #Connect to minecraft by creating the minecraft object 41 | # - minecraft needs to be running and in a game 42 | mc = minecraft.Minecraft.create(server.address) 43 | mc.setBlocks(-10,-10,-10,10,100,10,block.AIR) 44 | 45 | x = 0.0 46 | y = 0.0 47 | z = 0.0 48 | max_x = 50 49 | max_y = 10 50 | max_z = 50 51 | min_distance = 10 52 | max_distance = 100 53 | direction = -1 54 | directions = ["Forward", "Left", "Right", "Backward", "Up", "Down"] 55 | while True: 56 | mc.setBlock(x, y, z, block.DIAMOND_BLOCK) 57 | time.sleep(2) 58 | 59 | direction = new_direction(direction) 60 | duration = random.randint(min_distance, max_distance) 61 | print "New Roll: %s direction (%d) for %s more cycles!" % (directions[direction], direction, duration) 62 | # time.sleep(3) 63 | while duration > 0: 64 | mc.setBlock(x, y, z, block.TNT) 65 | if direction == 0 or direction == 3: 66 | # Going forward or back Adjust Z 67 | mc.setBlock(x, y, z-1, block.TNT) 68 | mc.setBlock(x, y, z+1, block.TNT) 69 | mc.setBlock(x, y-1, z, block.TNT) 70 | mc.setBlock(x, y+1, z, block.TNT) 71 | elif direction == 1 or direction == 2: 72 | # Going left or right Adjust X 73 | mc.setBlock(x-1, y, z, block.TNT) 74 | mc.setBlock(x+1, y, z, block.TNT) 75 | mc.setBlock(x, y-1, z, block.TNT) 76 | mc.setBlock(x, y+1, z, block.TNT) 77 | else: 78 | # Going up or down, Adjust Y 79 | mc.setBlock(x-1, y, z, block.TNT) 80 | mc.setBlock(x+1, y, z, block.TNT) 81 | mc.setBlock(x, y, z-1, block.TNT) 82 | mc.setBlock(x, y, z+1, block.TNT) 83 | time.sleep(.25) 84 | if direction == 0: 85 | # forward 86 | x += 1 87 | if math.fabs(x) > max_x: 88 | direction = new_direction(direction) 89 | x -= 2 90 | elif direction == 1: 91 | # left 92 | z -= 1 93 | if math.fabs(z) > max_z: 94 | direction = new_direction(direction) 95 | z += 2 96 | elif direction == 2: 97 | # right 98 | z += 1 99 | if math.fabs(z) > max_z: 100 | direction = new_direction(direction) 101 | z -= 2 102 | elif direction == 3: 103 | # backward 104 | x -= 1 105 | if math.fabs(x) > max_x: 106 | direction = new_direction(direction) 107 | x += 2 108 | elif direction == 4: 109 | # up 110 | y += 1 111 | if math.fabs(y) > max_y: 112 | # if it's going further than max_y allows, turn it around 113 | direction = new_direction(direction) 114 | y -= 2 115 | elif direction == 5: 116 | # down 117 | y -= 1 118 | if math.fabs(y) > max_y: 119 | # if it's going further than max_y allows, turn it around 120 | direction = new_direction(direction) 121 | y += 2 122 | else: 123 | print "Error! %s" % (direction) 124 | 125 | duration -= 1 126 | print "Going %s for %s more cycles" % (directions[direction],duration) 127 | 128 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mcpi/connection.py: -------------------------------------------------------------------------------- 1 | 2 | import socket 3 | import select 4 | import sys 5 | import atexit 6 | import os 7 | import platform 8 | import base64 9 | from hashlib import md5 10 | from util import flatten_parameters_to_string 11 | 12 | """ @author: Aron Nieminen, Mojang AB""" 13 | 14 | class RequestError(Exception): 15 | pass 16 | 17 | class Connection: 18 | """Connection to a Minecraft Pi game""" 19 | RequestFailed = "Fail" 20 | 21 | def __init__(self, address=None, port=None): 22 | self.windows = (platform.system() == "Windows" or platform.system().startswith("CYGWIN_NT")) 23 | if address==None: 24 | try: 25 | address = os.environ['MINECRAFT_API_HOST'] 26 | except KeyError: 27 | address = "localhost" 28 | if port==None: 29 | try: 30 | port = int(os.environ['MINECRAFT_API_PORT']) 31 | except KeyError: 32 | port = 4711 33 | if int(sys.version[0]) >= 3: 34 | self.send = self.send_python3 35 | self.send_flat = self.send_flat_python3 36 | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 37 | self.socket.connect((address, port)) 38 | self.readFile = self.socket.makefile("r") 39 | self.lastSent = "" 40 | if self.windows: 41 | atexit.register(self.close) 42 | 43 | def __del__(self): 44 | if self.windows: 45 | self.close() 46 | try: 47 | atexit.unregister(self.close) 48 | except: 49 | pass 50 | 51 | def close(self): 52 | try: 53 | if self.windows: 54 | # ugly hack to block until all sending is completed 55 | self.sendReceive("world.getBlock",0,0,0) 56 | except: 57 | pass 58 | try: 59 | self.socket.close() 60 | except: 61 | pass 62 | 63 | @staticmethod 64 | def tohex(data): 65 | return "".join((hex(b) for b in data)) 66 | 67 | def authenticate(self, username, password): 68 | challenge = self.sendReceive("world.getBlock",0,0,0) 69 | if challenge.startswith("security.challenge "): 70 | salt = challenge[19:].rstrip() 71 | auth = md5(salt+":"+username+":"+password).hexdigest() 72 | self.send("security.authenticate", auth) 73 | 74 | def drain(self): 75 | """Drains the socket of incoming data""" 76 | while True: 77 | readable, _, _ = select.select([self.socket], [], [], 0.0) 78 | if not readable: 79 | break 80 | data = self.socket.recv(1500) 81 | if not data: 82 | self.socket.close() 83 | raise ValueError('Socket got closed') 84 | e = "Drained Data: <%s>\n"%data.strip() 85 | e += "Last Message: <%s>\n"%self.lastSent.strip() 86 | sys.stderr.write(e) 87 | 88 | def send(self, f, *data): 89 | """Sends data. Note that a trailing newline '\n' is added here""" 90 | s = "%s(%s)\n"%(f, flatten_parameters_to_string(data)) 91 | #print "f,data:",f,data 92 | self.drain() 93 | self.lastSent = s 94 | self.socket.sendall(s) 95 | 96 | def send_python3(self, f, *data): 97 | """Sends data. Note that a trailing newline '\n' is added here""" 98 | s = "%s(%s)\n"%(f, flatten_parameters_to_string(data)) 99 | #print "f,data:",f,data 100 | self.drain() 101 | self.lastSent = s 102 | self.socket.sendall(s.encode("utf-8")) 103 | 104 | def send_flat(self, f, data): 105 | """Sends data. Note that a trailing newline '\n' is added here""" 106 | # print "f,data:",f,list(data) 107 | s = "%s(%s)\n"%(f, ",".join(data)) 108 | self.drain() 109 | self.lastSent = s 110 | self.socket.sendall(s) 111 | 112 | def send_flat_python3(self, f, data): 113 | """Sends data. Note that a trailing newline '\n' is added here""" 114 | # print "f,data:",f,list(data) 115 | s = "%s(%s)\n"%(f, ",".join(data)) 116 | self.drain() 117 | self.lastSent = s 118 | self.socket.sendall(s.encode("utf-8")) 119 | 120 | def receive(self): 121 | """Receives data. Note that the trailing newline '\n' is trimmed""" 122 | s = self.readFile.readline().rstrip("\n") 123 | if s == Connection.RequestFailed: 124 | raise RequestError("%s failed"%self.lastSent.strip()) 125 | return s 126 | 127 | def sendReceive(self, *data): 128 | """Sends and receive data""" 129 | self.send(*data) 130 | return self.receive() 131 | 132 | def sendReceive_flat(self, f, data): 133 | """Sends and receive data""" 134 | self.send_flat(f, data) 135 | return self.receive() 136 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/pysanka.py: -------------------------------------------------------------------------------- 1 | from mc import * 2 | import sys 3 | import os 4 | from ast import literal_eval 5 | from PIL import Image 6 | 7 | def parseBlock(s): 8 | try: 9 | return literal_eval(s) 10 | except: 11 | return globals()[s.upper()] 12 | 13 | def egg(block=GOLD_BLOCK, h=40, a=2.5, b=1, c=0.1): 14 | def radius(y): 15 | if y < 0 or y >= h: 16 | return 0 17 | l = y / float(h-1) 18 | # Formula from: http://www.jolyon.co.uk/myresearch/image-analysis/egg-shape-modelling/ 19 | return h*a*exp((-0.5*l*l+c*l-.5*c*c)/(b*b))*sqrt(1-l)*sqrt(l)/(pi*b) 20 | 21 | for y in range(0,h): 22 | r = radius(y) 23 | minimumr = min(r-2,radius(y-1),radius(y+1)) 24 | for x in range(-h,h+1): 25 | for z in range(-h,h+1): 26 | myr = sqrt(x*x + z*z) 27 | if myr <= r and minimumr <= myr: 28 | if x==0 and z==0: 29 | theta = 0 30 | else: 31 | theta = atan2(z,x)+pi/2 32 | yield (x,y,z,block,theta % (2*pi)) 33 | 34 | COLORS = ( (35,0, 222,222,222), 35 | (35,1, 219,125,63), 36 | (35,2, 180,81,189), 37 | (35,3, 107,138,201), 38 | (35,4, 177,166,39), 39 | (35,5, 66,174,57), 40 | (35,6, 208,132,153), 41 | (35,7, 64,64,64), 42 | (35,8, 155,161,161), 43 | (35,9, 47,111,137), 44 | (35,10, 127,62,182), 45 | (35,11, 46,57,142), 46 | (35,12, 79,50,31), 47 | (35,13, 53,71,27), 48 | (35,14, 151,52,49), 49 | (35,15, 26,22,22), 50 | (159,0,210,178,161), 51 | (159,1,162,84,38), 52 | (159,2,150,88,109), 53 | (159,3,113,109,138), 54 | (159,4,186,133,35), 55 | (159,5,104,118,53), 56 | (159,6,162,78,79), 57 | (159,7,58,42,36), 58 | (159,8,135,107,98), 59 | (159,9,87,91,91), 60 | (159,10,118,70,86), 61 | (159,11,74,60,91), 62 | (159,12,77,51,36), 63 | (159,13,76,83,42), 64 | (159,14,143,61,47), 65 | (159,15,37,23,16), 66 | (155,0,232,228,220), 67 | (152,0,164,26,9), 68 | (41,0,250,239,80), 69 | (173,0,19,19,19) ) 70 | 71 | def colorDist(a,b): 72 | return (a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])+(a[2]-b[2])*(a[2]-b[2]) 73 | 74 | def getBestColor(rgb): 75 | bestColor = COLORS[0] 76 | bestDist = 255*255*3 77 | for c in COLORS: 78 | d = colorDist(c[2:],rgb) 79 | if d < bestDist: 80 | bestDist = d 81 | bestColor = c 82 | return bestColor 83 | 84 | def getPixel(image, x, y): 85 | rgb = image.getpixel(( image.size[0]-1-floor( x * image.size[0] ), image.size[1]-1-floor( y * image.size[1] ) )) 86 | return getBestColor(rgb)[0:2] 87 | 88 | mc = Minecraft() 89 | 90 | if len(sys.argv) > 1: 91 | filename = sys.argv[1] 92 | if not os.path.isfile(filename): 93 | filename = os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + filename 94 | else: 95 | filename = os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + "pysanka.jpg" 96 | 97 | if len(sys.argv) > 2: 98 | height = int(sys.argv[2]) 99 | else: 100 | height = 100 101 | 102 | oval = False 103 | 104 | if len(sys.argv) > 3: 105 | if sys.argv[3] == "oval": 106 | oval = True 107 | else: 108 | repeat = int(sys.argv[3]) 109 | else: 110 | repeat = 2 111 | 112 | pos = mc.player.getPos() 113 | 114 | if oval: 115 | image = Image.open(filename).convert('RGBA') 116 | 117 | first = None 118 | last = None 119 | 120 | start = [None] * image.size[1] 121 | stop = [None] * image.size[1] 122 | 123 | for y in range(image.size[1]): 124 | for x in range(image.size[0]): 125 | _,_,_,alpha = image.getpixel((x,y)) 126 | if alpha == 255: 127 | start[y] = x 128 | break 129 | for x in range(image.size[0]-1,-1,-1): 130 | _,_,_,alpha = image.getpixel((x,y)) 131 | if alpha == 255: 132 | stop[y] = x 133 | break 134 | if start[y] is not None: 135 | if first is None: 136 | first = y 137 | last = y 138 | 139 | assert first is not None 140 | 141 | for (x,y,z,block,theta) in egg(h=height,block=None): 142 | imageY = first + int(float(height-1-y)/height*(last-first+1)) 143 | if imageY < first: 144 | imageY = first 145 | if imageY > last: 146 | imageY = last 147 | imageX = start[imageY]+ int((0.5 - 0.5 * sin(theta)) * (stop[imageY]-start[imageY])) 148 | if imageX < start[imageY]: 149 | imageX = start[imageY] 150 | if imageX > stop[imageY]: 151 | imageX = stop[imageY] 152 | mc.setBlock(x+pos.x,y+pos.y,z+pos.z, getBestColor(image.getpixel((imageX,imageY))[0:3])[0:2]) 153 | else: 154 | image = Image.open(filename).convert('RGB') 155 | 156 | for (x,y,z,block,theta) in egg(h=height,block=None): 157 | mc.setBlock(x+pos.x,y+pos.y,z+pos.z,getPixel(image, (theta * repeat / (2*pi)) % 1, y / float(height))) 158 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/davef21370_maze.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Quick rough & ready maze generator for Minecraft Pi edition. 4 | # Dave Finch 2013 5 | 6 | # mcpipy.com retrieved from URL below, written by davef21370 7 | # https://github.com/brooksc/mcpipy/blob/master/davef21370_maze.py 8 | 9 | import mcpi.minecraft as minecraft 10 | import mcpi.block as block 11 | import sys, random 12 | from random import randint as rand 13 | import server 14 | 15 | 16 | # Connect to Minecraft. 17 | try: 18 | mc = minecraft.Minecraft.create(server.address) 19 | except: 20 | print "Cannot connect to Minecraft." 21 | sys.exit(0) 22 | 23 | # Create a function for picking a random direction. 24 | def randDir(): 25 | r = rand(0,3) 26 | if r == 0: rv = (0,-1) # Up. 27 | if r == 1: rv = (0,1) # Down. 28 | if r == 2: rv = (-1,0) # Left. 29 | if r == 3: rv = (1,0) # Right. 30 | return rv 31 | 32 | # Create a function to initialize the maze. 33 | # w and h are the width and height respectively. 34 | def initMaze(w,h): 35 | global maze,spl 36 | 37 | # Create a 2 dimensional array. 38 | maze = [[0]*h for x in range(w)] 39 | 40 | # Create four walls around the maze. 41 | # 1=wall, 0=walkway. 42 | for x in range(0,w): 43 | maze[x][0] = maze[x][h-1] = 1 44 | makeWall(ppos.x+x,ppos.z+0) 45 | makeWall(ppos.x+x,ppos.z+h-1) 46 | for y in range(0,mazeYSize): 47 | maze[0][y] = maze[w-1][y] = 1 48 | makeWall(ppos.x,ppos.z+y) 49 | makeWall(ppos.x+w-1,ppos.z+y) 50 | 51 | # Make every other cell a starting point. 52 | # 2=starting point. 53 | # Also create a list of these points to speed up the main loop. 54 | spl = [] 55 | for y in range(2,h-2,2): 56 | for x in range(2,w-2,2): 57 | maze[x][y] = 2 58 | spl.append((x,y)) 59 | # Shuffle the list of points and we can choose a random point by 60 | # simply "popping" it off the list. 61 | random.shuffle(spl) 62 | 63 | def makeWall(x,z): 64 | mc.setBlock(x,ppos.y,z,block.STONE) 65 | mc.setBlock(x,ppos.y+1,z,block.STONE) 66 | mc.setBlock(x,ppos.y+2,z,block.STONE) 67 | 68 | # Define the X and Y size of the maze including the outer walls. 69 | # These values aren't checked but must be positive odd integers above 3. 70 | mazeXSize = 35 71 | mazeYSize = 35 72 | 73 | # Set the maximum length of a wall. 74 | maxWallLen = 1 75 | 76 | # Find position of player and set base of maze 3 blocks lower. 77 | ppos = mc.player.getPos() 78 | ppos.y -= 3 79 | 80 | # Clear an area for the maze. 81 | for x in range(0,mazeXSize-1): 82 | for z in range(mazeYSize-1): 83 | mc.setBlock(ppos.x+x,ppos.y,ppos.z+z,block.STONE) 84 | for y in range(1,5): 85 | mc.setBlock(ppos.x+x,ppos.y+y,ppos.z+z,block.AIR) 86 | 87 | # Create an empty maze. 88 | initMaze(mazeXSize,mazeYSize) 89 | 90 | # Loop until we have no more starting points (2's in the empty maze) 91 | while filter(lambda x: 2 in x, maze): 92 | # Get the X and Y values of the first point in our randomized list. 93 | rx = spl[0][0] 94 | ry = spl[0][1] 95 | # Pop the first entry in the list, this deletes it and the rest move down. 96 | spl.pop(0) 97 | # Check to see if our chosen point is still a valid starting point. 98 | ud = False 99 | if maze[rx][ry] == 2: 100 | ud = True 101 | # Pick a random wall length up to the maximum. 102 | rc = rand(0,maxWallLen) 103 | # Pick a random direction. 104 | rd = randDir() 105 | fc = rd 106 | loop = True 107 | while loop: 108 | # Look in each direction, if the current wall being built is stuck inside itself start again. 109 | if maze[rx][ry-2] == 3 and maze[rx][ry+2] == 3 and maze[rx-2][ry] == 3 and maze[rx+2][ry] == 3: 110 | # 111 | # Code to clear maze area required 112 | # 113 | initMaze(mazeXSize,mazeYSize) 114 | break 115 | # Look ahead to see if we're okay to go in this direction..... 116 | cx = rx + (rd[0]*2) 117 | cy = ry + (rd[1]*2) 118 | nc = maze[cx][cy] 119 | if nc != 3: 120 | for i in range(0,2): 121 | maze[rx][ry] = 3 122 | makeWall(ppos.x+rx,ppos.z+ry) 123 | rx += rd[0] 124 | ry += rd[1] 125 | # .....if not choose another direction. 126 | else: rd = randDir() 127 | # If we hit an existing wall break out of the loop. 128 | if nc == 1: loop = False 129 | # Update our wall length counter. When this hits zero pick another direction. 130 | # This also makes sure the new direction isn't the same as the current one. 131 | rc -= 1 132 | if rc <= 0: 133 | rc = rand(0,maxWallLen) 134 | dd = rd 135 | de = (fc[0]*-1,fc[1]*-1) 136 | while dd == rd or rd == de: 137 | rd = randDir() 138 | # The latest wall has been built so change all 3's (new wall) to 1's (existing wall) 139 | if ud: 140 | for x in range(0,mazeXSize): 141 | for y in range(0,mazeYSize): 142 | if maze[x][y] == 3: maze[x][y] = 1 143 | 144 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/mandelbrot.py: -------------------------------------------------------------------------------- 1 | # 2 | # Code under the MIT license by Alexander Pruss 3 | # 4 | 5 | from mc import * 6 | import mcpi.settings 7 | import cmath 8 | import time 9 | import sys 10 | 11 | ESCAPE = 256 12 | if len(sys.argv) < 2: 13 | SIZE = 640 if not mcpi.settings.isPE else 400 14 | else: 15 | SIZE = int(sys.argv[1]) 16 | 17 | if len(sys.argv) < 3: 18 | formula = lambda z,c : z * z + c 19 | else: 20 | formula = eval('lambda z,c : '+sys.argv[2]) 21 | 22 | black = WOOL_BLACK 23 | #palette = ( WOOL_WHITE, WOOL_ORANGE, WOOL_MAGENTA, WOOL_LIGHT_BLUE, 24 | # WOOL_YELLOW, WOOL_LIME, WOOL_PINK, WOOL_GRAY, WOOL_LIGHT_GRAY, 25 | # WOOL_CYAN, WOOL_PURPLE, WOOL_BLUE, WOOL_BROWN, WOOL_GREEN, 26 | # WOOL_RED, 152 ) 27 | 28 | 29 | # palette generated by solving traveling salesman problems in RGB space 30 | #palette = (WOOL_WHITE,WOOL_LIGHT_GRAY,WOOL_LIGHT_BLUE,WOOL_CYAN,WOOL_LIME,WOOL_YELLOW,WOOL_ORANGE,152,WOOL_RED,WOOL_BROWN,WOOL_GREEN,WOOL_GRAY,WOOL_BLUE,WOOL_PURPLE,WOOL_MAGENTA,WOOL_PINK) 31 | palette = (WOOL_WHITE,HARDENED_CLAY_STAINED_WHITE,WOOL_PINK,WOOL_MAGENTA,WOOL_PURPLE,HARDENED_CLAY_STAINED_LIGHT_BLUE,HARDENED_CLAY_STAINED_CYAN,HARDENED_CLAY_STAINED_PURPLE,HARDENED_CLAY_STAINED_LIGHT_GRAY,HARDENED_CLAY_STAINED_MAGENTA,HARDENED_CLAY_STAINED_PINK,HARDENED_CLAY_STAINED_RED,WOOL_RED,REDSTONE_BLOCK,HARDENED_CLAY_STAINED_ORANGE,WOOL_ORANGE,HARDENED_CLAY_STAINED_YELLOW,WOOL_YELLOW,WOOL_LIME,HARDENED_CLAY_STAINED_LIME,HARDENED_CLAY_STAINED_GREEN,WOOL_GREEN,HARDENED_CLAY_STAINED_GRAY,WOOL_BROWN,HARDENED_CLAY_STAINED_BROWN,WOOL_GRAY,HARDENED_CLAY_STAINED_BLUE,WOOL_BLUE,WOOL_CYAN,WOOL_LIGHT_BLUE,WOOL_LIGHT_GRAY) 32 | 33 | def escapeTime(c): 34 | i = 0 35 | z = c 36 | try: 37 | while abs(z) < 2 and i < ESCAPE: 38 | i = i + 1 39 | z = formula(z,c) 40 | return i 41 | except: 42 | return -1 43 | 44 | # 45 | # we could of course just do for x in range(0,size): for y in range(0,size): yield(x,y) 46 | # but it will make users happier if we start at the player 47 | # 48 | 49 | def loopGenerator(size, cenX, cenY): 50 | yield (cenX, cenY) 51 | for r in range(1,size): 52 | # right line segment 53 | if cenX+r < size: 54 | y = cenY - r 55 | if y < 0: 56 | y = 0 57 | while y < cenY + r and y < size: 58 | yield (cenX+r, y) 59 | y += 1 60 | # top line segment 61 | if cenY+r < size: 62 | x = cenX + r 63 | if x >= size: 64 | x = size - 1 65 | while cenX - r < x and 0 <= x: 66 | yield (x, cenY+r) 67 | x -= 1 68 | # left line segment 69 | if 0 <= cenX-r: 70 | y = cenY + r 71 | if y >= size: 72 | y = size - 1 73 | while cenY - r < y and 0 <= y: 74 | yield (cenX-r, y) 75 | y -= 1 76 | # bottom line segment 77 | if 0 <= cenY-r: 78 | x = cenX - r 79 | if x < 0: 80 | x = 0 81 | while x < cenX + r and x < size: 82 | yield(x, cenY - r) 83 | x += 1 84 | 85 | def pollZoom(): 86 | global lastHitEvent 87 | events = mc.events.pollBlockHits() 88 | if len(events) == 0: 89 | return lastHitEvent != None 90 | lastHitEvent = events[-1] 91 | return True 92 | 93 | def toComplex(x,y): 94 | return complex((x - centerMC.x) * scale + centerCx.real, 95 | (y - centerMC.z) * scale + centerCx.imag) 96 | 97 | def draw(): 98 | count = 0 99 | for (x,y) in loopGenerator(SIZE, SIZE/2, SIZE/2): 100 | mcX = x + centerMC.x - SIZE/2 101 | mcY = y + centerMC.z - SIZE/2 102 | c = toComplex(mcX, mcY) 103 | 104 | esc = escapeTime(c) 105 | if esc < 0: 106 | block = AIR 107 | elif esc < ESCAPE: 108 | block = palette[esc % len(palette)] 109 | else: 110 | block = black 111 | mc.setBlock(mcX, centerMC.y, mcY,block) 112 | if count >= 1000: 113 | if pollZoom(): 114 | break 115 | else: 116 | count = 0 117 | else: 118 | count += 1 119 | 120 | def formatComplex(z): 121 | return "%.2g+%.2gi" % (z.real,z.imag) 122 | 123 | def getInfo(): 124 | return ( "Center: "+formatComplex(centerCx)+", range from "+ 125 | formatComplex(toComplex(centerMC.x - SIZE/2, centerMC.z - SIZE/2))+" to "+ 126 | formatComplex(toComplex(centerMC.x + SIZE/2 - 1, centerMC.z + SIZE/2 - 1)) ) 127 | 128 | mc = Minecraft() 129 | centerMC = mc.player.getPos() 130 | centerMC.ifloor() 131 | adjustedPlayer = centerMC.clone() 132 | adjustedPlayer.y += 1 133 | centerCx = complex(0,0) 134 | scale = 4. / SIZE 135 | lastHitEvent = None 136 | 137 | while True: 138 | mc.player.setPos(adjustedPlayer) 139 | mc.postToChat(getInfo()) 140 | draw() 141 | mc.postToChat("Rendered") 142 | while not pollZoom(): 143 | time.sleep(0.25) 144 | if ( lastHitEvent.pos.y != centerMC.y or 145 | lastHitEvent.pos.x < centerMC.x - SIZE / 2 or 146 | lastHitEvent.pos.x >= centerMC.x + SIZE / 2 or 147 | lastHitEvent.pos.z < centerMC.z - SIZE / 2 or 148 | lastHitEvent.pos.z >= centerMC.z + SIZE / 2 ): 149 | mc.postToChat("resetting") 150 | centerCx = complex(0,0) 151 | scale = 4. / SIZE 152 | else: 153 | mc.postToChat("zooming") 154 | centerCx = toComplex(lastHitEvent.pos.x,lastHitEvent.pos.z) 155 | scale /= 2 156 | lastHitEvent = None 157 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/astrotutor_magic.py: -------------------------------------------------------------------------------- 1 | # mcpipy.com retrieved from URL below, written by astrotutor 2 | # http://www.minecraftforum.net/topic/1698103-camerasetpos-not-working-magic-trick/ 3 | 4 | import mcpi.minecraft as minecraft 5 | import mcpi.block as block 6 | import time as time 7 | 8 | mc = minecraft.Minecraft.create() 9 | 10 | # Find player position 11 | playerPos = mc.player.getPos() 12 | 13 | #Find block type below player 14 | Block = mc.getBlock(playerPos.x, playerPos.y - 1, playerPos.z) 15 | 16 | # Set camera to above player position 17 | mc.camera.setFollow() 18 | 19 | # Build 1st wall across in front to right 20 | 21 | length = 0 22 | height = 0 23 | 24 | while length < 5: 25 | 26 | mc.setBlock(playerPos.x + 2, playerPos.y + height, playerPos.z - 2 + length, 4) 27 | 28 | while height < 3: 29 | mc.setBlock(playerPos.x + 2, playerPos.y + height, playerPos.z - 2 + length, 4) 30 | time.sleep(0.2) 31 | height += 1 32 | 33 | length += 1 34 | height = 0 35 | 36 | # Build second wall on right towards 37 | 38 | length = 0 39 | height = 0 40 | 41 | while length < 4: 42 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z + 2, 4) 43 | 44 | while height < 3: 45 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z + 2, 4) 46 | time.sleep(0.2) 47 | height += 1 48 | 49 | length += 1 50 | height = 0 51 | 52 | # Build third wall on left towards 53 | 54 | length = 0 55 | height = 0 56 | 57 | while length < 4: 58 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z - 2, 4) 59 | 60 | while height < 3: 61 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z - 2 , 4) 62 | time.sleep(0.2) 63 | height += 1 64 | 65 | length += 1 66 | height = 0 67 | 68 | # Build last wall behind to right 69 | 70 | length = 0 71 | height = 0 72 | 73 | while length < 3: 74 | mc.setBlock(playerPos.x - 2, playerPos.y + height, playerPos.z - 1 + length, 4) 75 | 76 | while height < 3: 77 | mc.setBlock(playerPos.x - 2, playerPos.y + height, playerPos.z - 1 + length, 4) 78 | time.sleep(0.2) 79 | height += 1 80 | 81 | length += 1 82 | height = 0 83 | 84 | # Build the roof 85 | 86 | length = 1 87 | width = 0 88 | 89 | while length < 4: 90 | 91 | while width < 3: 92 | mc.setBlock(playerPos.x + 2 - length, playerPos.y + 2, playerPos.z - 1 + width, 5) 93 | time.sleep(0.2) 94 | width += 1 95 | 96 | length += 1 97 | width = 0 98 | 99 | # Create void below house 100 | 101 | length = 1 102 | width = 0 103 | 104 | while length < 4: 105 | 106 | while width < 3: 107 | mc.setBlock(playerPos.x + 2 - length, playerPos.y - 2, playerPos.z - 1 + width, 0) 108 | time.sleep(0.2) 109 | width += 1 110 | 111 | length += 1 112 | width = 0 113 | 114 | length = 1 115 | width = 0 116 | 117 | while length < 4: 118 | 119 | while width < 3: 120 | mc.setBlock(playerPos.x + 2 - length, playerPos.y - 3, playerPos.z - 1 + width, 0) 121 | time.sleep(0.2) 122 | width += 1 123 | 124 | length += 1 125 | width = 0 126 | 127 | # Remove the floor 128 | 129 | length = 1 130 | width = 0 131 | 132 | while length < 4: 133 | 134 | while width < 3: 135 | mc.setBlock(playerPos.x + 2 - length, playerPos.y - 1, playerPos.z - 1 + width, 0) 136 | time.sleep(0.2) 137 | width += 1 138 | 139 | length += 1 140 | width = 0 141 | 142 | # Build the floor 143 | 144 | 145 | 146 | length = 1 147 | width = 0 148 | 149 | while length < 4: 150 | 151 | while width < 3: 152 | mc.setBlock(playerPos.x + 2 - length, playerPos.y - 1, playerPos.z - 1 + width, Block) 153 | time.sleep(0.2) 154 | width += 1 155 | 156 | length += 1 157 | width = 0 158 | 159 | # Remove the roof 160 | 161 | length = 1 162 | width = 0 163 | 164 | while length < 4: 165 | 166 | while width < 3: 167 | mc.setBlock(playerPos.x + 2 - length, playerPos.y + 2, playerPos.z - 1 + width, 0) 168 | time.sleep(0.2) 169 | width += 1 170 | 171 | length += 1 172 | width = 0 173 | 174 | # Remove 1st wall across in front to right 175 | 176 | length = 0 177 | height = 0 178 | 179 | while length < 5: 180 | 181 | mc.setBlock(playerPos.x + 2, playerPos.y + height, playerPos.z - 2 + length, 0) 182 | 183 | while height < 3: 184 | mc.setBlock(playerPos.x + 2, playerPos.y + height, playerPos.z - 2 + length, 0) 185 | time.sleep(0.2) 186 | height += 1 187 | 188 | length += 1 189 | height = 0 190 | 191 | # Remove second wall on right towards 192 | 193 | length = 0 194 | height = 0 195 | 196 | while length < 4: 197 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z + 2, 0) 198 | 199 | while height < 3: 200 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z + 2, 0) 201 | time.sleep(0.2) 202 | height += 1 203 | 204 | length += 1 205 | height = 0 206 | 207 | # Remove third wall on left towards 208 | 209 | length = 0 210 | height = 0 211 | 212 | while length < 4: 213 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z - 2, 0) 214 | 215 | while height < 3: 216 | mc.setBlock(playerPos.x + 1 - length, playerPos.y + height, playerPos.z - 2 , 0) 217 | time.sleep(0.2) 218 | height += 1 219 | 220 | length += 1 221 | height = 0 222 | 223 | # Remove last wall behind to right 224 | 225 | length = 0 226 | height = 0 227 | 228 | while length < 3: 229 | mc.setBlock(playerPos.x - 2, playerPos.y + height, playerPos.z - 1 + length, 0) 230 | 231 | while height < 3: 232 | mc.setBlock(playerPos.x - 2, playerPos.y + height, playerPos.z - 1 + length, 0) 233 | time.sleep(0.2) 234 | height += 1 235 | 236 | length += 1 237 | height = 0 -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/symmetry.py: -------------------------------------------------------------------------------- 1 | # 2 | # This script uses RaspberryJamMod's ability to capture all hits, not just sword hits, to provide symmetric 3 | # drawing. Stand at the center of symmetry. By default, you get north-south and east-west mirroring, but you 4 | # can include other transformations on the commandline: 5 | # 6 | # n : northsouth flip 7 | # e : east west flip 8 | # u : up down flip 9 | # nw : nw - se flip 10 | # ne : ne - sw flip 11 | # 12 | # 90 : 90, 180 and 270 degrees in the plane 13 | # 180 : 180 degrees in the plane 14 | # 15 | # You can do translational symmetry with: 16 | # t N x y z : translate N-1 times by vector (x,y,z) 17 | # 18 | # The transformations are combined in a complicated fashion to generate the list of all applied transformations. 19 | # Effectively this works like this: 20 | # 1. The group generated by all the rotations and flips is put into the list. 21 | # 2. For each translational symmetry "t N x y z", the list is updated as follows: For each transformation F on the list 22 | # so far, the N-1 transformations lambda (x1,y1,z1) : F(x1,y1,z1) + (kx,ky,kz) are added to the list, for k from 1 to N-1. 23 | # 3. The identity transformation is removed. 24 | # 25 | # Then whenever you draw or erase a block, all the transforms of that block location are are also drawn or erased. 26 | # 27 | # For instance, specifying n e t 10 0 1 0 will do north-south and east-west mirroring, plus raising up pillars 10 high on 28 | # top of whatever you draw. On the other hand, doing t 10 1 0 0 t 10 0 1 0 t 10 0 0 1 will draw 10x10x10 cubes wherever you 29 | # draw. 30 | # 31 | 32 | 33 | # 34 | # Code by Alexander Pruss under MIT license. 35 | # 36 | 37 | from mcpi.minecraft import Minecraft 38 | import mcpi.block as block 39 | from functools import partial 40 | import sys 41 | import time 42 | 43 | xn = ( (1,0,0), 44 | (0,1,0), 45 | (0,0,-1) ) 46 | xe = ( (-1,0,0), 47 | (0,1,0), 48 | (0,0,1) ) 49 | xu = ( (1,0,0), 50 | (0,-1,0), 51 | (0,0,-1) ) 52 | xnw = ( (0,0,-1), 53 | (0,1,0), 54 | (-1,0,0) ) 55 | xne = ( (0,0,1), 56 | (0,1,0), 57 | (1,0,0 ) ) 58 | x90 = ( (0,0,1), 59 | (0,1,0), 60 | (-1,0,0) ) 61 | xid = ( (1,0,0), 62 | (0,1,0), 63 | (0,0,1) ) 64 | 65 | faces = ( (0,-1,0), (0,1,0), (0,0,-1), (0,0,1), (-1,0,0), (1,0,0), (0,0,0) ) 66 | 67 | def mulMat(a,b): 68 | return tuple(tuple(a[i][0]*b[0][j]+a[i][1]*b[1][j]+a[i][2]*b[2][j] for j in range(3)) for i in range(3)) 69 | 70 | def mulMatVec(a,b): 71 | return tuple(a[i][0]*b[0]+a[i][1]*b[1]+a[i][2]*b[2] for i in range(3)) 72 | 73 | def subVec(a,b): 74 | return tuple(a[i]-b[i] for i in range(3)) 75 | 76 | def addVec(a,b): 77 | return tuple(a[i]+b[i] for i in range(3)) 78 | 79 | x180 = mulMat(x90,x90) 80 | 81 | if __name__ == "__main__": 82 | def copy(v,airOnly=False): 83 | b = mc.getBlockWithNBT(v) 84 | if airOnly and b.id != block.AIR.id: 85 | return 86 | v1 = addVec(v,(0.5,0.5,0.5)) 87 | for t in transforms: 88 | mc.setBlockWithNBT(t(v1),b) 89 | 90 | def err(): 91 | mc.postToChat("Invalid symmetry specification. See symmetry.py comments.") 92 | exit() 93 | 94 | mc = Minecraft() 95 | 96 | playerPos = mc.player.getPos() 97 | 98 | matrices = set() 99 | translations = [] 100 | 101 | if len(sys.argv) <= 1: 102 | matrices.add(xn) 103 | matrices.add(xe) 104 | 105 | i = 1 106 | while i < len(sys.argv): 107 | opt = sys.argv[i] 108 | i += 1 109 | if opt == 't': 110 | if len(sys.argv) <= i + 3: 111 | err() 112 | translations.append((int(sys.argv[i]), float(sys.argv[i+1]), float(sys.argv[i+2]), float(sys.argv[i+3]))) 113 | i += 4 114 | elif opt == 'n': 115 | matrices.add(xn) 116 | elif opt == 'e': 117 | matrices.add(xe) 118 | elif opt == 'u': 119 | matrices.add(xu) 120 | elif opt == 'nw': 121 | matrices.add(xnw) 122 | elif opt == 'ne': 123 | matrices.add(xne) 124 | elif opt == '90': 125 | matrices.add(x90) 126 | elif opt == '180': 127 | matrices.add(x180) 128 | 129 | matrices.add(xid) 130 | old = set() 131 | while len(old) < len(matrices): 132 | old = matrices 133 | matrices = set() 134 | for a in old: 135 | for b in old: 136 | matrices.add(mulMat(a,b)) 137 | matrices.remove(xid) 138 | 139 | transforms = [] 140 | matrixApply = lambda v,mat : addVec(mulMatVec(mat,subVec(v,center)),center) 141 | for m in matrices: 142 | transforms.append(partial(matrixApply, mat=m)) 143 | 144 | for t in translations: 145 | add = [] 146 | for k in range(1,t[0]): 147 | delta = (t[1]*k,t[2]*k,t[3]*k) 148 | f = partial(addVec,b=delta) 149 | add.append(f) 150 | for g in transforms: 151 | add.append(lambda v,f=f,g=g : f(g(v))) 152 | transforms += add 153 | 154 | center = tuple(0.5 * round(2 * x) for x in playerPos) 155 | 156 | # if (len(matrices) > 0): 157 | # mc.conn.send("world.spawnParticle", "footstep", center, 0.0,0.0,0.0, 0, 1) 158 | 159 | mc.conn.send("events.setting","restrict_to_sword",0) 160 | mc.conn.send("events.setting","detect_left_click",1) 161 | 162 | mc.postToChat("Will be drawing {} copies".format(1+len(transforms))) 163 | 164 | mc.events.clearAll() 165 | 166 | while True: 167 | hits = mc.events.pollBlockHits() 168 | time.sleep(0.25) 169 | for h in hits: 170 | v = tuple(x for x in h.pos) 171 | copy(v,airOnly=True) 172 | copy(addVec(v,faces[h.face])) 173 | -------------------------------------------------------------------------------- /raspberryjammod/mcpipy/vehicles/X-Wing_Fighter.py: -------------------------------------------------------------------------------- 1 | baseAngle,highWater,baseVehicle=(-179.70188903808594, -9223372036854775808L, {(1, 1, -5): Block(95, 15), (0, 0, -11): Block(35, 14), (4, -2, -1): Block(35, 14), (3, -2, -1): Block(35, 0), (-1, 0, -4): Block(35, 0), (7, -4, -2): Block(35, 8), (4, -2, 0): Block(35, 14), (3, -1, 1): Block(35, 0), (-1, 0, -9): Block(35, 0), (7, -4, -3): Block(35, 8), (1, 1, -3): Block(35, 0), (4, 2, -1): Block(35, 14), (-2, 3, 0): Block(35, 8), (2, 1, -1): Block(35, 0), (-7, 4, -2): Block(35, 8), (2, 2, -1): Block(35, 0), (-1, 1, 3): Block(35, 0), (-3, -2, -1): Block(35, 0), (-1, 0, -7): Block(35, 14), (-7, -4, 1): Block(35, 8), (-2, 3, 2): Block(35, 0), (2, 2, 2): Block(35, 0), (7, -4, -4): Block(35, 8), (-1, 0, -5): Block(35, 0), (1, 1, -6): Block(95, 15), (-2, 2, 3): Block(35, 0), (-6, -3, -1): Block(35, 0), (-2, 2, 2): Block(35, 0), (5, 3, 1): Block(35, 0), (3, 2, 2): Block(35, 0), (-1, 0, -3): Block(35, 0), (1, 2, 0): Block(35, 8), (0, 1, -8): Block(95, 15), (-2, -1, 1): Block(35, 0), (-7, 4, -3): Block(35, 8), (3, 2, 0): Block(35, 8), (-5, 3, 0): Block(35, 0), (-2, -1, -1): Block(35, 0), (-2, -1, 4): Block(35, 0), (0, -1, -5): Block(35, 0), (-6, 3, 1): Block(35, 0), (2, -1, 5): Block(35, 0), (-3, -1, 0): Block(35, 8), (0, 0, 4): Block(35, 0), (-6, 3, -1): Block(35, 0), (-4, -2, 1): Block(35, 14), (1, 0, -7): Block(35, 14), (2, -1, 3): Block(35, 0), (-2, 0, 0): Block(35, 8), (-2, 2, 1): Block(35, 0), (-3, -1, 1): Block(35, 0), (-3, -1, -1): Block(35, 0), (1, 0, -8): Block(35, 14), (0, 1, -7): Block(95, 15), (2, -1, 1): Block(35, 0), (3, -2, 0): Block(35, 0), (-2, 1, 1): Block(35, 0), (-1, -1, 2): Block(35, 0), (-5, -3, 0): Block(35, 0), (2, -1, 2): Block(35, 0), (1, 0, -2): Block(35, 14), (-7, 4, -1): Block(35, 8), (6, 3, 1): Block(35, 0), (-1, -1, -1): Block(35, 0), (-7, -4, 0): Block(35, 8), (-1, 1, -6): Block(95, 15), (1, 0, -4): Block(35, 0), (6, 3, 0): Block(35, 0), (-1, -1, -2): Block(35, 0), (5, -3, 0): Block(35, 0), (1, -1, -3): Block(35, 0), (2, -2, 0): Block(35, 8), (1, 0, -6): Block(35, 14), (2, 2, 6): Block(35, 8), (6, 3, -1): Block(35, 0), (2, -1, 0): Block(35, 8), (5, -3, -1): Block(35, 0), (0, 2, 4): Block(35, 8), (-2, 1, -1): Block(35, 0), (2, 2, 4): Block(35, 0), (-2, 2, -1): Block(35, 0), (-5, 3, 1): Block(35, 0), (0, -1, -3): Block(35, 0), (-1, 1, -4): Block(95, 15), (0, -1, -8): Block(35, 0), (-7, -4, -1): Block(35, 8), (-4, -2, -1): Block(35, 14), (-5, 3, -1): Block(35, 0), (2, 1, 0): Block(35, 8), (0, 2, -5): Block(95, 15), (-2, 0, 2): Block(35, 0), (-6, -3, 0): Block(35, 0), (0, -1, 4): Block(35, 0), (0, 1, -9): Block(95, 15), (-3, 2, 1): Block(35, 0), (7, 4, -4): Block(35, 8), (-1, 2, 2): Block(35, 0), (0, 2, 0): Block(35, 8), (0, 0, -12): Block(35, 0), (-7, 4, 0): Block(35, 8), (5, 3, 0): Block(35, 0), (7, 4, -2): Block(35, 8), (2, 2, 0): Block(35, 8), (-4, 2, 0): Block(35, 14), (0, -1, 0): Block(35, 0), (-1, 0, -2): Block(35, 14), (3, -1, 0): Block(35, 8), (-2, -1, 3): Block(35, 0), (-1, 1, -5): Block(95, 15), (-7, -4, -2): Block(35, 8), (0, -1, 2): Block(35, 0), (-2, -2, 1): Block(35, 0), (1, -1, 2): Block(35, 0), (2, 1, 1): Block(35, 0), (0, 2, -1): Block(35, 0), (1, -1, 0): Block(35, 8), (4, 2, 1): Block(35, 14), (1, 1, 2): Block(89, 0), (-7, -4, -4): Block(35, 8), (-1, 0, 2): Block(35, 0), (3, -1, -1): Block(35, 0), (0, 2, 3): Block(35, 8), (3, -1, 2): Block(35, 0), (-2, 2, 5): Block(35, 0), (4, -2, 1): Block(35, 14), (-1, 1, -2): Block(35, 0), (1, 1, 4): Block(35, 0), (0, 2, -4): Block(95, 15), (-3, -1, 2): Block(35, 0), (2, -2, 1): Block(35, 0), (2, 2, 5): Block(35, 0), (5, -3, 1): Block(35, 0), (1, 0, 3): Block(35, 0), (-1, 0, 4): Block(35, 0), (7, -4, -1): Block(35, 8), (1, 1, -4): Block(95, 15), (-5, -3, -1): Block(35, 0), (-2, 3, 1): Block(35, 0), (0, -1, -2): Block(35, 0), (-1, -1, -3): Block(35, 0), (-5, -3, 1): Block(35, 0), (1, 0, -5): Block(35, 0), (2, 0, 1): Block(35, 0), (0, -1, -4): Block(35, 0), (1, 1, -2): Block(35, 0), (-2, -1, 5): Block(35, 0), (7, 4, 1): Block(35, 8), (7, 4, 0): Block(35, 8), (-1, 0, -6): Block(35, 14), (1, -1, -2): Block(35, 0), (0, -1, 1): Block(35, 0), (-7, 4, -4): Block(35, 8), (-2, 0, -1): Block(35, 0), (2, 0, 0): Block(35, 8), (-6, 3, 0): Block(35, 0), (2, -1, 6): Block(35, 8), (0, -1, -7): Block(35, 0), (3, 2, 1): Block(35, 0), (6, -3, 0): Block(35, 0), (0, -1, -6): Block(35, 0), (7, -4, 0): Block(35, 8), (0, 2, -6): Block(95, 15), (-2, 2, 4): Block(35, 0), (-1, 1, 2): Block(89, 0), (0, 2, -2): Block(35, 0), (-2, -2, 0): Block(35, 8), (-4, -2, 0): Block(35, 14), (2, -2, 2): Block(35, 0), (2, 3, -1): Block(35, 0), (0, 2, 2): Block(35, 8), (2, 3, 0): Block(35, 8), (-4, 2, -1): Block(35, 14), (6, -3, -1): Block(35, 0), (-1, 2, 0): Block(35, 8), (-1, 0, -8): Block(35, 14), (-1, -1, 1): Block(35, 0), (1, -1, 1): Block(35, 0), (1, 0, 2): Block(35, 0), (-1, 1, 4): Block(35, 0), (-3, 2, -1): Block(35, 0), (1, 0, -3): Block(35, 0), (0, -1, -1): Block(35, 8), (0, 1, 4): Block(35, 0), (3, -2, 1): Block(35, 0), (-2, 2, 6): Block(35, 8), (1, -1, -1): Block(35, 0), (0, 2, 1): Block(35, 8), (6, -3, 1): Block(35, 0), (2, 2, 1): Block(35, 0), (-4, 2, 1): Block(35, 14), (2, -2, -1): Block(35, 0), (-2, -1, 0): Block(35, 8), (2, 3, 1): Block(35, 0), (1, 0, 4): Block(35, 0), (2, -1, -1): Block(35, 0), (-1, 1, -3): Block(35, 0), (1, 0, -9): Block(35, 0), (1, 2, 1): Block(35, 0), (5, 3, -1): Block(35, 0), (1, 2, 2): Block(35, 0), (-2, 0, 1): Block(35, 0), (3, 2, -1): Block(35, 0), (-3, 2, 0): Block(35, 8), (-1, 2, -1): Block(35, 0), (7, 4, -1): Block(35, 8), (1, 2, -1): Block(35, 0), (-2, -2, -1): Block(35, 0), (-6, -3, 1): Block(35, 0), (-1, 0, 3): Block(35, 0), (2, 0, 2): Block(35, 0), (-3, 2, 2): Block(35, 0), (7, 4, -3): Block(35, 8), (0, 2, -3): Block(35, 0), (-3, -2, 0): Block(35, 0), (-2, -2, 2): Block(35, 0), (-7, 4, 1): Block(35, 8), (2, 1, 2): Block(35, 0), (0, 0, -10): Block(35, 0), (2, 3, 2): Block(35, 0), (2, -1, 4): Block(35, 0), (0, -1, 3): Block(35, 8), (2, 0, -1): Block(35, 0), (-1, 2, 1): Block(35, 0), (-2, -1, 2): Block(35, 0), (-2, 3, -1): Block(35, 0), (1, 1, 3): Block(35, 0), (7, -4, 1): Block(35, 8), (-2, 1, 0): Block(35, 8), (-2, 1, 2): Block(35, 0), (-1, -1, 0): Block(35, 8), (0, -1, -9): Block(35, 0), (4, 2, 0): Block(35, 14), (2, 2, 3): Block(35, 0), (-7, -4, -3): Block(35, 8), (-3, -2, 1): Block(35, 0), (-2, 2, 0): Block(35, 8), (-2, -1, 6): Block(35, 8)}) 2 | --------------------------------------------------------------------------------