Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block.py and add test for file block.py #25

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ed6a196
Fix block.py and add test for file
hashbangstudio Oct 1, 2014
ff8a464
Added missing enum34 dependency
doismellburning Oct 1, 2014
4d18907
Rename test to indicate not py.test form
hashbangstudio Oct 1, 2014
d6db56f
Revert "Added missing enum34 dependency"
doismellburning Oct 1, 2014
9a1edc7
Remove runner code in test
hashbangstudio Oct 1, 2014
b69f607
Remove block ordering comparisons
hashbangstudio Oct 1, 2014
9182af3
Remove ordered comparison tests
hashbangstudio Oct 1, 2014
1c6ec04
Undo unintentional indent change
hashbangstudio Oct 1, 2014
810f99d
Update setup.py to inline with master
hashbangstudio Oct 1, 2014
728b943
Fix comparison and typo
hashbangstudio Oct 1, 2014
acf013c
Use PEP8 method names and clarify enum test
hashbangstudio Oct 1, 2014
bed58c6
Fix missing func def and class naming
hashbangstudio Oct 1, 2014
11bb748
Hopefully correct unintentional indent change
hashbangstudio Oct 1, 2014
c8dad24
Move to PEP8 compliant naming
hashbangstudio Oct 2, 2014
2d3500c
Move to py.test style
hashbangstudio Oct 2, 2014
3c1fd01
Rename for clarity and PEP8
hashbangstudio Oct 2, 2014
f42e1f3
Add eval repr test and use constant string
hashbangstudio Oct 2, 2014
ffb7ca3
Merge remote-tracking branch 'upstream/block-update' into block-update
hashbangstudio Oct 19, 2014
b677dc6
Merge remote-tracking branch 'upstream/master' into block-update
hashbangstudio Oct 19, 2014
a3e3a00
Fix conflict between files
hashbangstudio Oct 19, 2014
8cb35c0
Add new block elements
hashbangstudio Oct 19, 2014
23f43fe
Remove default type assignment
hashbangstudio Oct 19, 2014
2f58179
Also remove the comment line
hashbangstudio Oct 19, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 139 additions & 8 deletions mcpi/block.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
from enum import IntEnum


class Block:
"""Minecraft PI block description. Can be sent to Minecraft.setBlock/s"""
def __init__(self, id, data=0):
self.id = id
"""
Minecraft PI block description. Can be sent to Minecraft.setBlock/s
block.type = the blockID of a block (Its material)
For example grass, sand, dirt or wool
block.data = The variant of the type of block.
For example the colour of wool or the orientation of stairs
"""
def __init__(self, type, data=0):
self.type = type
self.data = data

def __eq__(self, rhs):
"""
Equality override
Two blocks are equal only if both the type and data attributes are equal
"""
return all([self.type == rhs.type, self.data == rhs.data])

def __ne__(self, rhs):
"""
not equal override
"""
return not (self == rhs)

def __hash__(self):
return (self.id << 8) + self.data
"""
Override of hash generation
Returns a hashed representation of contents of block
"""
return (self.type << 8) + self.data

def withData(self, data):
return Block(self.id, data)
"""
Returns a new block with the same type as the invoking block but
with the passed in data value
"""
return Block(self.type, data)

def __iter__(self):
"""Allows a Block to be sent whenever id [and data] is needed"""
return iter((self.id, self.data))
"""
Returns an Iterator of the contents of the Block class
Makes the Block an Iterable object
This means that Block can be treated like a list/tuple in places
list/tuple of type and data
For example when flattening lists or *args
Allows a Block to be sent whenever id [and data] is needed
"""
return iter((self.type, self.data))

def __repr__(self):
return "Block(%d, %d)" % (self.id, self.data)
""" Override string representation """
return "Block(%d, %d)" % (self.type, self.data)

@property
def id(self):
""" Here for backwards compatibility for previous attribute name """
return self.type

AIR = Block(0)
STONE = Block(1)
Expand Down Expand Up @@ -89,3 +132,91 @@ def __repr__(self):
FENCE_GATE = Block(107)
GLOWING_OBSIDIAN = Block(246)
NETHER_REACTOR_CORE = Block(247)

ALL_BLOCKS = (AIR, STONE, GRASS, DIRT, COBBLESTONE, WOOD_PLANKS, SAPLING, BEDROCK,
WATER_FLOWING, WATER, WATER_STATIONARY, LAVA_FLOWING, LAVA, LAVA_STATIONARY,
SAND, GRAVEL, GOLD_ORE, IRON_ORE, COAL_ORE, WOOD, LEAVES, GLASS,
LAPIS_LAZULI_ORE, LAPIS_LAZULI_BLOCK, SANDSTONE, BED, COBWEB, GRASS_TALL,
WOOL, FLOWER_YELLOW, FLOWER_CYAN, MUSHROOM_BROWN, MUSHROOM_RED,
GOLD_BLOCK, IRON_BLOCK, STONE_SLAB_DOUBLE, STONE_SLAB, BRICK_BLOCK,
TNT, BOOKSHELF, MOSS_STONE, OBSIDIAN, TORCH, FIRE, STAIRS_WOOD, CHEST,
DIAMOND_ORE, DIAMOND_BLOCK, CRAFTING_TABLE, FARMLAND,
FURNACE_INACTIVE, FURNACE_ACTIVE, DOOR_WOOD, LADDER,
STAIRS_COBBLESTONE, DOOR_IRON, REDSTONE_ORE, SNOW, ICE, SNOW_BLOCK,
CACTUS, CLAY, SUGAR_CANE, FENCE, GLOWSTONE_BLOCK, BEDROCK_INVISIBLE, STONE_BRICK,
GLASS_PANE, MELON, FENCE_GATE, GLOWING_OBSIDIAN, NETHER_REACTOR_CORE, )


class BlockType(IntEnum):
AIR = 0
STONE = 1
GRASS = 2
DIRT = 3
COBBLESTONE = 4
WOOD_PLANKS = 5
SAPLING = 6
BEDROCK = 7
WATER_FLOWING = 8
WATER = WATER_FLOWING
WATER_STATIONARY = 9
LAVA_FLOWING = 10
LAVA = LAVA_FLOWING
LAVA_STATIONARY = 11
SAND = 12
GRAVEL = 13
GOLD_ORE = 14
IRON_ORE = 15
COAL_ORE = 16
WOOD = 17
LEAVES = 18
GLASS = 20
LAPIS_LAZULI_ORE = 21
LAPIS_LAZULI_BLOCK = 22
SANDSTONE = 24
BED = 26
COBWEB = 30
GRASS_TALL = 31
WOOL = 35
FLOWER_YELLOW = 37
FLOWER_CYAN = 38
MUSHROOM_BROWN = 39
MUSHROOM_RED = 40
GOLD_BLOCK = 41
IRON_BLOCK = 42
STONE_SLAB_DOUBLE = 43
STONE_SLAB = 44
BRICK_BLOCK = 45
TNT = 46
BOOKSHELF = 47
MOSS_STONE = 48
OBSIDIAN = 49
TORCH = 50
FIRE = 51
STAIRS_WOOD = 53
CHEST = 54
DIAMOND_ORE = 56
DIAMOND_BLOCK = 57
CRAFTING_TABLE = 58
FARMLAND = 60
FURNACE_INACTIVE = 61
FURNACE_ACTIVE = 62
DOOR_WOOD = 64
LADDER = 65
STAIRS_COBBLESTONE = 67
DOOR_IRON = 71
REDSTONE_ORE = 73
SNOW = 78
ICE = 79
SNOW_BLOCK = 80
CACTUS = 81
CLAY = 82
SUGAR_CANE = 83
FENCE = 85
GLOWSTONE_BLOCK = 89
BEDROCK_INVISIBLE = 95
STONE_BRICK = 98
GLASS_PANE = 102
MELON = 103
FENCE_GATE = 107
GLOWING_OBSIDIAN = 246
NETHER_REACTOR_CORE = 247
Loading