Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New event: world_chunk_update #215

Merged
merged 4 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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