3 new scripts from goldfish – HelloWorld, clearZone and drawBuilding!

Ryan (goldfish) has submitted 3 new programs — and he has my many thanks for doing so by pushing his changed to the github repo and making them compatible with the other scripts!!

Here’s what he’s contributed:

gf_helloworld.py

This is a simple program that connects to the minecraft server and does a quick chat — this is a great template for starting new programs…

#! /usr/bin/python
import mcpi.minecraft as minecraft
import server

""" hello world test app

    @author: goldfish"""

mc = minecraft.Minecraft.create( server.address )
mc.postToChat("Hello, Minecraft!")

gf_clearZone.py

This one creates a 20×20 block and adds a stone floor. ¬†Even better you can import it and call clearZone(x1,y1,x2,y2) to create a clear zone of the size you specify.

Screen Shot 2013-03-01 at 3.07.42 PM

#! /usr/bin/python
import mcpi.minecraft as minecraft
import mcpi.block as block
import server

""" clearZone clears an area and sets a stone floor
    takes two x,z pairs clears everything above 0y and then sets
    a stone floor at -1y
    @author: goldfish"""

def clearZone( alocx, alocz, blocx, blocz ):
    mc.setBlocks( alocx, 0, alocz, blocx, 64, blocz, block.AIR )
    mc.setBlocks( alocx, -1, alocz, blocx, -1, blocz, block.STONE )

if __name__ == "__main__":
    mc = minecraft.Minecraft.create( server.address )
    clearZone( -20, -20, 20, 20 )

gf_drawbuilding.py

This one creates a building with floors and windows in it — or you can call it again with your own parameters. ¬†Call the following function..

drawBuilding( locx, locy, locz, floors, width, depth, floorheight, wallmaterial, floormaterial)

Screen Shot 2013-03-01 at 3.08.56 PM
Screen Shot 2013-03-01 at 3.09.20 PM
Screen Shot 2013-03-01 at 3.09.39 PM

#! /usr/bin/python
import mcpi.minecraft as minecraft
import mcpi.block as block
import server
import random

""" draw a building

    @author: goldfish"""

def drawBuilding( locx, locy, locz, floors, width, depth, floorheight, wallmaterial, floormaterial ):
    topx = locx+width
    topy = locy+((floorheight+1)*floors)
    topz = locz+depth
    #draw building shell
    mc.setBlocks( locx, locy, locz, topx, topy, topz, wallmaterial )
    mc.setBlocks( locx+1, locy+1, locz+1, topx-1, topy-1, topz-1, block.AIR )
    #draw floors
    if( floors > 1 ):
        for i in range( floors -1 ):
            floorYloc = locy+( (floorheight+1)*(i+1) )
            mc.setBlocks( locx+1, floorYloc, locz+1, topx-1, floorYloc, topz-1, floormaterial )
    #draw door
    doorloc = random.randint( 1, width-2 )
    mc.setBlock( locx, locy+1, locz+doorloc, block.AIR )
    mc.setBlock( locx, locy+2, locz+doorloc, block.AIR )
    #draw front windows
    if( floors > 1 ):
        for i in range( floors-1 ):
            windowYloc = locy+2+( (floorheight+1)*(i+1) )
            for j in range( floorheight-1 ):
                mc.setBlocks( locx, windowYloc+j , locz+1, locx, windowYloc+j, locz+(width-1), block.GLASS_PANE )
    #draw back windows
    if( floors > 1 ):
        for i in range( floors-1 ):
            windowYloc = locy+2+( (floorheight+1)*(i+1) )
            for j in range( floorheight-1 ):
                mc.setBlocks( locx+depth, windowYloc+j , locz+1, locx+depth, windowYloc+j, locz+(width-1), block.GLASS_PANE )
    #connect levels with ladder
    #mc.setBlocks( topx-1, locy+1, topz-1, topx-1, topy-1, topz-1, block.LADDER )

if __name__ == "__main__":
    mc = minecraft.Minecraft.create( server.address )
    drawBuilding( 0, 0, 0, 5, 5, 5, 3, block.STONE, block.WOOD_PLANKS )
Advertisements

RaspberryJuice v1.2 update available, thanks Zhuowei!

Zhuowei Zhang has updated RaspberryJuice to v1.2! v1.2 includes the following changes:

  1. added world.getBlockWithData to be compatible with Minecraft Pi 1.1.
  2. changed block hit events to listen for right-click with sword
  3. added ban-ip feature: if an IP is banned in the server, connections to the Pi API will be automatically kicked

I’m most excited about the addition of getBlockWithData. With this change, the minescan.py program works just as well against the desktop as the raspberry pi.

Download the v1.2 change here.

Thanks Zhuowei for making this change!

If you’re not familiar with RaspberryJuice, check out my previous post on it here