Recently, we had a Minecraft tournament at the shop. Tournaments are not tournaments without a clear winner. We were stuck with the problem, how do we know who won? We came to the conclusion to assign a simple point system to some of the ores, ingots and minerals you can mine in the game. To actually calculate these points, a little bit of programming was used to read the player inventory file on the server. The player file is only written to disk when a client disconnects. This was easily remedied by just stopping the server and calculating the points once each of the inventories were flushed to the drive.
The following is the code we used to read the inventory file and calculate an overall score:
#!/usr/bin/python points = {} # http://www.minecraftwiki.net/wiki/Data_points points['263'] = 1 # coal points['331'] = 1 # redstone points['265'] = 2 # iron ingot points['266'] = 3 # gold bar points['264'] = 5 # diamond score = 0 import nbt import sys nbtfile = nbt.NBTFile(sys.argv[1], "rb") for k in nbtfile['Inventory'].tags: if points.has_key(str(k['id'])): score = score + points[str(k['id'])] * k['Count'].value print score
This code requires the NBT processing library available at https://github.com/twoolie/NBT