256
edits
Line 187: | Line 187: | ||
} | } | ||
return itemStacks.Values; | return itemStacks.Values; | ||
} | |||
</syntaxhighlight> | |||
Here we make our ShuffleBag by calling MakeShuffleBag. We calculate a grabCount which is random number between MIN_ITEMS and MAX_ITEMS that controls the number of times Santa is going to reach into his bag. We don't want to create an ItemStack for each item because we may get 3 iron ingots for example. We don't want 3 slots with one iron ingot, we want one slot with 3 iron ingots. So we create a Dictionary and add items of the same type to the same ItemStack. This method returns an IEnumerable that we can loop over so we need to add a method that can loop over a list of ItemStacks and add them to our chest. | |||
<syntaxhighlight lang="c#"> | |||
private void AddItemStacks(IBlockEntityContainer chest, IEnumerable<ItemStack> itemStacks) | |||
{ | |||
int slotNumber = 0; | |||
foreach (ItemStack itemStack in itemStacks) | |||
{ | |||
slotNumber = Math.Min(slotNumber, chest.Inventory.QuantitySlots - 1); | |||
IItemSlot slot = chest.Inventory.GetSlot(slotNumber); | |||
slot.Itemstack = itemStack; | |||
slotNumber++; | |||
} | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
edits