Close #1154 add dungeon loot

This commit is contained in:
mezz committed 2016-05-13 01:50:49 -07:00
1 parent 4cf74e4aa1
commit 9d9ea95ed1
28 files changed
+924 -69

No files matched your search

@@ -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();
}
@@ -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<String> lootPoolNames) {
super.addLootPoolNames(lootPoolNames);
lootPoolNames.add("forestry_apiculture_items");
lootPoolNames.add("forestry_apiculture_bees");
}
private static void createHives() {
@@ -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
@@ -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);
@@ -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<String> 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) {
@@ -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);
}
}
}
}
}
@@ -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();
}
@@ -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);
@@ -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;
}
}
@@ -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;
}
}
}
@@ -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<SetSpeciesNBT> {
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);
}
}
}
@@ -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<String> lootPoolNames) {
super.addLootPoolNames(lootPoolNames);
lootPoolNames.add("forestry_factory_items");
}
@Override
public void registerTriggers() {
FactoryTriggers.initialize();
@@ -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<String> lootPoolNames) {
}
@Override
public void postInit() {
}
@@ -50,6 +50,8 @@ public interface IForestryPlugin {
void registerRecipes();
void addLootPoolNames(Set<String> lootPoolNames);
void postInit();
boolean processIMCMessage(FMLInterModComms.IMCMessage message);
@@ -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<String> getLootPoolNames() {
Set<String> 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);