Example #1
0
 def test_check_crafting_offset(self):
     self.i.crafting[1] = Slot(bravo.blocks.items["coal"].slot, 0, 1)
     self.i.crafting[3] = Slot(bravo.blocks.items["stick"].slot, 0, 1)
     # Force crafting table to be rechecked.
     self.i.select(1)
     self.assertTrue(self.i.recipe)
     self.assertEqual(self.i.recipe_offset, 1)
Example #2
0
 def test_select_stack(self):
     self.i.holdables[0] = Slot(2, 0, 1)
     self.i.holdables[1] = Slot(2, 0, 1)
     self.i.select(37)
     self.i.select(36)
     self.assertEqual(self.i.holdables[0], (2, 0, 2))
     self.assertEqual(self.i.holdables[1], None)
Example #3
0
    def test_holds_secondary(self):
        """
        Secondary attributes always matter for .holds.
        """

        slot1 = Slot(4, 5, 1)
        slot2 = Slot(4, 6, 1)
        self.assertFalse(slot1.holds(slot2))
Example #4
0
    def test_holds_secondary(self):
        """
        Secondary attributes always matter for .holds.
        """

        slot1 = Slot(4, 5, 1)
        slot2 = Slot(4, 6, 1)
        self.assertFalse(slot1.holds(slot2))
Example #5
0
 def test_select_secondary_switch(self):
     self.i.holdables[0] = Slot(2, 0, 1)
     self.i.holdables[1] = Slot(3, 0, 1)
     self.i.select(36)
     self.i.select(37, True)
     self.i.select(36, True)
     self.assertEqual(self.i.holdables[0], (3, 0, 1))
     self.assertEqual(self.i.holdables[1], (2, 0, 1))
Example #6
0
 def test_check_crafting_multiple(self):
     self.i.crafting[0] = Slot(bravo.blocks.items["coal"].slot, 0, 2)
     self.i.crafting[2] = Slot(bravo.blocks.items["stick"].slot, 0, 2)
     # Force crafting table to be rechecked.
     self.i.select(2)
     # Only checking count of crafted table; the previous test assured that
     # the recipe was selected.
     self.assertEqual(self.i.crafted[0],
                      (bravo.blocks.blocks["torch"].slot, 0, 4))
Example #7
0
 def test_check_crafting(self):
     self.i.crafting[0] = Slot(bravo.blocks.items["coal"].slot, 0, 1)
     self.i.crafting[2] = Slot(bravo.blocks.items["stick"].slot, 0, 1)
     # Force crafting table to be rechecked.
     self.i.select(2)
     self.assertTrue(self.i.recipe)
     self.assertEqual(self.i.recipe_offset, 0)
     self.assertEqual(self.i.crafted[0],
                      (bravo.blocks.blocks["torch"].slot, 0, 4))
Example #8
0
 def test_consume_holdable_multiple_stacks(self):
     self.i.holdables[0] = Slot(2, 0, 1)
     self.i.holdables[1] = Slot(2, 0, 1)
     # consume second stack
     self.assertTrue(self.i.consume((2, 0), 1))
     self.assertEqual(self.i.holdables[0], (2, 0, 1))
     self.assertEqual(self.i.holdables[1], None)
     # consume second stack a second time
     self.assertFalse(self.i.consume((2, 0), 1))
     self.assertEqual(self.i.holdables[0], (2, 0, 1))
     self.assertEqual(self.i.holdables[1], None)
Example #9
0
 def test_select_secondary_fill_up_stack(self):
     # create two stacks
     self.i.holdables[0] = Slot(2, 0, 40)
     self.i.holdables[1] = Slot(2, 0, 30)
     # select first one
     self.i.select(36)
     # first slot is now empty - holding 40 items
     self.assertEqual(self.i.selected, (2, 0, 40))
     # second stack is untouched
     self.assertEqual(self.i.holdables[1], (2, 0, 30))
     # select second stack with left click
     self.i.select(37, True)
     # sums up to more than 64 items - fill up the second stack
     self.assertEqual(self.i.holdables[1], (2, 0, 64))
     # still hold the left overs
     self.assertEqual(self.i.selected, (2, 0, 6))
Example #10
0
 def test_check_crafting(self):
     self.i.crafting[0] = Slot(bravo.blocks.blocks["log"].slot, 0, 1)
     # Force crafting table to be rechecked.
     self.i.select(2)
     self.assertTrue(self.i.recipe)
     self.assertEqual(self.i.recipe_offset, 0)
     self.assertEqual(self.i.crafted[0],
                      (bravo.blocks.blocks["wood"].slot, 0, 4))
Example #11
0
    def _load_inventory_from_tag(self, inventory, tag):
        """
        Load an inventory from a tag.

        Due to quirks of inventory, we cannot instantiate the inventory here;
        instead, act on an inventory passed in from above.
        """
        items = [None] * len(inventory)

        for item in tag.tags:
            slot = item["Slot"].value
            items[slot] = Slot(item["id"].value,
                item["Damage"].value, item["Count"].value)

        inventory.load_from_list(items)
Example #12
0
 def test_check_crafting_multiple(self):
     self.i.crafting[0] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[1] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[2] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[3] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[5] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[6] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[7] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     self.i.crafting[8] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0,
                               2)
     # Force crafting table to be rechecked.
     self.i.select(5)
     self.assertEqual(self.i.crafted[0],
                      (bravo.blocks.blocks["furnace"].slot, 0, 1))
Example #13
0
 def test_select_secondary_odd(self):
     self.i.holdables[0] = Slot(2, 0, 3)
     self.i.select(36, True)
     self.assertEqual(self.i.holdables[0], (2, 0, 1))
     self.assertEqual(self.i.selected, (2, 0, 2))
Example #14
0
 def test_decrement_none(self):
     slot = Slot(0, 0, 1)
     self.assertEqual(slot.decrement(), None)
Example #15
0
 def test_holds(self):
     slot1 = Slot(4, 5, 1)
     slot2 = Slot(4, 5, 1)
     self.assertTrue(slot1.holds(slot2))
Example #16
0
 def test_decrement_none(self):
     slot = Slot(0, 0, 1)
     self.assertEqual(slot.decrement(), None)
Example #17
0
 def test_consume_holdable_second_slot(self):
     self.i.holdables[1] = Slot(2, 0, 1)
     self.assertTrue(self.i.consume((2, 0), 1))
     self.assertEqual(self.i.holdables[1], None)
Example #18
0
 def test_consume_holdable(self):
     self.i.holdables[0] = Slot(2, 0, 1)
     self.assertTrue(self.i.consume((2, 0), 0))
     self.assertEqual(self.i.holdables[0], None)
Example #19
0
 def test_add_to_inventory_fill_slot(self):
     self.i.holdables[0] = Slot(2, 0, 50)
     self.assertTrue(self.i.add((2, 0), 30))
     self.assertEqual(self.i.holdables[0], (2, 0, 64))
     self.assertEqual(self.i.holdables[1], (2, 0, 16))
Example #20
0
 def test_holds(self):
     slot1 = Slot(4, 5, 1)
     slot2 = Slot(4, 5, 1)
     self.assertTrue(slot1.holds(slot2))