Skip to content

Commit

Permalink
Merge pull request #215 from Gjum/new-event-world_chunk_update
Browse files Browse the repository at this point in the history
New event: world_chunk_update
  • Loading branch information
gamingrobot committed Feb 22, 2016
2 parents dc93384 + 92b4149 commit 2787cca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 15 additions & 4 deletions spockbot/plugins/helpers/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def handle_new_dimension(self, name, packet):
def handle_chunk_data(self, name, packet):
"""Chunk Data - Update World state"""
self.world.unpack_column(packet.data)
location = packet.data['chunk_x'], packet.data['chunk_z']
self.event.emit('world_chunk_update', {'location': location})

def handle_multi_block_change(self, name, packet):
"""Multi Block Change - Update multiple blocks"""
Expand All @@ -71,26 +73,35 @@ def handle_multi_block_change(self, name, packet):
x = block['x'] + chunk_x
z = block['z'] + chunk_z
y = block['y']
self.world.set_block(x, y, z, data=block['block_data'])
old_data = self.world.set_block(x, y, z, data=block['block_data'])
self.event.emit('world_block_update', {
'location': {
'x': x,
'y': y,
'z': z,
},
'block_data': block['block_data'],
'old_data': old_data,
})

def handle_block_change(self, name, packet):
"""Block Change - Update a single block"""
p = packet.data['location']
pos = packet.data['location']
block_data = packet.data['block_data']
self.world.set_block(p['x'], p['y'], p['z'], data=block_data)
self.event.emit('world_block_update', packet.data)
old_data = self.world.set_block(pos['x'], pos['y'], pos['z'],
data=block_data)
self.event.emit('world_block_update', {
'location': pos,
'block_data': block_data,
'old_data': old_data,
})

def handle_map_chunk_bulk(self, name, packet):
"""Map Chunk Bulk - Update World state"""
self.world.unpack_bulk(packet.data)
for meta in packet.data['metadata']:
location = meta['chunk_x'], meta['chunk_z']
self.event.emit('world_chunk_update', {'location': location})

def handle_update_sign(self, event, packet):
location = Vector3(packet.data['location'])
Expand Down
3 changes: 3 additions & 0 deletions spockbot/plugins/tools/smpmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ def set_block(self, pos_or_x, y=None, z=None,

if data is None:
data = (block_id << 4) | (meta & 0x0F)

old_data = chunk.block_data.get(rx, ry, rz)
chunk.block_data.set(rx, ry, rz, data)
return old_data >> 4, old_data & 0x0F

def get_block_entity_data(self, pos_or_x, y=None, z=None):
"""
Expand Down

0 comments on commit 2787cca

Please sign in to comment.