Fix logs, load order and GameMode loading

This commit is contained in:
mezz committed 2016-03-04 03:54:32 -08:00
1 parent 92b1f85d84
commit 4677ae7d54
9 files changed
+105 -103

No files matched your search

@@ -5,8 +5,6 @@
******************************************************************************/
package forestry.api.core;
import net.minecraft.item.ItemStack;
public interface IGameMode {
/**
@@ -32,10 +30,4 @@ public interface IGameMode {
*/
float getFloatSetting(String ident);
/**
* @param ident Identifier for the setting. (See the gamemode config.)
* @return Value of the requested setting, an itemstack containing an apple if unknown setting.
*/
ItemStack getStackSetting(String ident);
}
@@ -493,8 +493,17 @@ public class PluginApiculture extends BlankForestryPlugin {
}
// / CAPSULES
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.capsule"), "###", '#', PluginCore.items.beeswax);
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.refractory"), "###", '#', PluginCore.items.refractoryWax);
int outputCapsuleAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.capsule");
if (outputCapsuleAmount > 0) {
ItemStack capsule = PluginFluids.items.waxCapsuleEmpty.getItemStack(outputCapsuleAmount);
RecipeUtil.addRecipe(capsule, "###", '#', PluginCore.items.beeswax);
}
int outputRefractoryAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.refractory");
if (outputRefractoryAmount > 0) {
ItemStack capsule = PluginFluids.items.refractoryEmpty.getItemStack(outputRefractoryAmount);
RecipeUtil.addRecipe(capsule, "###", '#', PluginCore.items.refractoryWax);
}
// / BITUMINOUS PEAT
RecipeUtil.addRecipe(PluginCore.items.bituminousPeat.getItemStack(),
+41 -24
View File
@@ -128,11 +128,6 @@ public class PluginCore extends BlankForestryPlugin {
AlleleHelper.instance.init();
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public ISaveEventHandler getSaveEventHandler() {
return new SaveEventHandlerCore();
@@ -227,7 +222,9 @@ public class PluginCore extends BlankForestryPlugin {
RecipeUtil.addRecipe(items.sturdyCasing, "###", "# #", "###", '#', "ingotBronze");
// / EMPTY CANS
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.can"), " # ", "# #", '#', "ingotTin");
int canAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.can");
ItemStack canOutput = PluginFluids.items.canEmpty.getItemStack(canAmount);
RecipeUtil.addRecipe(canOutput, " # ", "# #", '#', "ingotTin");
// / GEARS
List<ItemStack> stoneGear = OreDictionary.getOres("gearStone");
@@ -254,39 +251,59 @@ public class PluginCore extends BlankForestryPlugin {
RecipeUtil.addRecipe(items.wrench, "# #", " # ", " # ", '#', "ingotBronze");
// Manure and Fertilizer
if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "cropWheat");
int compostWheatAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.wheat");
if (compostWheatAmount > 0) {
ItemStack compost = items.fertilizerBio.getItemStack(compostWheatAmount);
RecipeUtil.addRecipe(compost, " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "cropWheat");
}
if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.ash").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.compost.ash"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "dustAsh");
int compostAshAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.ash");
if (compostAshAmount > 0) {
ItemStack compost = items.fertilizerBio.getItemStack(compostAshAmount);
RecipeUtil.addRecipe(compost, " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "dustAsh");
}
if (ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.apatite").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.apatite"), " # ", " X ", " # ", '#', "sand", 'X', "gemApatite");
int fertilizerApatiteAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.fertilizer.apatite");
if (fertilizerApatiteAmount > 0) {
ItemStack fertilizer = items.fertilizerCompound.getItemStack(fertilizerApatiteAmount);
RecipeUtil.addRecipe(fertilizer, " # ", " X ", " # ", '#', "sand", 'X', "gemApatite");
}
if (ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.ash").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.ash"), "###", "#X#", "###", '#', "dustAsh", 'X', "gemApatite");
int fertilizerAshAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.fertilizer.ash");
if (fertilizerAshAmount > 0) {
ItemStack fertilizer = items.fertilizerCompound.getItemStack(fertilizerAshAmount);
RecipeUtil.addRecipe(fertilizer, "###", "#X#", "###", '#', "dustAsh", 'X', "gemApatite");
}
// Humus
if (ForestryAPI.activeMode.getStackSetting("recipe.output.humus.compost").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.humus.compost"), "###", "#X#", "###", '#', Blocks.dirt, 'X', items.fertilizerBio);
int humusCompostAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.humus.compost");
if (humusCompostAmount > 0) {
ItemStack humus = blocks.soil.get(BlockSoil.SoilType.HUMUS, humusCompostAmount);
RecipeUtil.addRecipe(humus, "###", "#X#", "###", '#', Blocks.dirt, 'X', items.fertilizerBio);
}
if (ForestryAPI.activeMode.getStackSetting("recipe.output.humus.fertilizer").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.humus.fertilizer"), "###", "#X#", "###", '#', Blocks.dirt, 'X', items.fertilizerCompound);
int humusFertilizerAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.humus.fertilizer");
if (humusFertilizerAmount > 0) {
ItemStack humus = blocks.soil.get(BlockSoil.SoilType.HUMUS, humusFertilizerAmount);
RecipeUtil.addRecipe(humus, "###", "#X#", "###", '#', Blocks.dirt, 'X', items.fertilizerCompound);
}
// Bog earth
if (ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.bucket").stackSize > 0) {
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.bucket"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', Items.water_bucket, 'Y', "sand");
int bogEarthOutputBucket = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.bucket");
if (bogEarthOutputBucket > 0) {
ItemStack bogEarth = blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputBucket);
RecipeUtil.addRecipe(bogEarth, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', Items.water_bucket, 'Y', "sand");
}
if (ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can").stackSize > 0) {
int bogEarthOutputCan = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.can");
if (bogEarthOutputCan > 0) {
ItemStack bogEarth = blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputCan);
ItemStack canWater = PluginFluids.items.getContainer(EnumContainerType.CAN, Fluids.WATER).getItemStack();
ItemStack waxCapsuleWater = PluginFluids.items.getContainer(EnumContainerType.CAPSULE, Fluids.WATER).getItemStack();
ItemStack refractoryWater = PluginFluids.items.getContainer(EnumContainerType.REFRACTORY, Fluids.WATER).getItemStack();
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', canWater, 'Y', "sand");
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waxCapsuleWater, 'Y', "sand");
RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', refractoryWater, 'Y', "sand");
RecipeUtil.addRecipe(bogEarth, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', canWater, 'Y', "sand");
RecipeUtil.addRecipe(bogEarth, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waxCapsuleWater, 'Y', "sand");
RecipeUtil.addRecipe(bogEarth, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', refractoryWater, 'Y', "sand");
}
// Crafting Material
@@ -83,9 +83,9 @@ public class PluginFluids extends BlankForestryPlugin {
}
} else {
GameRegistry.UniqueIdentifier blockID = GameRegistry.findUniqueIdentifierFor(fluidBlock);
Log.warning("Pre-existing {0} fluid block detected, deferring to {1}:{2}, "
Log.warning("Pre-existing {} fluid block detected, deferring to {}:{}, "
+ "this may cause issues if the server/client have different mod load orders, "
+ "recommended that you disable all but one instance of {0} fluid blocks via your configs.", fluid.getName(), blockID.modId, blockID.name);
+ "recommended that you disable all but one instance of {} fluid blocks via your configs.", fluid.getName(), blockID.modId, blockID.name, fluid.getName());
}
}
}
@@ -22,8 +22,8 @@ import forestry.plugins.PluginManager;
public abstract class BlockRegistry {
protected static <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass, String name, Object... itemCtorArgs) {
if (PluginManager.getStage() != PluginManager.Stage.SETUP) {
throw new RuntimeException("Tried to register Block outside of Setup");
if (PluginManager.getStage() != PluginManager.Stage.REGISTER) {
throw new RuntimeException("Tried to register Block outside of REGISTER");
}
block.setUnlocalizedName("for." + name);
GameRegistry.registerBlock(block, itemClass, StringUtil.cleanBlockName(block), itemCtorArgs);
@@ -14,14 +14,8 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import forestry.Forestry;
import forestry.api.core.IGameMode;
import forestry.core.PluginCore;
import forestry.core.PluginFluids;
import forestry.core.blocks.BlockSoil;
import forestry.core.utils.Log;
public class GameMode implements IGameMode {
@@ -32,27 +26,26 @@ public class GameMode implements IGameMode {
private final Map<String, Boolean> booleanSettings = new HashMap<>();
private final Map<String, Integer> integerSettings = new HashMap<>();
private final Map<String, Float> floatSettings = new HashMap<>();
private final Map<String, ItemStack> stackSettings = new HashMap<>();
private static final float ENERGY_DEMAND_MODIFIER = 1.0f;
private static final float FUEL_MODIFIER = 1.0f;
private static final int FARM_FERTILIZER_VALUE = 2000;
private final ItemStack recipeFertilizerOutputApatite = PluginCore.items.fertilizerCompound.getItemStack(8);
private final ItemStack recipeFertilizerOutputAsh = PluginCore.items.fertilizerCompound.getItemStack(16);
private final ItemStack recipeCompostOutputWheat = PluginCore.items.fertilizerBio.getItemStack(4);
private final ItemStack recipeCompostOutputAsh = PluginCore.items.fertilizerBio.getItemStack(1);
private static final int recipeFertilizerOutputApatite = 8;
private static final int recipeFertilizerOutputAsh = 16;
private static final int recipeCompostOutputWheat = 4;
private static final int recipeCompostOutputAsh = 1;
private final ItemStack recipeHumusOutputFertilizer = PluginCore.blocks.soil.get(BlockSoil.SoilType.HUMUS, 8);
private final ItemStack recipeHumusOutputCompost = PluginCore.blocks.soil.get(BlockSoil.SoilType.HUMUS, 8);
private static final int recipeHumusOutputFertilizer = 8;
private static final int recipeHumusOutputCompost = 8;
private final ItemStack recipeBogEarthOutputBucket = PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, 6);
private final ItemStack recipeBogEarthOutputCans = PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, 8);
private static final int recipeBogEarthOutputBucket = 6;
private static final int recipeBogEarthOutputCans = 8;
private final ItemStack recipeCanOutput = PluginFluids.items.canEmpty.getItemStack(12);
private final ItemStack recipeCapsuleOutput = PluginFluids.items.waxCapsuleEmpty.getItemStack(4);
private final ItemStack recipeRefractoryOutput = PluginFluids.items.refractoryEmpty.getItemStack(4);
private static final int recipeCanOutput = 12;
private static final int recipeCapsuleOutput = 4;
private static final int recipeRefractoryOutput = 4;
private static final int FERMENTATION_DURATION_FERTILIZER = 200;
private static final int FERMENTATION_DURATION_COMPOST = 250;
@@ -89,17 +82,17 @@ public class GameMode implements IGameMode {
initSettingFloat(config, "fuel.biomass", "generator", FUEL_MODIFIER);
initSettingFloat(config, "fuel.biomass", "biogas", FUEL_MODIFIER);
initSettingStack(config, "recipe.output.fertilizer", "apatite", recipeFertilizerOutputApatite);
initSettingStack(config, "recipe.output.fertilizer", "ash", recipeFertilizerOutputAsh);
initSettingStack(config, "recipe.output.compost", "wheat", recipeCompostOutputWheat);
initSettingStack(config, "recipe.output.compost", "ash", recipeCompostOutputAsh);
initSettingStack(config, "recipe.output.humus", "fertilizer", recipeHumusOutputFertilizer);
initSettingStack(config, "recipe.output.humus", "compost", recipeHumusOutputCompost);
initSettingStack(config, "recipe.output.bogearth", "bucket", recipeBogEarthOutputBucket);
initSettingStack(config, "recipe.output.bogearth", "can", recipeBogEarthOutputCans);
initSettingStack(config, "recipe.output", "can", recipeCanOutput);
initSettingStack(config, "recipe.output", "capsule", recipeCapsuleOutput);
initSettingStack(config, "recipe.output", "refractory", recipeRefractoryOutput);
initSettingInt(config, "recipe.output.fertilizer", "apatite", recipeFertilizerOutputApatite);
initSettingInt(config, "recipe.output.fertilizer", "ash", recipeFertilizerOutputAsh);
initSettingInt(config, "recipe.output.compost", "wheat", recipeCompostOutputWheat);
initSettingInt(config, "recipe.output.compost", "ash", recipeCompostOutputAsh);
initSettingInt(config, "recipe.output.humus", "fertilizer", recipeHumusOutputFertilizer);
initSettingInt(config, "recipe.output.humus", "compost", recipeHumusOutputCompost);
initSettingInt(config, "recipe.output.bogearth", "bucket", recipeBogEarthOutputBucket);
initSettingInt(config, "recipe.output.bogearth", "can", recipeBogEarthOutputCans);
initSettingInt(config, "recipe.output", "can", recipeCanOutput);
initSettingInt(config, "recipe.output", "capsule", recipeCapsuleOutput);
initSettingInt(config, "recipe.output", "refractory", recipeRefractoryOutput);
initSettingInt(config, "fermenter.cycles", "fertilizer", FERMENTATION_DURATION_FERTILIZER);
initSettingInt(config, "fermenter.cycles", "compost", FERMENTATION_DURATION_COMPOST);
@@ -133,14 +126,6 @@ public class GameMode implements IGameMode {
integerSettings.put(fullKey, intValue);
}
private void initSettingStack(LocalizedConfiguration config, String category, String key, ItemStack defaultValue) {
String fullKey = category + '.' + key;
int stackSize = config.getIntLocalized(GAMEMODE_KEY + '.' + category, key, defaultValue.stackSize, 0, 64);
ItemStack changed = defaultValue.copy();
changed.stackSize = stackSize;
stackSettings.put(fullKey, changed);
}
private void initSettingBoolean(LocalizedConfiguration config, String category, String key, boolean defaultValue) {
String fullKey = category + '.' + key;
boolean booleanValue = config.getBooleanLocalized(GAMEMODE_KEY + '.' + category, key, defaultValue);
@@ -174,15 +159,6 @@ public class GameMode implements IGameMode {
return false;
}
@Override
public ItemStack getStackSetting(String ident) {
if (stackSettings.containsKey(ident)) {
return stackSettings.get(ident);
}
Log.warning("No such setting: " + ident);
return new ItemStack(Items.apple, 1);
}
@Override
public String getIdentifier() {
return identifier;
@@ -21,8 +21,8 @@ import forestry.plugins.PluginManager;
public abstract class ItemRegistry {
protected static <T extends Item> T registerItem(T item, String name) {
if (PluginManager.getStage() != PluginManager.Stage.SETUP) {
throw new RuntimeException("Tried to register Item outside of Setup");
if (PluginManager.getStage() != PluginManager.Stage.REGISTER) {
throw new RuntimeException("Tried to register Item outside of REGISTER");
}
item.setUnlocalizedName("for." + name);
GameRegistry.registerItem(item, StringUtil.cleanItemName(item));
@@ -64,8 +64,9 @@ public class PluginManager {
private static Stage stage = Stage.SETUP;
public enum Stage {
SETUP, // setup API to make it functional, register basic blocks and items. GameMode Configs are not yet accessible
SETUP, // setup API to make it functional. GameMode Configs are not yet accessible
SETUP_DISABLED, // setup fallback API to avoid crashes
REGISTER, // register basic blocks and items
PRE_INIT, // register handlers, triggers, definitions, backpacks, crates, and anything that depends on basic items
INIT, // anything that depends on PreInit stages, recipe registration
POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods
@@ -145,12 +146,12 @@ public class PluginManager {
if (plugin.canBeDisabled()) {
if (!isEnabled(config, plugin)) {
iterator.remove();
Log.info("Plugin disabled: {0}", plugin);
Log.info("Plugin disabled: {}", plugin);
continue;
}
if (!plugin.isAvailable()) {
iterator.remove();
Log.info("Plugin {0} failed to load: {1}", plugin, plugin.getFailMessage());
Log.info("Plugin {} failed to load: {}", plugin, plugin.getFailMessage());
continue;
}
}
@@ -171,7 +172,7 @@ public class PluginManager {
ForestryPlugin info = plugin.getClass().getAnnotation(ForestryPlugin.class);
String pluginId = info.pluginID();
toLoad.remove(pluginId);
Log.warning("Plugin {0} is missing dependencies: {1}", pluginId, dependencies);
Log.warning("Plugin {} is missing dependencies: {}", pluginId, dependencies);
}
}
} while (changed);
@@ -202,24 +203,30 @@ public class PluginManager {
configurePlugins(forestryPlugins);
for (IForestryPlugin plugin : loadedPlugins) {
Log.debug("Setup Start: {0}", plugin);
Log.debug("Setup API Start: {}", plugin);
plugin.setupAPI();
plugin.registerItemsAndBlocks();
Log.debug("Setup Complete: {0}", plugin);
Log.debug("Setup API Complete: {}", plugin);
}
stage = Stage.SETUP_DISABLED;
for (IForestryPlugin plugin : unloadedPlugins) {
Log.debug("Disabled-Setup Start: {0}", plugin);
Log.debug("Disabled-Setup Start: {}", plugin);
plugin.disabledSetupAPI();
Log.debug("Disabled-Setup Complete: {0}", plugin);
Log.debug("Disabled-Setup Complete: {}", plugin);
}
stage = Stage.REGISTER;
for (IForestryPlugin plugin : loadedPlugins) {
Log.debug("Register Items and Blocks Start: {}", plugin);
plugin.registerItemsAndBlocks();
Log.debug("Register Items and Blocks Complete: {}", plugin);
}
}
public static void runPreInit() {
stage = Stage.PRE_INIT;
for (IForestryPlugin plugin : loadedPlugins) {
Log.debug("Pre-Init Start: {0}", plugin);
Log.debug("Pre-Init Start: {}", plugin);
registerHandlers(plugin);
plugin.preInit();
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.BUILDCRAFT_STATEMENTS)) {
@@ -229,26 +236,26 @@ public class PluginManager {
plugin.registerBackpackItems();
plugin.registerCrates();
}
Log.debug("Pre-Init Complete: {0}", plugin);
Log.debug("Pre-Init Complete: {}", plugin);
}
}
public static void runInit() {
stage = Stage.INIT;
for (IForestryPlugin plugin : loadedPlugins) {
Log.debug("Init Start: {0}", plugin);
Log.debug("Init Start: {}", plugin);
plugin.doInit();
plugin.registerRecipes();
Log.debug("Init Complete: {0}", plugin);
Log.debug("Init Complete: {}", plugin);
}
}
public static void runPostInit() {
stage = Stage.POST_INIT;
for (IForestryPlugin plugin : loadedPlugins) {
Log.debug("Post-Init Start: {0}", plugin);
Log.debug("Post-Init Start: {}", plugin);
plugin.postInit();
Log.debug("Post-Init Complete: {0}", plugin);
Log.debug("Post-Init Complete: {}", plugin);
}
stage = Stage.FINISHED;
@@ -269,8 +269,9 @@ public class PluginNatura extends BlankForestryPlugin {
if (itemBarley != null) {
RecipeUtil.addFermenterRecipes(itemBarley, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat").stackSize > 0) {
ItemStack compostWheat = ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat");
int compostWheatAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.wheat");
if (compostWheatAmount > 0) {
ItemStack compostWheat = PluginCore.items.fertilizerBio.getItemStack(compostWheatAmount);
RecipeUtil.addRecipe(compostWheat, " X ", "X#X", " X ", '#', Blocks.dirt, 'X', itemBarley);
}
FuelManager.moistenerResource.put(itemBarley, new MoistenerFuel(itemBarley, PluginCore.items.mouldyWheat.getItemStack(), 0, 300));