(Ideally, this code could go wherever your mod's initialization method is)
In the above code, when a chest's contents are generated, it will try between 7-8 times (exclusive of max parameter) to select a random item to add to the inventory.
WeightedRandomChestContent has 2 constructors
WeightedRandomChestContent(int itemId, int damage, int minChance, int maxChance, int itemWeight)
WeightedRandomChestContent(ItemStack itemStack, int minChance, int maxChance, int itemWeight)
When a WeightedRandomChestContent entry is selected for generation, it will produce between minChance and maxChance items of that type (inclusive).
The probability of an entry being selected is the itemWeight for a particular item divided by the combined itemWeight for all the entries.
In the above example, the combined item weight is 35, so cocoa beans would have a probability of 10/35 (28.6%) of being selected.
To actually generate the items in your chest, you would use this code
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof IInventory)
{
ChestGenHooks info = ChestGenHooks.getInfo("Category");
WeightedRandomChestContent.generateChestContents(random, info.getItems(random), te, info.getCount(random));
}
Note the "Category" string, this name should be unique. 'world' and 'random' are your standard World and Random parameters, and x, y, z are is the position at which you previously created the chest.
This should work for any chest that implements IInventory.
I haven't been able to find any tutorials, the only one shows how to add items to existing chests.
Thanks in advance
(Ideally, this code could go wherever your mod's initialization method is)
In the above code, when a chest's contents are generated, it will try between 7-8 times (exclusive of max parameter) to select a random item to add to the inventory.
WeightedRandomChestContent has 2 constructors
WeightedRandomChestContent(int itemId, int damage, int minChance, int maxChance, int itemWeight)
WeightedRandomChestContent(ItemStack itemStack, int minChance, int maxChance, int itemWeight)
When a WeightedRandomChestContent entry is selected for generation, it will produce between minChance and maxChance items of that type (inclusive).
The probability of an entry being selected is the itemWeight for a particular item divided by the combined itemWeight for all the entries.
In the above example, the combined item weight is 35, so cocoa beans would have a probability of 10/35 (28.6%) of being selected.
To actually generate the items in your chest, you would use this code
Note the "Category" string, this name should be unique. 'world' and 'random' are your standard World and Random parameters, and x, y, z are is the position at which you previously created the chest.
This should work for any chest that implements IInventory.
I am terrible at figuring out the config for custom loot chests. is there a tutorial someone could point me in the direction of?
He don't cheese! Baby, Baby! He don't cheese!