示例#1
0
 def test_select_stack(self):
     self.i.inventory.holdables[0] = Slot(2, 0, 1)
     self.i.inventory.holdables[1] = Slot(2, 0, 1)
     self.i.select(37)
     self.i.select(36)
     self.assertEqual(self.i.inventory.holdables[0], (2, 0, 2))
     self.assertEqual(self.i.inventory.holdables[1], None)
示例#2
0
 def test_furnace_no_drop(self):
     self.i.slots.crafted[0] = Slot(1, 0, 1)
     self.i.slots.crafting[0] = Slot(2, 0, 1)
     self.i.slots.fuel[0] = Slot(3, 0, 1)
     items, packets = self.i.close()
     self.assertEqual(items, [])
     self.assertEqual(packets, "")
示例#3
0
    def test_glass_from_sand_on_wood_multiple(self):
        """
        Crafting two glass, from two sand, using ten saplings, should take
        20s and only use four saplings.
        """

        # Patch the clock.
        clock = Clock()
        self.tile.burning.clock = clock

        self.tile.inventory.fuel[0] = Slot(blocks['sapling'].slot, 0, 10)
        self.tile.inventory.crafting[0] = Slot(blocks['sand'].slot, 0, 2)
        self.tile.changed(self.factory, coords)

        # Pump the clock. Burn time is 20s.
        clock.pump([0.5] * 40)

        self.assertEqual(self.factory.world.chunk.states[0],
                         blocks["burning-furnace"].slot) # it was started...
        self.assertEqual(self.factory.world.chunk.states[1],
                         blocks["furnace"].slot) # ...and stopped at the end
        # 2 sands take 20s to smelt, only 4 saplings needed
        self.assertEqual(self.tile.inventory.fuel[0], (blocks['sapling'].slot, 0, 6))
        self.assertEqual(self.tile.inventory.crafting[0], None)
        self.assertEqual(self.tile.inventory.crafted[0], (blocks['glass'].slot, 0, 2))
示例#4
0
 def test_check_crafting_offset(self):
     self.i.crafting[1] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0, 2)
     self.i.crafting[4] = Slot(bravo.blocks.items["stick"].slot, 0, 2)
     self.i.crafting[7] = Slot(bravo.blocks.items["stick"].slot, 0, 2)
     # Force crafting table to be rechecked.
     self.i.update_crafted()
     self.assertTrue(self.i.recipe)
示例#5
0
 def test_dirty_slots_move(self):
     self.i.slots.storage[0] = Slot(2, 0, 1)
     self.i.slots.storage[2] = Slot(1, 0, 4)
     # simple move
     self.i.select(0)
     self.i.select(1)
     self.assertEqual(self.i.dirty_slots, {0: None, 1: (2, 0, 1)})
示例#6
0
    def test_timer_mega_drift(self):
        # Patch the clock.
        clock = Clock()
        self.tile.burning.clock = clock

        # we have more wood than we need and we can process 2 blocks
        # but we have space only for one
        self.tile.inventory.fuel[0] = Slot(blocks['sapling'].slot, 0, 10)
        self.tile.inventory.crafting[0] = Slot(blocks['sand'].slot, 0, 2)
        self.tile.inventory.crafted[0] = Slot(blocks['glass'].slot, 0, 63)
        self.tile.changed(self.factory, coords)

        # Pump the clock. Burn time is 20s.
        clock.advance(20)

        self.assertEqual(self.factory.world.chunk.states[0],
                         blocks["burning-furnace"].slot) # it was started...
        self.assertEqual(self.factory.world.chunk.states[1],
                         blocks["furnace"].slot) # ...and stopped at the end
        self.assertEqual(self.tile.inventory.fuel[0], (blocks['sapling'].slot, 0, 8))
        self.assertEqual(self.tile.inventory.crafting[0], (blocks['sand'].slot, 0, 1))
        self.assertEqual(self.tile.inventory.crafted[0], (blocks['glass'].slot, 0, 64))
        headers = [header[0] for header, params in self.protocol.write_packet_calls]
        # 2 updates for fuel slot (2 saplings burned)
        # 1 updates for crafting slot (1 sand blocks melted)
        # 1 updates for crafted slot (1 glass blocks crafted)
        self.assertEqual(headers.count('window-slot'), 4)
示例#7
0
 def test_check_crafting(self):
     self.i.crafting[0] = Slot(bravo.blocks.blocks["wood"].slot, 0, 1)
     self.i.crafting[2] = Slot(bravo.blocks.blocks["wood"].slot, 0, 1)
     # Force crafting table to be rechecked.
     self.i.update_crafted()
     self.assertTrue(self.i.recipe)
     self.assertEqual(self.i.crafted[0],
         (bravo.blocks.items["stick"].slot, 0, 4))
示例#8
0
 def test_select_secondary_switch(self):
     self.i.inventory.holdables[0] = Slot(2, 0, 1)
     self.i.inventory.holdables[1] = Slot(3, 0, 1)
     self.i.select(36)
     self.i.select(37, True)
     self.i.select(36, True)
     self.assertEqual(self.i.inventory.holdables[0], (3, 0, 1))
     self.assertEqual(self.i.inventory.holdables[1], (2, 0, 1))
示例#9
0
    def test_from_key(self):
        """
        Slots have an alternative constructor.
        """

        slot1 = Slot(2, 3, 1)
        slot2 = Slot.from_key((2, 3))
        self.assertEqual(slot1, slot2)
示例#10
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))
示例#11
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))
示例#12
0
 def test_dirty_slots_move_stack(self):
     self.b.storage[3] = Slot(1, 0, 1)
     self.i.select(30, False, True)
     self.assertEqual(self.b.storage[3], None)
     self.assertEqual(self.i.dirty_slots, {30: None})
     self.i.inventory.holdables[0] = Slot(2, 0, 1)
     self.i.select(81, False, True)
     self.assertEqual(self.i.inventory.holdables[0], None)
     self.assertEqual(self.a.storage[0], (2, 0, 1))
示例#13
0
 def test_check_crafting(self):
     self.i.crafting[0] = Slot(bravo.blocks.blocks["cobblestone"].slot, 0, 1)
     self.i.crafting[3] = Slot(bravo.blocks.items["stick"].slot, 0, 1)
     self.i.crafting[6] = Slot(bravo.blocks.items["stick"].slot, 0, 1)
     # Force crafting table to be rechecked.
     self.i.update_crafted()
     self.assertTrue(self.i.recipe)
     self.assertEqual(self.i.crafted[0],
         (bravo.blocks.items["stone-shovel"].slot, 0, 1))
示例#14
0
 def test_check_crafting_multiple(self):
     self.i.crafting[0] = Slot(bravo.blocks.blocks["wood"].slot, 0, 2)
     self.i.crafting[2] = Slot(bravo.blocks.blocks["wood"].slot, 0, 2)
     # Force crafting table to be rechecked.
     self.i.update_crafted()
     # Only checking count of crafted table; the previous test assured that
     # the recipe was selected.
     self.assertEqual(self.i.crafted[0],
         (bravo.blocks.items["stick"].slot, 0, 4))
示例#15
0
 def test_dirty_slots_split_and_stack(self):
     self.i.slots.storage[0] = Slot(2, 0, 1)
     self.i.slots.storage[2] = Slot(1, 0, 4)
     # split
     self.i.select(2, True)
     self.i.select(1)
     self.assertEqual(self.i.dirty_slots, {1: (1, 0, 2), 2: (1, 0, 2)})
     # stack
     self.i.select(2)
     self.i.select(1)
     self.assertEqual(self.i.dirty_slots, {1: (1, 0, 4), 2: None})
示例#16
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)
示例#17
0
    def test_black_wool_matches_lime(self):
        """
        Lime wool plus an ink sac equals black wool.
        """

        table = [
            Slot.from_key(blocks["lime-wool"].key, 1),
            Slot.from_key(items["ink-sac"].key, 1),
            None,
            None,
        ]
        self.assertTrue(recipe_dict["black-wool"].matches(table, 2))
示例#18
0
 def test_unstackable_items(self):
     shovel = (bravo.blocks.items["wooden-shovel"].slot, 0, 1)
     self.i.inventory.storage[0] = Slot(*shovel)
     self.i.inventory.storage[1] = Slot(*shovel)
     self.i.select(9)
     self.i.select(10)
     self.assertEqual(self.i.inventory.storage[0], None)
     self.assertEqual(self.i.inventory.storage[1], shovel)
     self.assertEqual(self.i.selected, shovel)
     self.i.select(36)
     self.i.select(10, False, True)
     self.assertEqual(self.i.inventory.holdables[0], shovel)
     self.assertEqual(self.i.inventory.holdables[1], shovel)
示例#19
0
 def test_shift_click_crafted_full_inventory(self):
     # there is no space left
     self.i.inventory.storage[:] = [Slot(1, 0, 64)] * 27
     self.i.inventory.holdables[:] = [
         Slot(bravo.blocks.blocks["wood"].slot, 0, 64)
     ] * 9
     # Select log into crafting.
     self.i.slots.crafting[0] = Slot(bravo.blocks.blocks["log"].slot, 0, 2)
     self.i.slots.update_crafted()
     # Shift-Click on wood from crafted.
     self.assertFalse(self.i.select(0, False, True))
     self.assertEqual(self.i.selected, None)
     self.assertEqual(self.i.slots.crafting[0],
                      (bravo.blocks.blocks["log"].slot, 0, 2))
示例#20
0
 def test_stacking_items(self):
     # setup initial items
     self.i.slots.crafting[0] = Slot(1, 0, 2)
     self.i.inventory.storage[0] = Slot(2, 0, 1)
     self.i.inventory.storage[2] = Slot(1, 0, 3)
     self.i.inventory.holdables[0] = Slot(3, 0, 1)
     self.i.inventory.holdables[2] = Slot(1, 0, 62)
     self.i.inventory.holdables[4] = Slot(1, 0, 4)
     # shift-LMB on crafting area
     self.i.select(1, False, True)
     self.assertEqual(self.i.slots.crafting[0], None)
     self.assertEqual(self.i.inventory.storage[1], None)
     self.assertEqual(self.i.inventory.storage[2], (1, 0, 5))
     # shift-LMB on storage area
     self.i.select(11, False, True)
     self.assertEqual(self.i.inventory.storage[2], None)
     self.assertEqual(self.i.inventory.holdables[2], (1, 0, 64))
     self.assertEqual(self.i.inventory.holdables[4], (1, 0, 7))
     # shift-RMB on holdables area
     self.i.select(38, True, True)
     self.assertEqual(self.i.inventory.holdables[2], None)
     self.assertEqual(self.i.inventory.storage[1], (1, 0, 64))
     # check if item goes from crafting area directly to
     # holdables if possible
     self.i.slots.crafting[1] = Slot(1, 0, 60)
     self.i.inventory.storage[3] = Slot(1, 0, 63)
     self.i.select(2, True, True)
     self.assertEqual(self.i.slots.crafting[1], None)
     self.assertEqual(self.i.inventory.storage[2], (1, 0, 2))
     self.assertEqual(self.i.inventory.storage[3], (1, 0, 64))
     self.assertEqual(self.i.inventory.holdables[4], (1, 0, 64))
示例#21
0
    def test_black_wool_matches_lime(self):
        """
        Lime wool plus an ink sac equals black wool.
        """

        if "black-wool" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        table = [
            Slot.from_key(blocks["lime-wool"].key, 1),
            Slot.from_key(items["ink-sac"].key, 1),
            None,
            None,
        ]
        self.assertTrue(self.p["black-wool"].matches(table, 2))
示例#22
0
    def test_black_wool_matches_lime(self):
        """
        Lime wool plus an ink sac equals black wool.
        """

        if "black-wool" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        table = [
            Slot.from_key(blocks["lime-wool"].key, 1),
            Slot.from_key(items["ink-sac"].key, 1),
            None,
            None,
        ]
        self.assertTrue(self.p["black-wool"].matches(table, 2))
示例#23
0
 def test_select_secondary_fill_up_stack(self):
     # create two stacks
     self.i.inventory.holdables[0] = Slot(2, 0, 40)
     self.i.inventory.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.inventory.holdables[1], (2, 0, 30))
     # select second stack with right click
     self.i.select(37, True)
     # sums up to more than 64 items
     self.assertEqual(self.i.inventory.holdables[1], (2, 0, 31))
     # still hold the left overs
     self.assertEqual(self.i.selected, (2, 0, 39))
示例#24
0
 def update_crafted(self):
     self.check_recipes()
     if self.recipe is None:
         self.crafted[0] = None
     else:
         provides = self.recipe.provides
         self.crafted[0] = Slot(provides[0][0], provides[0][1], provides[1])
示例#25
0
    def test_from_key(self):
        """
        Slots have an alternative constructor.
        """

        slot1 = Slot(2, 3, 1)
        slot2 = Slot.from_key((2, 3))
        self.assertEqual(slot1, slot2)
示例#26
0
    def test_can_craft_no_recipe(self):
        """
        Furnaces can't craft if there is no known recipe matching an input in
        the crafting slot.
        """

        self.tile.inventory.crafting[0] = Slot(blocks['rose'].slot, 0, 1)
        self.assertFalse(self.tile.can_craft())
示例#27
0
 def test_dirty_slots_move(self):
     self.a.storage[0] = Slot(1, 0, 1)
     # simple move
     self.i.select(0)
     self.i.select(53)
     self.assertEqual(self.a.storage[0], None)
     self.assertEqual(self.b.storage[26], (1, 0, 1))
     self.assertEqual(self.i.dirty_slots, {0: None, 53: (1, 0, 1)})
示例#28
0
 def test_dirty_slots_packaging(self):
     self.a.storage[0] = Slot(1, 0, 1)
     self.i.select(0)
     self.i.select(53)
     self.assertEqual(self.i.dirty_slots, {0: None, 53: (1, 0, 1)})
     packets = self.i.packets_for_dirty(self.i.dirty_slots)
     self.assertEqual(packets, '\x67\x01\x00\x00\xff\xff' +\
                               '\x67\x01\x00\x35\x00\x01\x01\x00\x00')
示例#29
0
    def test_snow_1ko(self):
        """
        Snow can't be 1KO'd by hand, just with a shovel.
        """

        slot = Slot(items["wooden-shovel"].slot, 0x64, 1)

        self.assertFalse(self.p.is_1ko(blocks["snow"].slot, None))
        self.assertTrue(self.p.is_1ko(blocks["snow"].slot, slot))
示例#30
0
    def test_close_window(self):
        items, packets = self.i.close()
        self.assertEqual(len(items), 0)
        self.assertEqual(packets, "")

        self.i.slots.crafting[0] = Slot(bravo.blocks.items["coal"].slot, 0, 1)
        self.i.slots.crafting[2] = Slot(bravo.blocks.items["stick"].slot, 0, 1)
        self.i.inventory.storage[0] = Slot(3, 0, 1)
        # Force crafting table to be rechecked.
        self.i.slots.update_crafted()
        self.i.select(9)
        items, packets = self.i.close()
        self.assertEqual(self.i.selected, None)
        self.assertEqual(self.i.slots.crafted[0], None)
        self.assertEqual(self.i.slots.crafting, [None] * 4)
        self.assertEqual(len(items), 3)
        self.assertEqual(items[0], (263, 0, 1))
        self.assertEqual(items[1], (280, 0, 1))
        self.assertEqual(items[2], (3, 0, 1))
示例#31
0
 def test_slot_update(self):
     update_all_windows_slot(self.factory, coords, 1, None)
     update_all_windows_slot(self.factory, coords, 2, Slot(blocks['glass'].slot, 0, 13))
     self.assertEqual(self.protocol1.write_packet_calls, [])
     self.assertEqual(self.protocol2.write_packet_calls, [])
     self.assertEqual(len(self.protocol3.write_packet_calls), 2)
     self.assertEqual(self.protocol3.write_packet_calls[0],
         (('window-slot',), {'wid': 2, 'slot': 1, 'primary': -1}))
     self.assertEqual(self.protocol3.write_packet_calls[1],
         (('window-slot',), {'wid': 2, 'slot': 2, 'primary': 20, 'secondary': 0, 'count': 13}))
示例#32
0
文件: windows.py 项目: tazjel/bravo
 def drop_selected(self, alternate=False):
     items = []
     if self.selected is not None:
         if alternate:  # drop one item
             i = Slot(self.selected.primary, self.selected.secondary, 1)
             items.append(i)
             self.selected = self.selected.decrement()
         else:  # drop all
             items.append(self.selected)
             self.selected = None
     return items
示例#33
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.update_crafted()
     self.assertEqual(self.i.crafted[0],
         (bravo.blocks.blocks["furnace"].slot, 0, 1))
示例#34
0
    def test_bed_matches_tie_dye(self):
        """
        Three different colors of wool can be used to build beds.
        """

        table = [
            None,
            None,
            None,
            Slot.from_key(blocks["blue-wool"].key, 1),
            Slot.from_key(blocks["red-wool"].key, 1),
            Slot.from_key(blocks["lime-wool"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
        ]
        self.assertTrue(recipe_dict["bed"].matches(table, 3))
示例#35
0
    def test_bed_matches_tie_dye(self):
        """
        Three different colors of wool can be used to build beds.
        """

        if "bed" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        table = [
            None,
            None,
            None,
            Slot.from_key(blocks["blue-wool"].key, 1),
            Slot.from_key(blocks["red-wool"].key, 1),
            Slot.from_key(blocks["lime-wool"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
            Slot.from_key(blocks["wood"].key, 1),
        ]
        self.assertTrue(self.p["bed"].matches(table, 3))
示例#36
0
 def test_holds(self):
     slot1 = Slot(4, 5, 1)
     slot2 = Slot(4, 5, 1)
     self.assertTrue(slot1.holds(slot2))
示例#37
0
 def test_decrement_none(self):
     slot = Slot(0, 0, 1)
     self.assertEqual(slot.decrement(), None)
示例#38
0
from bravo.beta.structures import Slot
from bravo.blocks import blocks, items
from bravo.inventory.windows import FurnaceWindow

'''
Furnace recipes
'''
furnace_recipes = {
    blocks["cactus"].slot     : Slot.from_key(items["green-dye"].key, 1),
    blocks["cobblestone"].slot: Slot.from_key(blocks["stone"].key, 1),
    blocks["diamond-ore"].slot: Slot.from_key(items["diamond"].key, 1),
    blocks["gold-ore"].slot   : Slot.from_key(items["gold-ingot"].key, 1),
    blocks["iron-ore"].slot   : Slot.from_key(items["iron-ingot"].key, 1),
    blocks["log"].slot        : Slot.from_key(items["charcoal"].key, 1),
    blocks["sand"].slot       : Slot.from_key(blocks["glass"].key, 1),
    items["clay-balls"].slot  : Slot.from_key(items["clay-brick"].key, 1),
    items["raw-fish"].slot    : Slot.from_key(items["cooked-fish"].key, 1),
    items["raw-porkchop"].slot: Slot.from_key(items["cooked-porkchop"].key, 1),
}

def update_all_windows_slot(factory, coords, slot, item):
    '''
    For players who have THIS furnace's window opened send update for
    specified slot: crafting, crafted or fuel.

    :param `BravoFactory` factory: The factory
    :param tuple coords: (bigx, smallx, bigz, smallz, y) - coords of the furnace
    :param int slot: 0 - crafting slot, 1 - fuel slot, 2 - crafted slot
    :param `Slot` item: the slot content
    '''
    for p in factory.protocols.itervalues():