Skip to content

Commit

Permalink
improve Juice compatibility in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jun 28, 2015
1 parent 7e26ee8 commit 2204706
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 203 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions python2-scripts/mcpipy/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

mc = Minecraft()

playerId = mc.getPlayerId()
try:
playerId = int(os.environ['MINECRAFT_PLAYER_ID'])
getTilePos = lambda: mc.entity.getTilePos(playerId)
except:
pass
getTilePos = mc.player.getTilePos

bridge = []

while True:
pos = mc.entity.getTilePos(playerId)
pos = getTilePos()
pos.y = pos.y - 1
belowBlock = mc.getBlock(pos)
if belowBlock == AIR.id or belowBlock == WATER_FLOWING.id or belowBlock == WATER_STATIONARY.id:
Expand Down
3 changes: 3 additions & 0 deletions python2-scripts/mcpipy/console.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#
# Code under the MIT license by Alexander Pruss
#
# This script only works on Raspberry Jam
#

import mcpi.minecraft as minecraft
import time
Expand All @@ -9,6 +11,7 @@
import code
import sys


def quit():
sys.exit()

Expand Down
76 changes: 0 additions & 76 deletions python2-scripts/mcpipy/forcefield.py

This file was deleted.

13 changes: 9 additions & 4 deletions python2-scripts/mcpipy/grenade.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ def getXYZ(path, t1):

try:
player = int(os.environ['MINECRAFT_PLAYER_ID'])
getPos = lambda: mc.entity.getPos(player)
getRotation = lambda: mc.entity.getRotation(player)
getPitch = lambda: mc.entity.getPitch(player)
except:
player = mc.getPlayerId()
getPos = mc.player.getPos
getRotation = mc.player.getRotation
getPitch = mc.player.getPitch

center = mc.entity.getPos(player)
azi = mc.entity.getRotation(player) * pi/180.
alt = -mc.entity.getPitch(player) * pi/180.
center = getPos()
azi = getRotation() * pi/180.
alt = -getPitch() * pi/180.

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 }

Expand Down
9 changes: 0 additions & 9 deletions python2-scripts/mcpipy/header.py

This file was deleted.

25 changes: 18 additions & 7 deletions python2-scripts/mcpipy/mcturtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,28 @@ def __init__(self,mc=None):
self.mc = mc
else:
self.mc = minecraft.Minecraft()
self.block = BEDROCK
self.block = GOLD_BLOCK
self.width = 1
self.pen = True
self.directionIn()
self.positionIn()
self.delayTime = 0.05
self.nib = [(0,0,0)]
self.turtleType = PLAYER
self.playerId = self.mc.getPlayerId()
self.turtleId = self.playerId
self.turtleId = None
self.fan = None
self.stack = []
self.setEntityCommands()

def setEntityCommands(self):
if self.turtleId == None:
self.setPos = self.mc.player.setPos
self.setPitch = self.mc.player.setPitch
self.setRotation = self.mc.player.setRotation
else:
self.setPos = lambda *pos: self.mc.entity.setPos(self.turtleId,*pos)
self.setPitch = lambda angle: self.mc.entity.setPitch(self.turtleId,angle)
self.setRotation = lambda angle: self.mc.entity.setRotation(self.turtleId,angle)

def save(self):
dict = {}
Expand Down Expand Up @@ -67,11 +77,12 @@ def turtle(self,turtleType):
self.mc.removeEntity(self.turtleId)
self.turtleType = turtleType
if turtleType == PLAYER:
self.turtleId = self.playerId
self.turtleId = None
elif turtleType:
self.turtleId = self.mc.spawnEntity(turtleType,
self.position.x,self.position.y,self.position.z,
"{NoAI:1}")
self.setEntityCommands()
self.positionOut()
self.directionOut()

Expand Down Expand Up @@ -157,7 +168,7 @@ def positionIn(self):

def positionOut(self):
if self.turtleType:
self.mc.entity.setPos(self.turtleId,self.position)
self.setPos(self.position)

def delay(self):
if self.delayTime > 0:
Expand Down Expand Up @@ -276,10 +287,10 @@ def directionOut(self):
heading = self.getHeading()
xz = sqrt(heading[0]*heading[0] + heading[2]*heading[2])
pitch = atan2(-heading[1], xz) * Turtle.TO_DEGREES
self.mc.entity.setPitch(self.turtleId,pitch)
self.setPitch(pitch)
if xz >= 1e-9:
rotation = atan2(-heading[0], heading[2]) * Turtle.TO_DEGREES
self.mc.entity.setRotation(self.turtleId,rotation)
self.setRotation(rotation)

def pendelay(self, t):
"""Set pen delay in seconds (t: float)"""
Expand Down
4 changes: 4 additions & 0 deletions python2-scripts/mcpipy/turtleconsole.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#
# Code under the MIT license by Alexander Pruss
#
#
# Requires Raspberry Jam
#


import mcpi.minecraft as minecraft
import time
Expand Down
1 change: 0 additions & 1 deletion python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def moveTo(self,x,y,z,angleDegrees=0):
playerGetTilePos = lambda: minecraft.entity.getTilePos(player)
playerGetRotation = lambda: minecraft.entity.getRotation(player)
except:
player = minecraft.getPlayerId()
playerGetTilePos = minecraft.player.getTilePos
playerGetRotation = minecraft.player.getRotation

Expand Down
Binary file modified python3-scripts.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions python3-scripts/mcpipy/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

mc = Minecraft()

playerId = mc.getPlayerId()
try:
playerId = int(os.environ['MINECRAFT_PLAYER_ID'])
getTilePos = lambda: mc.entity.getTilePos(playerId)
except:
pass
getTilePos = mc.player.getTilePos

bridge = []

while True:
pos = mc.entity.getTilePos(playerId)
pos = getTilePos()
pos.y = pos.y - 1
belowBlock = mc.getBlock(pos)
if belowBlock == AIR.id or belowBlock == WATER_FLOWING.id or belowBlock == WATER_STATIONARY.id:
Expand Down
3 changes: 3 additions & 0 deletions python3-scripts/mcpipy/console.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#
# Code under the MIT license by Alexander Pruss
#
# This script only works on Raspberry Jam
#

import mcpi.minecraft as minecraft
import time
Expand All @@ -9,6 +11,7 @@
import code
import sys


def quit():
sys.exit()

Expand Down
76 changes: 0 additions & 76 deletions python3-scripts/mcpipy/forcefield.py

This file was deleted.

13 changes: 9 additions & 4 deletions python3-scripts/mcpipy/grenade.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ def getXYZ(path, t1):

try:
player = int(os.environ['MINECRAFT_PLAYER_ID'])
getPos = lambda: mc.entity.getPos(player)
getRotation = lambda: mc.entity.getRotation(player)
getPitch = lambda: mc.entity.getPitch(player)
except:
player = mc.getPlayerId()
getPos = mc.player.getPos
getRotation = mc.player.getRotation
getPitch = mc.player.getPitch

center = mc.entity.getPos(player)
azi = mc.entity.getRotation(player) * pi/180.
alt = -mc.entity.getPitch(player) * pi/180.
center = getPos()
azi = getRotation() * pi/180.
alt = -getPitch() * pi/180.

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 }

Expand Down
9 changes: 0 additions & 9 deletions python3-scripts/mcpipy/header.py

This file was deleted.

Loading

0 comments on commit 2204706

Please sign in to comment.