Skip to content

Commit

Permalink
compatibility with command block launch; all multiple simultaneous sc…
Browse files Browse the repository at this point in the history
…ripts
  • Loading branch information
arpruss committed Jun 21, 2015
1 parent 1fd0d1e commit 5df5e9b
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 65 deletions.
2 changes: 1 addition & 1 deletion RaspberryJamMod.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "RaspberryJamMod"
#define MyAppVersion "0.30"
#define MyAppVersion "0.31"
#define MyAppPublisher "Omega Centauri Software"
#define MyAppURL "http://github.com/arpruss/raspberryjammod"

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "0.30"
version = "0.31"
group= "mobi.omegacentauri.raspberryjammod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "RaspberryJamMod"

Expand Down
Binary file modified python2-scripts.zip
Binary file not shown.
10 changes: 9 additions & 1 deletion python2-scripts/mcpipy/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@

mc = mc.Minecraft()
mc.postToChat("Python interpreter "+sys.executable+" "+sys.version)
mc.postToChat("Invoking user "+os.environ['MINECRAFT_PLAYER_NAME']+" "+os.environ['MINECRAFT_PLAYER_ID'])
try:
userName = os.environ['MINECRAFT_PLAYER_NAME']
except:
userName = "unspecified"
try:
userId = os.environ['MINECRAFT_PLAYER_ID']
except:
userId = "unspecified"
mc.postToChat("Invoked by user "+userName+" "+userId)
2 changes: 2 additions & 0 deletions python2-scripts/mcpipy/mcpi/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __repr__(self):
STAIRS_COBBLESTONE = Block(67)
DOOR_IRON = Block(71)
REDSTONE_ORE = Block(73)
STONE_BUTTON = Block(77)
SNOW = Block(78)
ICE = Block(79)
SNOW_BLOCK = Block(80)
Expand All @@ -113,6 +114,7 @@ def __repr__(self):
GLASS_PANE = Block(102)
MELON = Block(103)
FENCE_GATE = Block(107)
WOOD_BUTTON = Block(143)
REDSTONE_BLOCK = Block(152)
QUARTZ_BLOCK = Block(155)

Expand Down
43 changes: 32 additions & 11 deletions python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
167,CARPET.id,SUNFLOWER.id,176,177,178,183,184,185,186,187,188,189,190,191,192,
193,194,195,196,197))

def keyFunction(dict,pos):
return (dict[pos].id in NEED_SUPPORT,pos)
def keyFunction(dict,erase,pos):
return (dict[pos].id in NEED_SUPPORT,pos not in erase or erase[pos].id not in NEED_SUPPORT,pos[1],pos[0],pos[2])

def box(x0,y0,z0,x1,y1,z1):
for x in range(x0,x1+1):
Expand All @@ -68,6 +68,15 @@ def getSeed(x0,y0,z0):
return (x0+x,y0+y,z0+z)
return None

def safeSetBlockWithData(pos,block):
"""
Draw block, making sure buttons are not depressed. This is to fix a glitch where launching
the vehicle script from a commandblock resulted in re-pressing of the button.
"""
if block.id == WOOD_BUTTON.id or block.id == STONE_BUTTON.id:
block = Block(block.id, block.data & ~0x08)
setBlockWithData(pos,block)

def scan(x0,y0,z0):
global highWater

Expand All @@ -77,8 +86,8 @@ def scan(x0,y0,z0):

block = getBlockWithData(seed)
positions = {seed:block}
if flash:
mc.setBlock(seed,WOOL_RED)
if flash and block.id not in NEED_SUPPORT:
mc.setBlock(seed,GOLD_BLOCK)
newlyAdded = set(positions.keys())

while len(newlyAdded)>0:
Expand All @@ -98,15 +107,16 @@ def scan(x0,y0,z0):
else:
positions[pos] = block
adding.add(pos)
mc.setBlock(pos,WOOL_RED)
if block.id not in NEED_SUPPORT:
mc.setBlock(pos,GOLD_BLOCK)
newlyAdded = adding

offsets = {}

for pos in sorted(positions, key=lambda x : keyFunction(positions,x)):
empty = {}
for pos in sorted(positions, key=lambda x : keyFunction(positions,empty,x)):
offsets[(pos[0]-x0,pos[1]-y0,pos[2]-z0)] = positions[pos]
if flash:
setBlockWithData(pos,positions[pos])
safeSetBlockWithData(pos,positions[pos])

return offsets

Expand Down Expand Up @@ -150,6 +160,12 @@ def rotateBlock(block,amount):
if block.id in STAIRS:
meta = block.data
return Block(block.id, (meta & ~0x03) | stairDirectionsClockwise[(stairToClockwise[meta & 0x03] + amount) % 4])
elif block.id == STONE_BUTTON.id or block.id == WOOD_BUTTON.id:
direction = block.data & 0x07
if direction < 1 or direction > 4:
return block
direction = 1 + stairDirectionsClockwise[(stairToClockwise[direction-1] + amount) % 4]
return Block(block.id, (block.data & ~0x07) | direction)
else:
return block

Expand Down Expand Up @@ -215,25 +231,30 @@ def translate(base,x,y,z):
if vehiclePos != oldPos or vehicleRotation != oldRotation:
newVehicle = translate(baseVehicle,vehiclePos.x,vehiclePos.y,vehiclePos.z)
todo = {}
erase = {}
for pos in oldVehicle:
if pos not in newVehicle:
if nondestructive and pos in saved:
todo[pos] = saved[pos]
del saved[pos]
else:
todo[pos] = WATER_STATIONARY if highWater is not None and pos[1] <= highWater else AIR
else:
erase[pos] = newVehicle[pos]
for pos in newVehicle:
block = newVehicle[pos]
if pos not in oldVehicle or oldVehicle[pos] != block:
todo[pos] = block
if nondestructive and pos not in oldVehicle:
if pos not in oldVehicle and nondestructive:
curBlock = getBlockWithData(pos)
if curBlock == block:
del todo[pos]
saved[pos] = curBlock
erase[pos] = curBlock

# mc.setting("pause_drawing",1)
for pos in sorted(todo, key=lambda x : keyFunction(todo,x)):
setBlockWithData(pos,todo[pos])
for pos in sorted(todo, key=lambda x : keyFunction(todo,erase,x)):
safeSetBlockWithData(pos,todo[pos])
# mc.setting("pause_drawing",0)
oldVehicle = newVehicle
oldPos = vehiclePos
Expand Down
Binary file modified python3-scripts.zip
Binary file not shown.
10 changes: 9 additions & 1 deletion python3-scripts/mcpipy/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@

mc = mc.Minecraft()
mc.postToChat("Python interpreter "+sys.executable+" "+sys.version)
mc.postToChat("Invoking user "+os.environ['MINECRAFT_PLAYER_NAME']+" "+os.environ['MINECRAFT_PLAYER_ID'])
try:
userName = os.environ['MINECRAFT_PLAYER_NAME']
except:
userName = "unspecified"
try:
userId = os.environ['MINECRAFT_PLAYER_ID']
except:
userId = "unspecified"
mc.postToChat("Invoked by user "+userName+" "+userId)
2 changes: 2 additions & 0 deletions python3-scripts/mcpipy/mcpi/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __repr__(self):
STAIRS_COBBLESTONE = Block(67)
DOOR_IRON = Block(71)
REDSTONE_ORE = Block(73)
STONE_BUTTON = Block(77)
SNOW = Block(78)
ICE = Block(79)
SNOW_BLOCK = Block(80)
Expand All @@ -113,6 +114,7 @@ def __repr__(self):
GLASS_PANE = Block(102)
MELON = Block(103)
FENCE_GATE = Block(107)
WOOD_BUTTON = Block(143)
REDSTONE_BLOCK = Block(152)
QUARTZ_BLOCK = Block(155)

Expand Down
8 changes: 6 additions & 2 deletions python3-scripts/mcpipy/mcpi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import atexit
import os
import platform
from .util import flatten_parameters_to_string

""" @author: Aron Nieminen, Mojang AB"""
Expand All @@ -29,10 +30,13 @@ def __init__(self, address=None, port=None):
self.socket.connect((address, port))
self.readFile = self.socket.makefile("r")
self.lastSent = ""
atexit.register(self.close)
if platform.system() == "Windows":
atexit.register(self.close)

def __del__(self):
self.close()
if platform.system() == "Windows":
self.close()
atexit.unregister(self.close)

def close(self):
try:
Expand Down
3 changes: 2 additions & 1 deletion python3-scripts/mcpipy/mcpi/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def getBlocks(self, *args):
"""Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]"""
return int(self.conn.sendReceive_flat("world.getBlocks", floorFlatten(args)))

# must have no NBT tags in any Block instances
# must have no NBT tags in Block instance
def setBlock(self, *args):
"""Set block (x,y,z,id,[data])"""
self.conn.send_flat("world.setBlock", floorFlatten(args))
Expand All @@ -233,6 +233,7 @@ def setBlockWithNBT(self, *args):
data = list(flatten(args))
self.conn.send_flat("world.setBlock", list(floorFlatten(data[:5]))+data[5:])

# must have no NBT tags in Block instance
def setBlocks(self, *args):
"""Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,[data])"""
self.conn.send_flat("world.setBlocks", floorFlatten(args))
Expand Down
2 changes: 1 addition & 1 deletion python3-scripts/mcpipy/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ def angleToTextDirection(angle):
del sys.argv[0]
text = " ".join(sys.argv)

pos = drawText(mc, fonts.FONTS['tallfont'], pos, forward, minecraft.Vec3(0,1,0), text, foreground, background)
drawText(mc, fonts.FONTS['tallfont'], pos, forward, minecraft.Vec3(0,1,0), text, foreground, background)
52 changes: 43 additions & 9 deletions python3-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
TERRAIN = set((AIR.id,WATER_FLOWING.id,WATER_STATIONARY.id,GRASS.id,DIRT.id,LAVA_FLOWING.id,
LAVA_STATIONARY.id,GRASS.id,DOUBLE_TALLGRASS.id,GRASS_TALL.id,BEDROCK.id,GRAVEL.id))

NEED_SUPPORT = set((SAPLING.id,WATER_FLOWING.id,LAVA_FLOWING.id,GRASS_TALL.id,34,35,FLOWER_YELLOW.id,
FLOWER_CYAN.id,MUSHROOM_BROWN.id,MUSHROOM_RED.id,TORCH.id,63,DOOR_WOOD.id,LADDER.id,
66,68,69,70,DOOR_IRON.id,72,75,76,77,SUGAR_CANE.id,93,94,96,104,105,106,108,111,
113,115,116,117,122,127,131,132,141,142,143,145,147,148,149,150,151,154,157,
167,CARPET.id,SUNFLOWER.id,176,177,178,183,184,185,186,187,188,189,190,191,192,
193,194,195,196,197))

def keyFunction(dict,erase,pos):
return (dict[pos].id in NEED_SUPPORT,pos not in erase or erase[pos].id not in NEED_SUPPORT,pos[1],pos[0],pos[2])

def box(x0,y0,z0,x1,y1,z1):
for x in range(x0,x1+1):
for y in range(y0,y1+1):
Expand All @@ -58,6 +68,15 @@ def getSeed(x0,y0,z0):
return (x0+x,y0+y,z0+z)
return None

def safeSetBlockWithData(pos,block):
"""
Draw block, making sure buttons are not depressed. This is to fix a glitch where launching
the vehicle script from a commandblock resulted in re-pressing of the button.
"""
if block.id == WOOD_BUTTON.id or block.id == STONE_BUTTON.id:
block = Block(block.id, block.data & ~0x08)
setBlockWithData(pos,block)

def scan(x0,y0,z0):
global highWater

Expand All @@ -67,12 +86,13 @@ def scan(x0,y0,z0):

block = getBlockWithData(seed)
positions = {seed:block}
if flash:
mc.setBlock(seed,WOOL_RED)
if flash and block.id not in NEED_SUPPORT:
mc.setBlock(seed,GOLD_BLOCK)
newlyAdded = set(positions.keys())

while len(newlyAdded)>0:
adding = set()
mc.postToChat("Added "+str(len(newlyAdded))+" blocks")
for q in newlyAdded:
for x,y,z in box(-1,-1,-1,1,1,1):
pos = (x+q[0],y+q[1],z+q[2])
Expand All @@ -87,15 +107,16 @@ def scan(x0,y0,z0):
else:
positions[pos] = block
adding.add(pos)
mc.setBlock(pos,WOOL_RED)
if block.id not in NEED_SUPPORT:
mc.setBlock(pos,GOLD_BLOCK)
newlyAdded = adding

offsets = {}

for pos in positions:
empty = {}
for pos in sorted(positions, key=lambda x : keyFunction(positions,empty,x)):
offsets[(pos[0]-x0,pos[1]-y0,pos[2]-z0)] = positions[pos]
if flash:
setBlockWithData(pos,positions[pos])
safeSetBlockWithData(pos,positions[pos])

return offsets

Expand Down Expand Up @@ -139,6 +160,12 @@ def rotateBlock(block,amount):
if block.id in STAIRS:
meta = block.data
return Block(block.id, (meta & ~0x03) | stairDirectionsClockwise[(stairToClockwise[meta & 0x03] + amount) % 4])
elif block.id == STONE_BUTTON.id or block.id == WOOD_BUTTON.id:
direction = block.data & 0x07
if direction < 1 or direction > 4:
return block
direction = 1 + stairDirectionsClockwise[(stairToClockwise[direction-1] + amount) % 4]
return Block(block.id, (block.data & ~0x07) | direction)
else:
return block

Expand Down Expand Up @@ -204,24 +231,31 @@ def translate(base,x,y,z):
if vehiclePos != oldPos or vehicleRotation != oldRotation:
newVehicle = translate(baseVehicle,vehiclePos.x,vehiclePos.y,vehiclePos.z)
todo = {}
erase = {}
for pos in oldVehicle:
if pos not in newVehicle:
if nondestructive and pos in saved:
todo[pos] = saved[pos]
del saved[pos]
else:
todo[pos] = WATER_STATIONARY if highWater is not None and pos[1] <= highWater else AIR
else:
erase[pos] = newVehicle[pos]
for pos in newVehicle:
block = newVehicle[pos]
if pos not in oldVehicle or oldVehicle[pos] != block:
todo[pos] = block
if nondestructive and pos not in oldVehicle:
if pos not in oldVehicle and nondestructive:
curBlock = getBlockWithData(pos)
if curBlock == block:
del todo[pos]
saved[pos] = curBlock
for pos in todo:
setBlockWithData(pos,todo[pos])
erase[pos] = curBlock

# mc.setting("pause_drawing",1)
for pos in sorted(todo, key=lambda x : keyFunction(todo,erase,x)):
safeSetBlockWithData(pos,todo[pos])
# mc.setting("pause_drawing",0)
oldVehicle = newVehicle
oldPos = vehiclePos
oldRotation = vehicleRotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class RaspberryJamMod
{
public static final String MODID = "raspberryjammod";
public static final String VERSION = "0.30";
public static final String VERSION = "0.31";
public static final String NAME = "Raspberry Jam Mod";
private APIServer mcc;
private PythonExternalCommand pythonExternalCommand = null;
Expand Down
Loading

0 comments on commit 5df5e9b

Please sign in to comment.