Created
March 18, 2011 13:08
-
-
Save squiddy/876034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Block(object): | |
""" | |
Block IDs this class is responsible for. | |
""" | |
slots = tuple() | |
def build(self, factory, player, x, y, z, face): | |
""" | |
Called when a player places a block of this type. | |
""" | |
def dig(self, factory, player, x, y, z): | |
""" | |
Called when a player digs a block of this type. | |
""" | |
def use(self, factory, player, x, y, z, left_button=True): | |
""" | |
Called when a player clicks a block of this type. | |
""" | |
class Inventories(object): | |
""" | |
XXX Maybe this is worth an exception. wclose and waction packets are | |
already handled at the protocol layer. | |
""" | |
slots = ("workbench", "furnace", "dispenser", ) | |
def use(self, factory, player, x, y, z, left_button=True): | |
""" | |
Open window. | |
""" | |
if not left_button: | |
i = Workbench() | |
# Do stuff. | |
else: | |
# Continue with basic digging. (?) | |
return | |
class Torch(object): | |
slots = ("torch", "redstone-torch", ) | |
metadata = Metadata( | |
Face("-x", 0x2), | |
Face("+x", 0x1) | |
) | |
def dig(self, factory, player, x, y, z): | |
""" | |
Destroy torch. | |
Spawn pickup. | |
""" | |
class Ladder(object): | |
slots = ("ladder", ) | |
metadata = Metadata( | |
Face("-x", 0x4), | |
Face("+x", 0x5) | |
) | |
# This could work. | |
# Entities implement the `attack` interface to handle attacks. | |
class Entity(object): | |
types = ("creeper", "squid", "player", ) | |
def attack(self, factory, attacker, left_button=True): | |
""" | |
Ouch. | |
""" | |
# XXX What about items that create entities when placed? | |
class Painting(object): | |
""" | |
Paintings are entities, they are removed when a player clicks on them. | |
Digging has no effect. | |
""" | |
slots = ("paintings", ) | |
def build(self, factory, player, x, y, z, face): | |
self.factory.create_entity("Painting", | |
# ... | |
) | |
# But it could be nice, if we implement a `attack` interface here, even | |
# thought it is triggered by `Entity action`. | |
def attack(self, factory, attacker, left_button=True): | |
""" | |
Remove painting, drop pickup. | |
""" | |
# But then, this needs to be handled as both a block and an entity. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment