<commit_before>"""
Provides a very raw (but very fast) world map for use by plugins. Plugins
interested in a more comprehensive world map view can use mcp.mapdata to
interpret blocks and their metadata more comprehensively. Planned to provide
light level interpretation based on sky light and time of day
"""

from spock.mcmap import smpmap
from spock.mcp import mcdata
from spock.plugins.base import PluginBase
from spock.utils import pl_announce


class WorldData(smpmap.Dimension):
    def __init__(self, dimension=mcdata.SMP_OVERWORLD):
        super(WorldData, self).__init__(dimension)
        self.age = 0
        self.time_of_day = 0

    def update_time(self, data):
        self.age = data['world_age']
        self.time_of_day = data['time_of_day']

    def neworld_dimension(self, dimension):
        super(WorldData, self).__init__(dimension)

    def reset(self):
        self.__init__(self.dimension)


@pl_announce('World')
class WorldPlugin(PluginBase):
    requires = 'Event'
    events = {
        'PLAY<Join Game': 'handle_neworld_dimension',
        'PLAY<Respawn': 'handle_neworld_dimension',
        'PLAY<Time Update': 'handle_time_update',
        'PLAY<Chunk Data': 'handle_chunk_data',
        'PLAY<Multi Block Change': 'handle_multi_block_change',
        'PLAY<Block Change': 'handle_block_change',
        'PLAY<Map Chunk Bulk': 'handle_map_chunk_bulk',
        'disconnect': 'handle_disconnect',
    }

    def __init__(self, ploader, settings):
        super(WorldPlugin, self).__init__(ploader, settings)
        self.world = WorldData()
        ploader.provides('World', self.world)

    # Time Update - Update World Time
    def handle_time_update(self, name, packet):
        self.world.update_time(packet.data)
        self.event.emit('world_time_update', packet.data)

    # Join Game/Respawn - New Dimension
    def handle_neworld_dimension(self, name, packet):
        self.world.neworld_dimension(packet.data['dimension'])
        self.event.emit('world_neworld_dimension', packet.data['dimension'])

    # Chunk Data - Update World state
    def handle_chunk_data(self, name, packet):
        self.world.unpack_column(packet.data)

    # Multi Block Change - Update multiple blocks
    def handle_multi_block_change(self, name, packet):
        chunk_x = packet.data['chunk_x'] * 16
        chunk_z = packet.data['chunk_z'] * 16
        for block in packet.data['blocks']:
            x = block['x'] + chunk_x
            z = block['z'] + chunk_z
            y = block['y']
            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'],
            })<commit_msg>Fix find and replace blunder<commit_after>"""
Provides a very raw (but very fast) world map for use by plugins. Plugins
interested in a more comprehensive world map view can use mcp.mapdata to
interpret blocks and their metadata more comprehensively. Planned to provide
light level interpretation based on sky light and time of day
"""

from spock.mcmap import smpmap
from spock.mcp import mcdata
from spock.plugins.base import PluginBase
from spock.utils import pl_announce


class WorldData(smpmap.Dimension):
    def __init__(self, dimension=mcdata.SMP_OVERWORLD):
        super(WorldData, self).__init__(dimension)
        self.age = 0
        self.time_of_day = 0

    def update_time(self, data):
        self.age = data['world_age']
        self.time_of_day = data['time_of_day']

    def neworld_dimension(self, dimension):
        super(WorldData, self).__init__(dimension)

    def reset(self):
        self.__init__(self.dimension)


@pl_announce('World')
class WorldPlugin(PluginBase):
    requires = 'Event'
    events = {
        'PLAY<Join Game': 'handle_neworld_dimension',
        'PLAY<Respawn': 'handle_neworld_dimension',
        'PLAY<Time Update': 'handle_time_update',
        'PLAY<Chunk Data': 'handle_chunk_data',
        'PLAY<Multi Block Change': 'handle_multi_block_change',
        'PLAY<Block Change': 'handle_block_change',
        'PLAY<Map Chunk Bulk': 'handle_map_chunk_bulk',
        'disconnect': 'handle_disconnect',
    }

    def __init__(self, ploader, settings):
        super(WorldPlugin, self).__init__(ploader, settings)
        self.world = WorldData()
        ploader.provides('World', self.world)

    # Time Update - Update World Time
    def handle_time_update(self, name, packet):
        self.world.update_time(packet.data)
        self.event.emit('world_time_update', packet.data)

    # Join Game/Respawn - New Dimension
    def handle_new_dimension(self, name, packet):
        self.world.new_dimension(packet.data['dimension'])
        self.event.emit('world_new_dimension', packet.data['dimension'])

    # Chunk Data - Update World state
    def handle_chunk_data(self, name, packet):
        self.world.unpack_column(packet.data)

    # Multi Block Change - Update multiple blocks
    def handle_multi_block_change(self, name, packet):
        chunk_x = packet.data['chunk_x'] * 16
        chunk_z = packet.data['chunk_z'] * 16
        for block in packet.data['blocks']:
            x = block['x'] + chunk_x
            z = block['z'] + chunk_z
            y = block['y']
            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'],
            })
{'fraction_non_alphanumeric': 0.11093558012989292, 'fraction_numerical': 0.00210637177461822, 'mean_word_length': 2.786046511627907, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338219', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1672, 'n_words': 416}