diff --git a/lang b/lang index 371d98e45..cdad7ef9c 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 371d98e450b69f7770b634c45f4887b9e301ad7d +Subproject commit cdad7ef9c59cd68ae153ec4efb2d8c918e823109 diff --git a/src/main/java/forestry/api/core/IForestryConstants.java b/src/main/java/forestry/api/core/IForestryConstants.java index 4e565fc21..42fa1175f 100644 --- a/src/main/java/forestry/api/core/IForestryConstants.java +++ b/src/main/java/forestry/api/core/IForestryConstants.java @@ -5,6 +5,10 @@ ******************************************************************************/ package forestry.api.core; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.event.LootTableLoadEvent; + public interface IForestryConstants { /** @@ -18,7 +22,7 @@ public interface IForestryConstants { int getArboricultureVillagerID(); /** - * @return The ChestGenHooks key for adding items to the Forestry Villager chest. + * @return The {@link LootTableLoadEvent} key for adding items to the Forestry Villager chest. */ - String getVillagerChestGenKey(); + ResourceLocation getVillagerChestLootKey(); } diff --git a/src/main/java/forestry/apiculture/PluginApiculture.java b/src/main/java/forestry/apiculture/PluginApiculture.java index 826d793a4..833288d48 100644 --- a/src/main/java/forestry/apiculture/PluginApiculture.java +++ b/src/main/java/forestry/apiculture/PluginApiculture.java @@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.IChunkGenerator; +import net.minecraft.world.storage.loot.LootTableList; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.BiomeDictionary; @@ -804,34 +805,14 @@ public class PluginApiculture extends BlankForestryPlugin { } private static void registerDungeonLoot() { - int rarity; - if (Config.dungeonLootRare) { - rarity = 5; - } else { - rarity = 10; - } + LootTableList.register(Constants.VILLAGE_NATURALIST_LOOT_KEY); + } - //TODO: Chest Loot - /* - ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new WeightedRandomChestContent(BeeDefinition.STEADFAST.getMemberStack(EnumBeeType.DRONE), 1, 1, rarity)); - - ItemStack stack = blocks.candle.getUnlitCandle(1); - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger(BlockCandle.colourTagName, 0xffffff); - stack.setTagCompound(tag); - - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(stack, 7, 12, 12)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.scoop.getItemStack(), 1, 1, 8)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.smoker.getItemStack(), 1, 1, 8)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.propolis.get(EnumPropolis.NORMAL, 1), 2, 4, 6)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.beeComb.get(EnumHoneyComb.HONEY, 1), 4, 12, 7)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.beeComb.get(EnumHoneyComb.FROZEN, 1), 2, 10, 7)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.beeComb.get(EnumHoneyComb.SILKY, 1), 1, 6, 7)); - - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(BeeDefinition.FOREST.getRainResist().getMemberStack(EnumBeeType.PRINCESS), 1, 1, 5)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(BeeDefinition.COMMON.getMemberStack(EnumBeeType.DRONE), 1, 2, 8)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(BeeDefinition.MEADOWS.getMemberStack(EnumBeeType.PRINCESS), 1, 1, 5)); - */ + @Override + public void addLootPoolNames(Set lootPoolNames) { + super.addLootPoolNames(lootPoolNames); + lootPoolNames.add("forestry_apiculture_items"); + lootPoolNames.add("forestry_apiculture_bees"); } private static void createHives() { diff --git a/src/main/java/forestry/apiculture/blocks/BlockCandle.java b/src/main/java/forestry/apiculture/blocks/BlockCandle.java index c65c6b6d6..8f1f4e238 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockCandle.java +++ b/src/main/java/forestry/apiculture/blocks/BlockCandle.java @@ -322,11 +322,19 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister, ITile } public ItemStack getUnlitCandle(int amount) { - return new ItemStack(this, amount, 0); + ItemStack itemStack = new ItemStack(this, amount, 0); + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger(BlockCandle.colourTagName, 0xffffff); + itemStack.setTagCompound(tag); + return itemStack; } public ItemStack getLitCandle(int amount) { - return new ItemStack(this, amount, 1); + ItemStack itemStack = new ItemStack(this, amount, 1); + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger(BlockCandle.colourTagName, 0xffffff); + itemStack.setTagCompound(tag); + return itemStack; } @Override diff --git a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java index 01c006060..a736e2a92 100755 --- a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java @@ -222,7 +222,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { // TODO: Chest loot // generateChestContents(world, structBoundingBox, random, 7, 1, 4, -// ChestGenHooks.getItems(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, random), + // ChestGenHooks.getItems(Constants.VILLAGE_NATURALIST_LOOT_KEY, random), // random.nextInt(4) + random.nextInt(4) + 5); spawnVillagers(world, boundingBox, 7, 1, 1, 2); diff --git a/src/main/java/forestry/arboriculture/PluginArboriculture.java b/src/main/java/forestry/arboriculture/PluginArboriculture.java index 807ee4035..18e2e0ca4 100644 --- a/src/main/java/forestry/arboriculture/PluginArboriculture.java +++ b/src/main/java/forestry/arboriculture/PluginArboriculture.java @@ -13,6 +13,7 @@ package forestry.arboriculture; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -142,6 +143,12 @@ public class PluginArboriculture extends BlankForestryPlugin { PluginCore.rootCommand.addChildCommand(new CommandTree()); } + @Override + public void addLootPoolNames(Set lootPoolNames) { + super.addLootPoolNames(lootPoolNames); + lootPoolNames.add("forestry_arboriculture_items"); + } + @Override public void doInit() { super.doInit(); @@ -165,12 +172,6 @@ public class PluginArboriculture extends BlankForestryPlugin { }*/ } - @Override - public void postInit() { - super.postInit(); - registerDungeonLoot(); - } - @Override public void registerCrates() { ICrateRegistry crateRegistry = StorageManager.crateRegistry; @@ -416,27 +417,6 @@ public class PluginArboriculture extends BlankForestryPlugin { hiddenItems.add(new ItemStack(blocks.saplingGE)); } - private static void registerDungeonLoot() { - // TODO: Fix chest loot - /* - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(items.grafter.getItemStack(), 1, 1, 8)); - - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Oak.getMemberStack(EnumGermlingType.SAPLING), 2, 3, 6)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Spruce.getMemberStack(EnumGermlingType.SAPLING), 2, 3, 6)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Birch.getMemberStack(EnumGermlingType.SAPLING), 2, 3, 6)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Larch.getMemberStack(EnumGermlingType.SAPLING), 1, 2, 4)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Lime.getMemberStack(EnumGermlingType.SAPLING), 1, 2, 4)); - - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.APICULTURE)) { - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Oak.getMemberStack(EnumGermlingType.POLLEN), 2, 3, 4)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Spruce.getMemberStack(EnumGermlingType.POLLEN), 2, 3, 4)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Birch.getMemberStack(EnumGermlingType.POLLEN), 2, 3, 4)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Larch.getMemberStack(EnumGermlingType.POLLEN), 1, 2, 3)); - ChestGenHooks.addItem(Constants.CHEST_GEN_HOOK_NATURALIST_CHEST, new WeightedRandomChestContent(TreeDefinition.Lime.getMemberStack(EnumGermlingType.POLLEN), 1, 2, 3)); - } - */ - } - private static class FuelHandler implements IFuelHandler { @Override public int getBurnTime(ItemStack fuel) { diff --git a/src/main/java/forestry/core/EventHandlerCore.java b/src/main/java/forestry/core/EventHandlerCore.java index b8552067a..d83cfe360 100755 --- a/src/main/java/forestry/core/EventHandlerCore.java +++ b/src/main/java/forestry/core/EventHandlerCore.java @@ -13,8 +13,12 @@ package forestry.core; import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.loot.LootPool; +import net.minecraft.world.storage.loot.LootTable; import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.event.LootTableLoadEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; @@ -26,7 +30,9 @@ import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.ISpeciesRoot; +import forestry.core.config.Constants; import forestry.core.errors.ErrorStateRegistry; +import forestry.core.loot.LootTableLoader; import forestry.core.render.TextureManager; import forestry.plugins.PluginManager; @@ -90,4 +96,21 @@ public class EventHandlerCore { TextureManager.initDefaultSprites(); } + @SubscribeEvent + public void lootLoad(LootTableLoadEvent event) { + if (!event.getName().getResourceDomain().equals("minecraft")) { + return; + } + + ResourceLocation resourceLocation = new ResourceLocation(Constants.RESOURCE_ID, event.getName().getResourcePath()); + LootTable forestryChestAdditions = LootTableLoader.loadBuiltinLootTable(resourceLocation); + if (forestryChestAdditions != null) { + for (String poolName : PluginManager.getLootPoolNames()) { + LootPool pool = forestryChestAdditions.getPool(poolName); + if (pool != null) { + event.getTable().addPool(pool); + } + } + } + } } diff --git a/src/main/java/forestry/core/PluginCore.java b/src/main/java/forestry/core/PluginCore.java index 5c43fd24e..fa59ba0da 100644 --- a/src/main/java/forestry/core/PluginCore.java +++ b/src/main/java/forestry/core/PluginCore.java @@ -21,6 +21,7 @@ import net.minecraft.command.ICommand; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.world.storage.loot.functions.LootFunctionManager; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.TextureStitchEvent; @@ -54,6 +55,7 @@ import forestry.core.genetics.alleles.AlleleHelper; import forestry.core.genetics.alleles.AlleleRegistry; import forestry.core.items.EnumContainerType; import forestry.core.items.ItemRegistryCore; +import forestry.core.loot.functions.SetSpeciesNBT; import forestry.core.models.ModelManager; import forestry.core.multiblock.MultiblockLogicFactory; import forestry.core.network.IPacketRegistry; @@ -98,6 +100,8 @@ public class PluginCore extends BlankForestryPlugin { AlleleHelper.instance = new AlleleHelper(); + LootFunctionManager.registerFunction(new SetSpeciesNBT.Serializer()); + MultiblockManager.logicFactory = new MultiblockLogicFactory(); ForestryAPI.climateManager = new ClimateManager(); } diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index a54fed148..32e29432a 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -59,9 +59,6 @@ public class Config { public static float researchMutationBoostMultiplier = 1.5f; public static float maxResearchMutationBoostPercent = 5.0f; - // Dungeon loot - public static boolean dungeonLootRare = false; - // World generation public static boolean generateApatiteOre = true; public static boolean generateCopperOre = true; @@ -212,8 +209,6 @@ public class Config { researchMutationBoostMultiplier = configCommon.getFloatLocalized("genetics.research.boost", "multiplier", researchMutationBoostMultiplier, 1.0f, 1000.f); maxResearchMutationBoostPercent = configCommon.getFloatLocalized("genetics.research.boost", "max.percent", maxResearchMutationBoostPercent, 0.0f, 100.0f); - dungeonLootRare = configCommon.getBooleanLocalized("difficulty", "loot.rare", dungeonLootRare); - enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply); mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui.mail.alert", "enabled", mailAlertEnabled); diff --git a/src/main/java/forestry/core/config/Constants.java b/src/main/java/forestry/core/config/Constants.java index a6ff761c9..abcf996a0 100644 --- a/src/main/java/forestry/core/config/Constants.java +++ b/src/main/java/forestry/core/config/Constants.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.config; +import net.minecraft.util.ResourceLocation; + import forestry.api.core.IForestryConstants; public class Constants implements IForestryConstants { @@ -47,8 +49,8 @@ public class Constants implements IForestryConstants { public static final int ID_VILLAGER_BEEKEEPER = 80; public static final int ID_VILLAGER_LUMBERJACK = 81; - // Village Chest Gen hook - public static final String CHEST_GEN_HOOK_NATURALIST_CHEST = "naturalistChest"; + // Village Loot Key + public static final ResourceLocation VILLAGE_NATURALIST_LOOT_KEY = new ResourceLocation(RESOURCE_ID, "village_naturalist"); // Item Ids @@ -135,7 +137,7 @@ public class Constants implements IForestryConstants { } @Override - public String getVillagerChestGenKey() { - return CHEST_GEN_HOOK_NATURALIST_CHEST; + public ResourceLocation getVillagerChestLootKey() { + return VILLAGE_NATURALIST_LOOT_KEY; } } diff --git a/src/main/java/forestry/core/loot/LootTableLoader.java b/src/main/java/forestry/core/loot/LootTableLoader.java new file mode 100644 index 000000000..8cd4c72c8 --- /dev/null +++ b/src/main/java/forestry/core/loot/LootTableLoader.java @@ -0,0 +1,57 @@ +package forestry.core.loot; + +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; + +import java.io.IOException; +import java.net.URL; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.loot.LootContext; +import net.minecraft.world.storage.loot.LootEntry; +import net.minecraft.world.storage.loot.LootPool; +import net.minecraft.world.storage.loot.LootTable; +import net.minecraft.world.storage.loot.LootTableManager; +import net.minecraft.world.storage.loot.RandomValueRange; +import net.minecraft.world.storage.loot.conditions.LootCondition; +import net.minecraft.world.storage.loot.conditions.LootConditionManager; +import net.minecraft.world.storage.loot.functions.LootFunction; +import net.minecraft.world.storage.loot.functions.LootFunctionManager; + +import forestry.core.utils.Log; + +/** + * Copy of {@link LootTableManager} that can load Forestry's loot table additions. + * This is a workaround so I can load loot table jsons that have pools to be added to vanilla's chests. + * During {@link net.minecraftforge.event.LootTableLoadEvent} the world's lootTable is not set yet. + */ +public class LootTableLoader { + private static final Gson GSON_INSTANCE = (new GsonBuilder()).registerTypeAdapter(RandomValueRange.class, new RandomValueRange.Serializer()).registerTypeAdapter(LootPool.class, new LootPool.Serializer()).registerTypeAdapter(LootTable.class, new LootTable.Serializer()).registerTypeHierarchyAdapter(LootEntry.class, new LootEntry.Serializer()).registerTypeHierarchyAdapter(LootFunction.class, new LootFunctionManager.Serializer()).registerTypeHierarchyAdapter(LootCondition.class, new LootConditionManager.Serializer()).registerTypeHierarchyAdapter(LootContext.EntityTarget.class, new LootContext.EntityTarget.Serializer()).create(); + + public static LootTable loadBuiltinLootTable(ResourceLocation resource) { + URL url = LootTableLoader.class.getResource("/assets/" + resource.getResourceDomain() + "/loot_tables/" + resource.getResourcePath() + ".json"); + + if (url != null) { + String s; + + try { + s = Resources.toString(url, Charsets.UTF_8); + } catch (IOException ioexception) { + Log.warning("Couldn\'t load loot table " + resource + " from " + url, ioexception); + return LootTable.EMPTY_LOOT_TABLE; + } + + try { + return net.minecraftforge.common.ForgeHooks.loadLootTable(GSON_INSTANCE, resource, s, false); + } catch (JsonParseException jsonparseexception) { + Log.error("Couldn\'t load loot table " + resource + " from " + url, jsonparseexception); + return LootTable.EMPTY_LOOT_TABLE; + } + } else { + return null; + } + } +} diff --git a/src/main/java/forestry/core/loot/functions/SetSpeciesNBT.java b/src/main/java/forestry/core/loot/functions/SetSpeciesNBT.java new file mode 100644 index 000000000..d0c0ecf9d --- /dev/null +++ b/src/main/java/forestry/core/loot/functions/SetSpeciesNBT.java @@ -0,0 +1,62 @@ +package forestry.core.loot.functions; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; + +import java.util.Random; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.JsonUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.loot.LootContext; +import net.minecraft.world.storage.loot.conditions.LootCondition; +import net.minecraft.world.storage.loot.functions.LootFunction; + +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import forestry.api.genetics.ISpeciesType; + +public class SetSpeciesNBT extends LootFunction { + private final String speciesUid; + + public SetSpeciesNBT(LootCondition[] conditionsIn, String speciesUid) { + super(conditionsIn); + this.speciesUid = speciesUid; + } + + @Override + public ItemStack apply(ItemStack stack, Random rand, LootContext context) { + ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(stack); + if (speciesRoot != null) { + ISpeciesType speciesType = speciesRoot.getType(stack); + if (speciesType != null) { + IAllele[] template = speciesRoot.getTemplate(speciesUid); + if (template != null) { + IIndividual individual = speciesRoot.templateAsIndividual(template); + return speciesRoot.getMemberStack(individual, speciesType); + } + } + } + return stack; + } + + public static class Serializer extends LootFunction.Serializer { + public Serializer() { + super(new ResourceLocation("set_species_nbt"), SetSpeciesNBT.class); + } + + @Override + public void serialize(JsonObject object, SetSpeciesNBT functionClazz, JsonSerializationContext serializationContext) { + object.addProperty("speciesUid", functionClazz.speciesUid); + } + + @Override + public SetSpeciesNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) { + String speciesUid = JsonUtils.getString(object, "speciesUid"); + return new SetSpeciesNBT(conditionsIn, speciesUid); + } + } +} \ No newline at end of file diff --git a/src/main/java/forestry/factory/PluginFactory.java b/src/main/java/forestry/factory/PluginFactory.java index c0a804b03..4ccc74c30 100644 --- a/src/main/java/forestry/factory/PluginFactory.java +++ b/src/main/java/forestry/factory/PluginFactory.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.factory; +import java.util.Set; + import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -185,6 +187,12 @@ public class PluginFactory extends BlankForestryPlugin { } + @Override + public void addLootPoolNames(Set lootPoolNames) { + super.addLootPoolNames(lootPoolNames); + lootPoolNames.add("forestry_factory_items"); + } + @Override public void registerTriggers() { FactoryTriggers.initialize(); diff --git a/src/main/java/forestry/plugins/BlankForestryPlugin.java b/src/main/java/forestry/plugins/BlankForestryPlugin.java index 06572a6dd..c8739a85c 100644 --- a/src/main/java/forestry/plugins/BlankForestryPlugin.java +++ b/src/main/java/forestry/plugins/BlankForestryPlugin.java @@ -21,6 +21,7 @@ import net.minecraft.command.ICommand; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkGenerator; + import net.minecraftforge.fml.common.IFuelHandler; import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage; @@ -90,6 +91,11 @@ public abstract class BlankForestryPlugin implements IForestryPlugin { public void registerRecipes() { } + @Override + public void addLootPoolNames(Set lootPoolNames) { + + } + @Override public void postInit() { } diff --git a/src/main/java/forestry/plugins/IForestryPlugin.java b/src/main/java/forestry/plugins/IForestryPlugin.java index 2bc742e1e..089092410 100644 --- a/src/main/java/forestry/plugins/IForestryPlugin.java +++ b/src/main/java/forestry/plugins/IForestryPlugin.java @@ -50,6 +50,8 @@ public interface IForestryPlugin { void registerRecipes(); + void addLootPoolNames(Set lootPoolNames); + void postInit(); boolean processIMCMessage(FMLInterModComms.IMCMessage message); diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index 3e10291a4..34367d565 100644 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -31,6 +31,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkGenerator; + import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import net.minecraftforge.fml.common.IFuelHandler; @@ -305,6 +306,15 @@ public class PluginManager { return hiddenItems; } + @Nonnull + public static Set getLootPoolNames() { + Set lootPoolNames = new HashSet<>(); + for (IForestryPlugin plugin : loadedPlugins) { + plugin.addLootPoolNames(lootPoolNames); + } + return lootPoolNames; + } + private static boolean isEnabled(Configuration config, IForestryPlugin plugin) { ForestryPlugin info = plugin.getClass().getAnnotation(ForestryPlugin.class); diff --git a/src/main/resources/assets/forestry/loot_tables/chests/abandoned_mineshaft.json b/src/main/resources/assets/forestry/loot_tables/chests/abandoned_mineshaft.json new file mode 100644 index 000000000..557e5356b --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/abandoned_mineshaft.json @@ -0,0 +1,70 @@ +{ + "pools": [ + { + "name": "forestry_factory_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:brokenBronzeShovel", + "weight": 10 + }, + { + "type": "item", + "name": "forestry:brokenBronzePickaxe", + "weight": 30 + }, + { + "type": "item", + "name": "forestry:kitPickaxe", + "weight": 10 + }, + { + "type": "item", + "name": "forestry:kitShovel", + "weight": 5 + }, + { + "type": "empty", + "weight": 50 + } + ] + }, + { + "name": "forestry_apiculture_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:minerBag", + "weight": 1 + }, + { + "type": "empty", + "weight": 20 + } + ] + }, + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 9 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/desert_pyramid.json b/src/main/resources/assets/forestry/loot_tables/chests/desert_pyramid.json new file mode 100644 index 000000000..41d87fdaa --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/desert_pyramid.json @@ -0,0 +1,88 @@ +{ + "pools": [ + { + "name": "forestry_arboriculture_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeAcacia" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 3 + } + ] + }, + { + "name": "forestry_factory_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:ash", + "functions": [ + { + "function": "set_count", + "count": { + "min": 7, + "max": 12 + } + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 1 + } + ] + }, + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesModest" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 3 + }, + { + "type": "empty", + "weight": 6 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/end_city_treasure.json b/src/main/resources/assets/forestry/loot_tables/chests/end_city_treasure.json new file mode 100644 index 000000000..37da0c493 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/end_city_treasure.json @@ -0,0 +1,100 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:ambrosia", + "functions": [ + { + "function": "set_count", + "count": { + "min": 2, + "max": 5 + } + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 3 + } + ] + }, + { + "name": "forestry_apiculture_bees", + "rolls": 2, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 2 + } + } + ], + "weight": 20 + }, + { + "type": "item", + "name": "forestry:beePrincessGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesEnded" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 20 + }, + { + "type": "empty", + "weight": 60 + } + ] + }, + { + "name": "forestry_arboriculture_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:grafterProven", + "weight": 1 + }, + { + "type": "empty", + "weight": 1 + } + ] + }, + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/igloo_chest.json b/src/main/resources/assets/forestry/loot_tables/chests/igloo_chest.json new file mode 100644 index 000000000..78bbc10aa --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/igloo_chest.json @@ -0,0 +1,43 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesWintry" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 2 + }, + { + "type": "empty", + "weight": 7 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/jungle_temple.json b/src/main/resources/assets/forestry/loot_tables/chests/jungle_temple.json new file mode 100644 index 000000000..6ef12bf22 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/jungle_temple.json @@ -0,0 +1,64 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesTropical" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 3 + }, + { + "type": "empty", + "weight": 6 + } + ] + }, + { + "name": "forestry_arboriculture_items", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeSipiri" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 9 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/nether_bridge.json b/src/main/resources/assets/forestry/loot_tables/chests/nether_bridge.json new file mode 100644 index 000000000..72ef10b7a --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/nether_bridge.json @@ -0,0 +1,36 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSinister" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 8 + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/loot_tables/chests/simple_dungeon.json b/src/main/resources/assets/forestry/loot_tables/chests/simple_dungeon.json new file mode 100644 index 000000000..e646be6e6 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/simple_dungeon.json @@ -0,0 +1,25 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 9 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/spawn_bonus_chest.json b/src/main/resources/assets/forestry/loot_tables/chests/spawn_bonus_chest.json new file mode 100644 index 000000000..3d68c2bc0 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/spawn_bonus_chest.json @@ -0,0 +1,15 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:scoop", + "weight": 1 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/stronghold_corridor.json b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_corridor.json new file mode 100644 index 000000000..e646be6e6 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_corridor.json @@ -0,0 +1,25 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 9 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/stronghold_crossing.json b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_crossing.json new file mode 100644 index 000000000..e646be6e6 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_crossing.json @@ -0,0 +1,25 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "empty", + "weight": 9 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/stronghold_library.json b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_library.json new file mode 100644 index 000000000..824980b06 --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/stronghold_library.json @@ -0,0 +1,36 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_bees", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesSteadfast" + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesMonastic" + } + ], + "weight": 6 + }, + { + "type": "empty", + "weight": 3 + } + ] + } + ] +} diff --git a/src/main/resources/assets/forestry/loot_tables/chests/village_naturalist.json b/src/main/resources/assets/forestry/loot_tables/chests/village_naturalist.json new file mode 100644 index 000000000..298b63c7f --- /dev/null +++ b/src/main/resources/assets/forestry/loot_tables/chests/village_naturalist.json @@ -0,0 +1,186 @@ +{ + "pools": [ + { + "name": "forestry_apiculture_items", + "rolls": 3, + "entries": [ + { + "type": "item", + "name": "forestry:candle", + "functions": [ + { + "function": "set_count", + "count": { + "min": 7, + "max": 12 + } + } + ], + "weight": 10 + }, + { + "type": "item", + "name": "forestry:beeCombs", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 4 + } + } + ], + "weight": 20 + }, + { + "type": "item", + "name": "forestry:scoop", + "weight": 1 + }, + { + "type": "item", + "name": "forestry:smoker", + "weight": 1 + } + ] + }, + { + "name": "forestry_apiculture_bees", + "rolls": 2, + "entries": [ + { + "type": "item", + "name": "forestry:beePrincessGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesForest" + } + ], + "weight": 6 + }, + { + "type": "item", + "name": "forestry:beeDroneGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesCommon" + } + ], + "weight": 6 + }, + { + "type": "item", + "name": "forestry:beePrincessGE", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.speciesMeadows" + } + ], + "weight": 6 + }, + { + "type": "empty", + "weight": 3 + } + ] + }, + { + "name": "forestry_arboriculture_items", + "rolls": 2, + "entries": [ + { + "type": "item", + "name": "forestry:grafter", + "weight": 1 + }, + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeLime" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeCherry" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeLarch" + }, + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treeTeak" + }, + { + "function": "set_count", + "count": 1 + } + ], + "weight": 1 + }, + { + "type": "item", + "name": "forestry:sapling", + "functions": [ + { + "function": "set_species_nbt", + "speciesUid": "Forestry.treePadauk" + }, + { + "function": "set_count", + "count": 1 + } + ], + "weight": 1 + } + ] + } + ] +}