Skip to content

Commit

Permalink
win32move
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jul 4, 2016
1 parent 6eaccd9 commit dd21e7d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
60 changes: 38 additions & 22 deletions python2-scripts/mcpipy/win32move.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#
# (c) 2016 A. R. Pruss. MIT License.
#
from mc import *
from time import sleep
from sys import argv
import win32con,win32api

mc = Minecraft()

player = True

if len(argv)>=2 and argv[1] != "me":
playerPos = mc.player.getPos()
playerYaw = mc.player.getRotation()
entity = mc.spawnEntity(argv[1], playerPos.x - sin(radians(playerYaw)), playerPos.z,
playerPos.z + cos(radians(playerYaw)), "{NoAI:1}")
player = False
else:
entity = mc.getPlayerId()

lastPlatform = None
lastPlatformBlock = None

UNSOLID = set([WATER_FLOWING.id,WATER_STATIONARY.id,AIR.id,LAVA_FLOWING.id,LAVA_STATIONARY.id])

while True:
pos = mc.player.getTilePos()
pos = mc.entity.getPos(entity)
yaw = mc.entity.getRotation(entity)
move = False
if win32api.GetAsyncKeyState(win32con.VK_NEXT):
pos.y -= 1
Expand All @@ -22,30 +32,36 @@
pos.y += 1
move = True
if win32api.GetAsyncKeyState(win32con.VK_LEFT):
pos.x += 1
move = True
yaw -= 15
mc.entity.setRotation(entity,yaw)
if win32api.GetAsyncKeyState(win32con.VK_RIGHT):
pos.x -= 1
move = True
yaw += 15
mc.entity.setRotation(entity,yaw)
if win32api.GetAsyncKeyState(win32con.VK_UP):
pos.z += 1
pos.x += .5 * -sin(radians(yaw))
pos.z += .5 * cos(radians(yaw))
move = True
if win32api.GetAsyncKeyState(win32con.VK_DOWN):
pos.z -= 1
pos.x -= .5 * -sin(radians(yaw))
pos.z -= .5 * cos(radians(yaw))
move = True
if move:
block = mc.getBlock(pos.x,pos.y-1,pos.z)
if block in UNSOLID:
drew = Vec3(pos.x,pos.y-1,pos.z)
mc.setBlock(drew,GLASS)
if player:
under = (int(floor(pos.x)),int(floor(pos.y))-1,int(floor(pos.z)))
block = mc.getBlock(under)
if block in UNSOLID:
drew = under
mc.setBlock(drew,GLASS)
else:
drew = None
mc.entity.setPos(entity,pos)
if lastPlatform != under:
mc.setBlock(lastPlatform,AIR)
lastPlatform = None
if drew:
lastPlatform = drew
lastPlatformBlock = block
else:
drew = None
mc.player.setTilePos(pos)
if lastPlatform and (not drew or lastPlatform != drew):
mc.setBlock(lastPlatform,AIR)
lastPlatform = None
if drew:
lastPlatform = drew
lastPlatformBlock = block
mc.entity.setPos(entity,pos)
sleep(0.2)

Binary file modified python3-scripts.zip
Binary file not shown.
57 changes: 38 additions & 19 deletions python3-scripts/mcpipy/win32move.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
from mc import *
from time import sleep
from sys import argv
import win32con,win32api

mc = Minecraft()

player = True

if len(argv)>=2 and argv[1] != "me":
playerPos = mc.player.getPos()
playerYaw = mc.player.getRotation()
entity = mc.spawnEntity(argv[1], playerPos.x - sin(radians(playerYaw)), playerPos.z,
playerPos.z + cos(radians(playerYaw)), "{NoAI:1}")
player = False
else:
entity = mc.getPlayerId()

lastPlatform = None
lastPlatformBlock = None

UNSOLID = set([WATER_FLOWING.id,WATER_STATIONARY.id,AIR.id,LAVA_FLOWING.id,LAVA_STATIONARY.id])

while True:
pos = mc.player.getTilePos()
pos = mc.entity.getPos(entity)
yaw = mc.entity.getRotation(entity)
move = False
if win32api.GetAsyncKeyState(win32con.VK_NEXT):
pos.y -= 1
Expand All @@ -19,30 +32,36 @@
pos.y += 1
move = True
if win32api.GetAsyncKeyState(win32con.VK_LEFT):
pos.x += 1
move = True
yaw -= 15
mc.entity.setRotation(entity,yaw)
if win32api.GetAsyncKeyState(win32con.VK_RIGHT):
pos.x -= 1
move = True
yaw += 15
mc.entity.setRotation(entity,yaw)
if win32api.GetAsyncKeyState(win32con.VK_UP):
pos.z += 1
pos.x += .5 * -sin(radians(yaw))
pos.z += .5 * cos(radians(yaw))
move = True
if win32api.GetAsyncKeyState(win32con.VK_DOWN):
pos.z -= 1
pos.x -= .5 * -sin(radians(yaw))
pos.z -= .5 * cos(radians(yaw))
move = True
if move:
block = mc.getBlock(pos.x,pos.y-1,pos.z)
if block in UNSOLID:
drew = Vec3(pos.x,pos.y-1,pos.z)
mc.setBlock(drew,GLASS)
if player:
under = (int(floor(pos.x)),int(floor(pos.y))-1,int(floor(pos.z)))
block = mc.getBlock(under)
if block in UNSOLID:
drew = under
mc.setBlock(drew,GLASS)
else:
drew = None
mc.entity.setPos(entity,pos)
if lastPlatform != under:
mc.setBlock(lastPlatform,AIR)
lastPlatform = None
if drew:
lastPlatform = drew
lastPlatformBlock = block
else:
drew = None
mc.player.setTilePos(pos)
if lastPlatform and (not drew or lastPlatform != drew):
mc.setBlock(lastPlatform,AIR)
lastPlatform = None
if drew:
lastPlatform = drew
lastPlatformBlock = block
mc.entity.setPos(entity,pos)
sleep(0.2)

0 comments on commit dd21e7d

Please sign in to comment.