Skip to content
A plugin for Bukkit implementing the Minecraft Pi API
Java
Branch: master
Clone or download
Pull request Compare This branch is 29 commits ahead, 122 commits behind zhuowei:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
jars
src/main/java/net/zhuoweizhang/raspberryjuice
.gitignore
README.md
pom.xml

README.md

RaspberryJuice

A Bukkit plugin which implements the Minecraft Pi Socket API.

Hardcoded Settings:

  • Weather is off
  • Hunger is off
  • Permanent Night Vision
  • Lava damage reduced (but not eliminated)

Python API

These are the functions are exposed via this mod. To use these functions, you'll need the Python API, which is available in TeachCraft-Examples repository.

Click a function name to see an example.

mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

Connect to a minecraft world

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

#Get current player's position
pos = mc.player.getPos()
print pos.x, pos.y, pos.z
mc.setBlock(x, y, z, block_id, [block_data])

Set the block at coordinates X/Y/Z to block_id

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

#Get current player's position
pos = mc.player.getPos()

#This is the minecraft block ID of the glass block.
#To see what other block IDs are available, go here in your browser: http://minecraft-ids.grahamedgecombe.com/
glass_block_id = 20

#Set the block underneath the player to be glass
mc.setBlock(pos.x, pos.y-1, pos.z, glass_block_id)

#Set the block to the side of player to be wood of a specific subtype
wood_block_id = 5
wood_data = 1 #subtype
mc.setBlock(pos.x+1, pos.y, pos.z, wood_block_id, wood_data)
mc.getBlock(x, y, z)

Get the block at coordinates X/Y/Z, returning its block ID

from mcpi import minecraft

# Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

# Get current player's position
pos = mc.player.getPos()

# Get the block underneath the player
block_id_under_player = mc.getBlock(pos.x, pos.y-1, pos.z)
grass_block_id = 2

if block_id_under_player == grass_block_id:
    print "Player is standing on grass"
mc.getBlockWithData(x, y, z)

Get the block at coordinates X/Y/Z, returning its block ID & data field (e.g. for wool color)

from mcpi import minecraft

# Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

# Get current player's position
pos = mc.player.getPos()

# Get the block underneath the player
block_under_player = mc.getBlockWithData(pos.x, pos.y-1, pos.z)
print "block id", block_under_player.id
print "block data", block_under_player.data
mc.setBlocks(x1, y1, z1, x2, y2, z2, block_id, [block_data])

Set a cuboid of blocks between two opposite corners (x1/y1/z1 and x2/y2/z2)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

#Get current player's position
pos = mc.player.getPos()

#This is the minecraft block ID of the glass block.
#To see what other block IDs are available, go here in your browser: http://minecraft-ids.grahamedgecombe.com/
glass_block_id = 20

#Build a glass cube next to the player
mc.setBlocks(pos.x+3, pos.y, pos.z, pos.x+8, pos.y+5, pos.z+5, glass_block_id)

#Build a wood cube of a specific subtype next to the player, then make it hollow by building a smaller cube of air inside
wood_block_id = 5
wood_data = 1 #subtype
mc.setBlocks(pos.x-3, pos.y, pos.z, pos.x-8, pos.y+5, pos.z-5, wood_block_id, wood_data)

air_block_id = 0
mc.setBlocks(pos.x-2, pos.y+1, pos.z-1, pos.x-7, pos.y+4, pos.z-4, air_block_id)
mc.getBlocks(x1, y1, z1, x2, y2, z2)

Get a cuboid of blocks between two opposite corners (x1/y1/z1 and x2/y2/z2)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

#Get current player's position
pos = mc.player.getPos()

blocks = mc.getBlocks(pos.x+3, pos.y, pos.z, pos.x+8, pos.y+5, pos.z+5)
for block_id in blocks:
    print block_id

mc.player.getPos()

Get current player's position exactly (decimals)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's position
pos = mc.player.getPos()

# Returns Vec3(18.3814903971,6.0,25.6063951368)
# Can be accessed as pos.x, pos.y, and pos.z
print pos.x, pos.y, pos.z
mc.player.setPos()

Set current player's position exactly (supports decimals)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's position
pos = mc.player.getPos()

#Set current player's position 100 blocks in the air
mc.player.setPos(pos.x, pos.y+100, pos.z)
mc.player.getTilePos()

Get current player's position rounded to the block (integer)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's position
pos = mc.player.getTilePos()

# Returns Vec3(52, 4, -10)
# Can be accessed as pos.x, pos.y, and pos.z
print pos.x, pos.y, pos.z
mc.player.setTilePos()

Set current player's position rounded to the block (supports integers)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's position
pos = mc.player.getTilePos()

#Set current player's position 100 blocks in the air
mc.player.setTilePos(pos.x, pos.y+100, pos.z)
mc.getHeight(x, z)

Given an x/z coordinate, find the highest non-air block (y coordinate)

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's position
pos = mc.player.getTilePos()

highest_block_y_coordinate = mc.getHeight(pos.x, pos.y)
print highest_block_y_coordinate
mc.postToChat("Hello World!")

Post any text string to chat in-game

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

mc.postToChat("Hello World!")
mc.player.pollBlockHits()

Perform an action wherever the player right clicks with a sword

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

while True:

    for blockhit in mc.player.pollBlockHits():

        #Get coordinates for block that player right clicked with sword
        pos = blockhit.pos

        #Clear out a cube of blocks at that location
        air_block_id = 0
        mc.setBlocks(pos.x+2, pos.y+2, pos.z+2, pos.x-2, pos.y-2, pos.z-2, air_block_id)
mc.player.pollProjectileHits()

Perform an action wherever the player shoots with an arrow

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

while True:

    for blockhit in mc.player.pollProjectileHits():

        #Get coordinates for block that player shot with an arrow
        pos = blockhit.pos

        #Teleport player to where arrow landed
        mc.player.setPos(pos.x, pos.y, pos.z)
mc.player.pollChatPosts()

Perform an action whenever the player types something in chat

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

while True:

    for chatpost in mc.player.pollChatPosts():

        #If I type explode into chat...
        if chatpost.message.lower() == "explode":

            #Get my position
            pos = mc.player.getPos()

            #Put TNT at my position
            mc.setBlock(pos.x, pos.y, pos.z, 46)

            #And put a redstone block under the TNT to activate it
            mc.setBlock(pos.x, pos.y-1, pos.z, 152)
mc.events.clearAll()

Clear all events that have happened since the events where last retrieved

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

mc.events.clearAll()
mc.player.getDirection()

Get unit vector of x,y,z for the player's direction

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's direction
direction = mc.player.getDirection()

# Returns Vec3(-0.935271308082,-0.271442436324,-0.227126801679)
# Can be accessed as direction.x, direction.y, and direction.z
print direction.x, direction.y, direction.z
mc.player.getPitch()

Get the pitch angle (-90 to 90) for the player

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's pitch
pitch = mc.player.getPitch()

# Returns 15.750118 (or something like that)
print pitch
mc.player.getRotation()

Get the rotational angle (0 to 360) for the player

from mcpi import minecraft

#Connect to minecraft server 127.0.0.1 as player 'steve'
mc = minecraft.Minecraft.create(address="127.0.0.1", name="bob")

#Get current player's rotation
rotation = mc.player.getRotation()

# Returns -256.3502 (or something like that)
print rotation

More details available here

Compile

  • Download Maven
  • After extracting it, cd to the directory this repository is downloaded to, and run the binary from the package you downloaded above like so:
cd ~/Desktop/RaspberryJuice && /Users/emeth/Downloads/apache-maven-3.5.0/bin/mvn  package
You can’t perform that action at this time.