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 )
About these ads

5 thoughts on “3 new scripts from goldfish – HelloWorld, clearZone and drawBuilding!

  1. To get the ladders to work you need to add data to the setblocks.
    mc.setBlocks(x+2,y,z+1,x+2,y+ht-1,z+1,65,[3])
    I have not figured out yet how to determine which number to use. I hardcoded 3 in my example to make sure it worked but not sure in code how to figure out which “side” to use.

  2. Great program. Awesome when you see the building appearing.
    Can I point out two bugs? In the front windows you have used width instead of depth for the z-axis, while for the back windows you have used depth instead of width for the x-axis. If you start location is 0,0,0 you don’t see the bug, but you do when you use eg 50, 0, 0 and of course a different width & depth. Front windows then get too long or too short, back windows appear in the middle of your building or outside.
    Hope this helps. But perhaps you put this in to get us into debugging Python programs, which is a respectable goal!! :-)

    • We do not actually make the programs (TnT snake and minecraft path we made) but we do reblog them so people can find them but you can tell “goldfish” about the bugs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s