本文整理汇总了Python中inventory.Inventory.remove_unnecessary_stacks方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.remove_unnecessary_stacks方法的具体用法?Python Inventory.remove_unnecessary_stacks怎么用?Python Inventory.remove_unnecessary_stacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.remove_unnecessary_stacks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import remove_unnecessary_stacks [as 别名]
def test_remove(self):
inv = Inventory(slot_count=20)
block = random.choice(G.BLOCKS_DIR.keys())
max_items = G.BLOCKS_DIR[block].max_stack_size * 20
for i in xrange(0, max_items):
self.assertTrue(inv.add_item(block))
self.assertFalse(inv.remove_item(block, quantity=0))
for i in xrange(0, 20):
self.assertTrue(inv.remove_item(block, quantity=G.BLOCKS_DIR[block].max_stack_size))
self.assertEqual(inv.slots, [None] * 20)
for i in xrange(0, max_items):
self.assertTrue(inv.add_item(block))
for i in xrange(0, 20):
self.assertTrue(inv.remove_by_index(i, quantity=G.BLOCKS_DIR[block].max_stack_size))
self.assertEqual(inv.slots, [None] * 20)
for i in xrange(0, 20):
inv.slots[i] = ItemStack(block, amount=1)
inv.slots[i].change_amount(-1)
inv.remove_unnecessary_stacks()
self.assertEqual(inv.slots, [None] * 20)
示例2: InventorySelector
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import remove_unnecessary_stacks [as 别名]
#.........这里部分代码省略.........
crafting_rows = (2 if self.mode == 0 else 3 if self.mode == 1 else 2)
quick_slots_y = self.frame.y + 4
inventory_y = quick_slots_y + 42
inventory_height = (inventory_rows * (self.icon_size * 0.5)) + (inventory_rows * 3)
crafting_items_per_row = (2 if self.mode == 0 else 3 if self.mode == 1 else 1)
crafting_y = inventory_y + inventory_height + (42 if self.mode == 0 else 14 if self.mode == 1 else 32)
crafting_x = self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63)
crafting_height = (crafting_rows * (self.icon_size * 0.5)) + (crafting_rows * 3)
crafting_width = (crafting_items_per_row * (self.icon_size * 0.5)) + (crafting_items_per_row-1) * 3
armor_y = inventory_y + inventory_height + 10
armor_x = self.frame.x + 7
armor_height = 4 * (self.icon_size * 0.5 + 3)
armor_width = self.icon_size * 0.5
crafting_outcome_y = inventory_y + inventory_height + (60 if self.mode == 0 else 42 if self.mode == 1 else 57)
crafting_outcome_x = self.frame.x + (270 if self.mode == 0 else 222)
crafting_outcome_width = crafting_outcome_height = self.icon_size * 0.5
# out of bound
if (x <= self.frame.x + 7) or (x >= (self.frame.x + self.frame.width) - 7) or (y <= quick_slots_y) or y >= (armor_y + armor_height):
return -1, -1
x_offset = x - (self.frame.x + 7)
if y <= quick_slots_y + 35:
row = 0.0
inventory = self.player.quick_slots
items_per_row = 9
elif y <= inventory_y + inventory_height and y >= inventory_y:
y_offset = (y - (inventory_y + inventory_height)) * -1
row = floor(y_offset // (self.icon_size * 0.5 + 3))
if self.mode == 0:
self.crafting_panel.remove_unnecessary_stacks()
elif self.mode == 1:
self.crafting_table_panel.remove_unnecessary_stacks()
elif self.mode == 2:
self.furnace_panel.remove_unnecessary_stacks()
inventory = self.player.inventory
items_per_row = 9
elif crafting_y <= y <= crafting_y + crafting_height and x >= crafting_x \
and x <= crafting_x + crafting_width:
y_offset = (y - (crafting_y + crafting_height)) * -1
row = floor(y_offset // (self.icon_size * 0.5 + 3))
if self.mode == 0:
self.crafting_panel.remove_unnecessary_stacks()
inventory = self.crafting_panel
elif self.mode == 1:
self.crafting_table_panel.remove_unnecessary_stacks()
inventory = self.crafting_table_panel
elif self.mode == 2:
self.furnace_panel.remove_unnecessary_stacks()
inventory = self.furnace_panel
x_offset = x - crafting_x
items_per_row = crafting_items_per_row
elif crafting_outcome_y <= y <= crafting_outcome_y + crafting_outcome_height and \
crafting_outcome_x <= x <= crafting_outcome_x + crafting_outcome_width:
#print('Crafting outcome!')
return 0, 256 # 256 for crafting outcome
elif armor_y <= y <= armor_y + armor_height and \
armor_x <= x <= armor_x + armor_width:
items_per_row = 1
row = floor((armor_y + armor_height - y) // (self.icon_size * 0.5))
x_offset = 0
inventory = self.player.armor
else: