def build(self, container): if container.x == -1 and container.z == -1 and container.y == 255: # Lala-land build packet. Discard it for now. return # Is the target being selected? bigx, smallx, bigz, smallz = split_coords(container.x, container.z) try: chunk = self.chunks[bigx, bigz] except KeyError: self.error("Couldn't select in chunk (%d, %d)!" % (bigx, bigz)) return if (chunk.get_block( (smallx, container.y, smallz)) == blocks["workbench"].slot): i = Workbench() sync_inventories(self.player.inventory, i) self.windows[self.wid] = i packet = make_packet("window-open", wid=self.wid, type="workbench", title="Hurp", slots=2) self.wid += 1 self.transport.write(packet) return # Ignore clients that think -1 is placeable. if container.primary == -1: return # Special case when face is "noop": Update the status of the currently # held block rather than placing a new block. if container.face == "noop": return if container.primary in blocks: block = blocks[container.primary] elif container.primary in items: block = items[container.primary] else: log.err("Ignoring request to place unknown block %d" % container.primary) return if time() - self.last_dig_build_timer < 0.05: self.error("You are building too fast.") self.last_dig_build_timer = time() # it's the top of the world, you can't build here if container.y == 127 and container.face == '+y': return builddata = BuildData(block, 0x0, container.x, container.y, container.z, container.face) for hook in self.build_hooks: cont, builddata = yield maybeDeferred(hook.build_hook, self.factory, self.player, builddata) if not cont: break newblock = builddata.block.slot # Feed automatons. for automaton in self.factory.automatons: if newblock in automaton.blocks: automaton.feed(self.factory, (builddata.x, builddata.y, builddata.z)) # Re-send inventory. # XXX this could be optimized if/when inventories track damage. packet = self.player.inventory.save_to_packet() self.transport.write(packet) # Flush damaged chunks. for chunk in self.chunks.itervalues(): self.factory.flush_chunk(chunk)
def setUp(self): self.i = Workbench()