예제 #1
0
		/// <summary>
		/// Internal CraftRecipe.
		/// Performs the actual crafting of the recipe.
		/// </summary>
		/// <param name="recipe">CraftingRecipe</param>
		/// <param name="container">Input container</param>
		/// <param name="simulate">If true; does not subtract the ingredients from the container</param>
		/// <returns></returns>
		private ItemStack[] PerformCraftRecipe(CraftingRecipe recipe, Container container = null, bool simulate = false)
		{
			if (!simulate)
			{
				container.Remove(ItemStack.CloneMultiple(true, recipe.RecipeIngredients));
			}

			return ItemStack.GetPersistantMultiple(recipe.Output);
		}
예제 #2
0
		public void IncorrectInputItemsPlacementTest()
		{
			var stick = FrameworkRegistry.GetItem("Stick");
			var stone = FrameworkRegistry.GetItem("Stone");

			var shapedRecipe = new ShapedTestingRecipe();

			var craftingField = new Container(16) { Width = 4 };
			craftingField.Add(1, new ItemStack(stone));
			craftingField.Add(6, new ItemStack(stone));
			craftingField.Add(10, new ItemStack(stick,12));
			craftingField.Add(14, new ItemStack(stick));

			Assert.IsFalse(shapedRecipe.CheckRecipe(craftingField));

			craftingField.Remove(1);
			var testItem = new UnitTestItem();
			craftingField.Add(1, new ItemStack(testItem));

			Assert.IsFalse(shapedRecipe.CheckRecipe(craftingField));
		}
예제 #3
0
		public void ItemContainerSubtractionTest()
		{
			// Percentage amount in the ItemStacks
			float p1 = 0.8f;
			float p2 = 0.6f;
			float p3 = p1 + p2 - 1;

			// Stack sizes
			int q1 = (int)(Common.ItemStackSize * p1);
			int q2 = (int)(Common.ItemStackSize * p2);
			int q3 = (int)(Common.ItemStackSize * p3);

			// ItemStacks
			ItemStack i1 = common.GetItemStack(q1);
			ItemStack i2 = common.GetItemStack(q2);
			ItemStack i3 = common.GetItemStack(q3);

			// Container
			Container container = new Container(3);
			
			// Add ItemStacks to the Container
			container.Add(i1, i2);

			// Remove ItemStack from the Container
			container.Remove(i3);

			// Check that the right amount is in the first ItemStack
			Assert.AreEqual(Common.ItemStackSize - q3, container.Get(0).Amount);

			// Check that the right amount is in the second ItemStack
			Assert.AreEqual(q3, container.Get(1).Amount);

			// Check that the right amount is returned
			Assert.AreEqual(Common.ItemStackSize, container.Count(common.GetItem().GetType()));
		}