def sign(self, container): bigx, smallx, bigz, smallz = split_coords(container.x, container.z) try: chunk = self.chunks[bigx, bigz] except KeyError: self.error("Couldn't handle sign in chunk (%d, %d)!" % (bigx, bigz)) return if (smallx, container.y, smallz) in chunk.tiles: new = False s = chunk.tiles[smallx, container.y, smallz] else: new = True s = Sign(smallx, container.y, smallz) chunk.tiles[smallx, container.y, smallz] = s s.text1 = container.line1 s.text2 = container.line2 s.text3 = container.line3 s.text4 = container.line4 chunk.dirty = True # The best part of a sign isn't making one, it's showing everybody # else on the server that you did. packet = make_packet("sign", container) self.factory.broadcast_for_chunk(packet, bigx, bigz) # Run sign hooks. for hook in self.sign_hooks: hook.sign_hook(self.factory, chunk, container.x, container.y, container.z, [s.text1, s.text2, s.text3, s.text4], new)
def sign(self, container): bigx, smallx, bigz, smallz = split_coords(container.x, container.z) try: chunk = self.chunks[bigx, bigz] except KeyError: self.error("Couldn't handle sign in chunk (%d, %d)!" % (bigx, bigz)) return if (smallx, container.y, smallz) in chunk.tiles: s = chunk.tiles[smallx, container.y, smallz] else: s = Sign() s.x = smallx s.y = container.y s.z = smallz s.text1 = container.line1 s.text2 = container.line2 s.text3 = container.line3 s.text4 = container.line4 chunk.tiles[smallx, container.y, smallz] = s chunk.dirty = True # The best part of a sign isn't making one, it's showing everybody # else on the server that you did. packet = make_packet("sign", container) self.factory.broadcast_for_chunk(packet, bigx, bigz)
def build_hook(self, factory, player, builddata): item, metadata, x, y, z, face = builddata if item.slot == items["sign"].slot: # Buildin' a sign, puttin' it on a wall... builddata = builddata._replace(block=blocks["wall-sign"]) # Offset coords according to face. if face == "-x": builddata = builddata._replace(metadata=0x4) x -= 1 elif face == "+x": builddata = builddata._replace(metadata=0x5) x += 1 elif face == "-y": # Ceiling Sign is watching you read. return False, builddata elif face == "+y": # Put +Y signs on signposts. We're fancy that way. Also, # calculate the proper orientation based on player # orientation. # 180 degrees around to orient the signs correctly, and then # 23 degrees to get the sign to midpoint correctly. metadata = ((player.location.yaw + 180) * 16 // 360) % 0xf builddata = builddata._replace(block=blocks["signpost"], metadata=metadata) y += 1 elif face == "-z": builddata = builddata._replace(metadata=0x2) z -= 1 elif face == "+z": builddata = builddata._replace(metadata=0x3) z += 1 bigx, smallx, bigz, smallz = split_coords(x, z) chunk = factory.world.load_chunk(bigx, bigz) # Let's build a sign! s = Sign(smallx, y, smallz) chunk.tiles[smallx, y, smallz] = s elif item.slot == blocks["chest"].slot: if face == "-x": x -= 1 elif face == "+x": x += 1 elif face == "-y": y -= 1 elif face == "+y": y += 1 elif face == "-z": z -= 1 elif face == "+z": z += 1 bigx, smallx, bigz, smallz = split_coords(x, z) chunk = factory.world.load_chunk(bigx, bigz) # Not much to do, just tell the chunk about this chest. c = Chest(smallx, y, smallz) chunk.tiles[smallx, y, smallz] = c return True, builddata