def cb(chunk): for i, o in ((True, False), (False, True)): # Reset the hook. self.hook.asic = Asic() # The tableau. chunk.set_block((2, 1, 1), blocks["sand"].slot) chunk.set_block((3, 1, 1), blocks["redstone-torch"].slot) # Attach the lever to the sand block, and throw it. For sanity # purposes, grab the orientation metadata from the block # definition. orientation = blocks["lever"].orientation("-x") iblock, imetadata = truthify_block(i, blocks["lever"].slot, orientation) chunk.set_block((1, 1, 1), iblock) chunk.set_metadata((1, 1, 1), imetadata) # Attach the torch to the sand block too. orientation = blocks["redstone-torch"].orientation("+x") chunk.set_metadata((3, 1, 1), orientation) # Run the circuit, starting at the switch. self.hook.feed((1, 1, 1)) # Lever, torch, sand. self.hook.process() self.hook.process() self.hook.process() block = chunk.get_block((3, 1, 1)) metadata = chunk.get_metadata((3, 1, 1)) self.assertEqual((block, metadata), truthify_block(o, block, metadata))
def cb(chunk): for i1, i2, o in ( (False, False, False), (True, False, True), (False, True, True), (True, True, True), ): # The tableau. chunk.set_block((1, 1, 2), blocks["sand"].slot) chunk.set_block((2, 1, 2), blocks["redstone-wire"].slot) # Attach the levers to the sand block. orientation = blocks["lever"].orientation("+z") iblock, imetadata = truthify_block(i1, blocks["lever"].slot, orientation) chunk.set_block((1, 1, 1), iblock) chunk.set_metadata((1, 1, 1), imetadata) orientation = blocks["lever"].orientation("-z") iblock, imetadata = truthify_block(i2, blocks["lever"].slot, orientation) chunk.set_block((1, 1, 3), iblock) chunk.set_metadata((1, 1, 3), imetadata) # Run the circuit, starting at the switches. circuit = list(self.hook.run_circuit(1, 1, 1))[0] self.hook.run_circuit(*circuit) circuit = list(self.hook.run_circuit(1, 1, 3))[0] self.hook.run_circuit(*circuit) block = chunk.get_block((2, 1, 2)) metadata = chunk.get_metadata((2, 1, 2)) self.assertEqual((block, metadata), truthify_block(o, block, metadata))
def cb(chunk): for i1, i2, o in ( (False, False, False), (True, False, False), (False, True, False), (True, True, True), ): # Reset the hook. self.hook.asic = Asic() # The tableau. chunk.set_block((1, 1, 1), blocks["sand"].slot) chunk.set_block((1, 1, 2), blocks["sand"].slot) chunk.set_block((1, 1, 3), blocks["sand"].slot) chunk.set_block((1, 2, 1), blocks["redstone-torch"].slot) chunk.set_metadata((1, 2, 1), blocks["redstone-torch"].orientation("+y")) chunk.set_block((1, 2, 3), blocks["redstone-torch"].slot) chunk.set_metadata((1, 2, 3), blocks["redstone-torch"].orientation("+y")) chunk.set_block((1, 2, 2), blocks["redstone-wire"].slot) # Output torch. chunk.set_block((2, 1, 2), blocks["redstone-torch"].slot) chunk.set_metadata((2, 1, 2), blocks["redstone-torch"].orientation("+x")) # Attach the levers to the sand block. orientation = blocks["lever"].orientation("-x") iblock, imetadata = truthify_block(i1, blocks["lever"].slot, orientation) chunk.set_block((0, 1, 1), iblock) chunk.set_metadata((0, 1, 1), imetadata) iblock, imetadata = truthify_block(i2, blocks["lever"].slot, orientation) chunk.set_block((0, 1, 3), iblock) chunk.set_metadata((0, 1, 3), imetadata) # Run the circuit, starting at the switches. Six times: # Lever (x2), sand (x2), torch (x2), wire, block, torch. self.hook.feed((0, 1, 1)) self.hook.feed((0, 1, 3)) self.hook.process() self.hook.process() self.hook.process() self.hook.process() self.hook.process() self.hook.process() block = chunk.get_block((2, 1, 2)) metadata = chunk.get_metadata((2, 1, 2)) self.assertEqual((block, metadata), truthify_block(o, block, metadata))
def test_truthify_lever(self): """ Ditto for truthification. """ self.assertEqual(truthify_block(True, blocks["lever"].slot, 0x3), (blocks["lever"].slot, 0xb))
def test_falsify_lever(self): """ Levers should be falsifiable without affecting which block they are attached to. """ self.assertEqual(truthify_block(False, blocks["lever"].slot, 0xd), (blocks["lever"].slot, 0x5))
def test_wire_idempotence(self): """ A wire which is already on shouldn't have its value affected by ``truthify_block()``. """ self.assertEqual( truthify_block(True, blocks["redstone-wire"].slot, 0x9), (blocks["redstone-wire"].slot, 0x9))
def to_block(self, block, metadata): return truthify_block(self.status, block, metadata)