# Path: terrabot/util/streamer.py
# class Streamer(object):
#     """A class for streaming data from a databuffer."""
# 
#     def __init__(self, data):
#         self.data = data
#         self.index = 0
# 
#     def next_short(self):
#         result = struct.unpack("<h", self.data[self.index: self.index + 2])[0]
#         self.index += 2
#         return result
# 
#     def next_u_short(self):
#         result = struct.unpack("<H", self.data[self.index: self.index + 2])[0]
#         self.index += 2
#         return result
# 
#     def next_int32(self):
#         result = struct.unpack("<i", self.data[self.index: self.index + 4])[0]
#         self.index += 4
#         return result
# 
#     def next_byte(self):
#         result = self.data[self.index]
#         self.index += 1
#         return result
# 
#     def next_float(self):
#         result = struct.unpack("<f", self.data[self.index: self.index + 4])[0]
#         self.index += 4
#         return result
# 
#     def remainder(self):
#         return self.data[self.index:]
# 
# Path: terrabot/events/events.py
# class Events(enum.Enum):
#     # Trigger: chat message
#     # Data: message as string
#     Chat = 0
# 
#     # Trigger: Tile information
#     # Data: 2D array of Tiles
#     TileUpdate = 1
# 
#     # Trigger: Login
#     # Data: null
#     Login = 2
# 
#     # Trigger: PlayerID packet comes in
#     # Data: PlayerID as int
#     PlayerID = 3
# 
#     # Trigger: Access blocked
#     # Data: reason-message as string
#     Blocked = 4
# 
#     # Trigger: Initialization on the server
#     # Data: null
#     Initialized = 5
# 
#     # Trigger: Item owner changes
#     # Data: Tuple: (item_id, owner_id)
#     ItemOwnerChanged = 6
# 
#     # Trigger: A new item drops
#     # Data: Item object
#     ItemDropped = 7
# 
#     # Trigger: Server sends update on an item
#     # Data: Item object
#     ItemDropUpdate = 8
# 
#     # Trigger: A new player joins
#     # Data: PlayerID
#     NewPlayer = 9
# 
# Path: terrabot/data/item.py



from terrabot.util.streamer import Streamer
from terrabot.events.events import Events
from terrabot.data.item import Item


class Packet15Parser(object):

	def parse(self, world, player, data, ev_man):
		streamer = Streamer(data)
		streamer.next_byte()  # Skip packet byte
		item_id = streamer.next_short()
		position = (streamer.next_float(), streamer.next_float())
		velocity = (streamer.next_float(), streamer.next_float())
		stacks = streamer.next_short()
		prefix = streamer.next_byte()
		no_delay = streamer.next_byte()
		net_id = streamer.next_short()


# Path: terrabot/util/streamer.py
# class Streamer(object):
#     """A class for streaming data from a databuffer."""
# 
#     def __init__(self, data):
#         self.data = data
#         self.index = 0
# 
#     def next_short(self):
#         result = struct.unpack("<h", self.data[self.index: self.index + 2])[0]
#         self.index += 2
#         return result
# 
#     def next_u_short(self):
#         result = struct.unpack("<H", self.data[self.index: self.index + 2])[0]
#         self.index += 2
#         return result
# 
#     def next_int32(self):
#         result = struct.unpack("<i", self.data[self.index: self.index + 4])[0]
#         self.index += 4
#         return result
# 
#     def next_byte(self):
#         result = self.data[self.index]
#         self.index += 1
#         return result
# 
#     def next_float(self):
#         result = struct.unpack("<f", self.data[self.index: self.index + 4])[0]
#         self.index += 4
#         return result
# 
#     def remainder(self):
#         return self.data[self.index:]
# 
# Path: terrabot/events/events.py
# class Events(enum.Enum):
#     # Trigger: chat message
#     # Data: message as string
#     Chat = 0
# 
#     # Trigger: Tile information
#     # Data: 2D array of Tiles
#     TileUpdate = 1
# 
#     # Trigger: Login
#     # Data: null
#     Login = 2
# 
#     # Trigger: PlayerID packet comes in
#     # Data: PlayerID as int
#     PlayerID = 3
# 
#     # Trigger: Access blocked
#     # Data: reason-message as string
#     Blocked = 4
# 
#     # Trigger: Initialization on the server
#     # Data: null
#     Initialized = 5
# 
#     # Trigger: Item owner changes
#     # Data: Tuple: (item_id, owner_id)
#     ItemOwnerChanged = 6
# 
#     # Trigger: A new item drops
#     # Data: Item object
#     ItemDropped = 7
# 
#     # Trigger: Server sends update on an item
#     # Data: Item object
#     ItemDropUpdate = 8
# 
#     # Trigger: A new player joins
#     # Data: PlayerID
#     NewPlayer = 9
# 
# Path: terrabot/data/item.py



# Path: terrabot/packets/packet15.py
from terrabot.util.streamer import Streamer
from terrabot.events.events import Events
from terrabot.data.item import Item



class Packet15Parser(object):

	def parse(self, world, player, data, ev_man):
		streamer = Streamer(data)
		streamer.next_byte()  # Skip packet byte
		item_id = streamer.next_short()
		position = (streamer.next_float(), streamer.next_float())
		velocity = (streamer.next_float(), streamer.next_float())
		stacks = streamer.next_short()
		prefix = streamer.next_byte()
		no_delay = streamer.next_byte()
		net_id = streamer.next_short()


		item_object = Item(item_id, net_id, position, velocity, prefix, stacks)