Changing Chest Items
In Forge is another useful file that can be used to change the contents of basically any vanilla-generated chest.
Removing an Item
Following is an example of how to remove an Item from a chest:
ChestGenHooks.removeItem(ChestGenHooks.DUNGEON_CHEST, new ItemStack(Items.saddle));
removeItem is a method in ChestGenHooks, which takes two parameters. The first parameter is a String. This string specifies which chest it should remove an item from. You can manually type this, but it’s suggested to use one of the variables in the ChestGenHooks file.
The second parameter is an ItemStack of the item that has to be removed from the chest.
Adding an Item
Just like with the dungeon mobs, you can also add new things to the chest here. The following code shows how to do that:
ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new
WeightedRandomChestContent(new ItemStack(Blocks.cobblestone), 25, 50, 10));
This method requires two parameters. Like with removeItem, the first parameter is the string that specifies the chest. The second parameter is a WeightedRandomChestContent. This is another file that requires four parameters.
The first parameter in the WeightedRandomChestContent is an ItemStack containing the Item or Block that should be generated. The second parameter is the minimum stack size in which it will generate. The third parameter is the maximum stack size. The final parameter is the chance of it being chosen. Gunpowder has a chance of 10 and a golden apple of 1.