From 17d0fe0c38d2a2ec948ed5729bf1aaf4094dbe61 Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Mon, 2 Feb 2015 18:47:23 +0000 Subject: [PATCH] Add a proper config for potion IDs. --- .../common/brew/potion/PotionAllure.java | 3 ++- .../common/brew/potion/PotionBloodthirst.java | 3 ++- .../common/brew/potion/PotionEmptiness.java | 3 ++- .../common/brew/potion/PotionFeatherfeet.java | 3 ++- .../botania/common/brew/potion/PotionMod.java | 12 ++--------- .../common/brew/potion/PotionSoulCross.java | 3 ++- .../common/core/handler/ConfigHandler.java | 20 +++++++++++++++++++ 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionAllure.java b/src/main/java/vazkii/botania/common/brew/potion/PotionAllure.java index 5feee4b7a..4f856911e 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionAllure.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionAllure.java @@ -15,13 +15,14 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityFishHook; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class PotionAllure extends PotionMod { public PotionAllure() { - super(LibPotionNames.ALLURE, false, 0x0034E4, 5); + super(ConfigHandler.potionIDAllure, LibPotionNames.ALLURE, false, 0x0034E4, 5); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java index a2ca12b0d..44eadad2b 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java @@ -18,6 +18,7 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import vazkii.botania.common.brew.ModPotions; +import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -27,7 +28,7 @@ public class PotionBloodthirst extends PotionMod { private static final int RANGE = 64; public PotionBloodthirst() { - super(LibPotionNames.BLOODTHIRST, false, 0xC30000, 3); + super(ConfigHandler.potionIDBloodthirst, LibPotionNames.BLOODTHIRST, false, 0xC30000, 3); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java index 66aa2f8c2..29d26393a 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java @@ -17,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingSpawnEvent; +import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -26,7 +27,7 @@ public class PotionEmptiness extends PotionMod { private static final int RANGE = 128; public PotionEmptiness() { - super(LibPotionNames.EMPTINESS, false, 0xE7E7E7, 2); + super(ConfigHandler.potionIDEmptiness, LibPotionNames.EMPTINESS, false, 0xE7E7E7, 2); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionFeatherfeet.java b/src/main/java/vazkii/botania/common/brew/potion/PotionFeatherfeet.java index 31f56e3f6..c9e26d3c1 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionFeatherfeet.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionFeatherfeet.java @@ -13,13 +13,14 @@ package vazkii.botania.common.brew.potion; import net.minecraft.entity.EntityLivingBase; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class PotionFeatherfeet extends PotionMod { public PotionFeatherfeet() { - super(LibPotionNames.FEATHER_FEET, false, 0x26ADFF, 1); + super(ConfigHandler.potionIDFeatherfeet, LibPotionNames.FEATHER_FEET, false, 0x26ADFF, 1); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionMod.java b/src/main/java/vazkii/botania/common/brew/potion/PotionMod.java index bfdf7f3bf..1cf8dcfe2 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionMod.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionMod.java @@ -22,20 +22,12 @@ public class PotionMod extends Potion { private static final ResourceLocation resource = new ResourceLocation(LibResources.GUI_POTIONS); - public PotionMod(String name, boolean badEffect, int color, int iconIndex) { - super(findFreeID(), badEffect, color); + public PotionMod(int id, String name, boolean badEffect, int color, int iconIndex) { + super(id, badEffect, color); setPotionName("botania.potion." + name); setIconIndex(iconIndex % 8, iconIndex / 8); } - static int findFreeID() { - for(int i = 0; i < potionTypes.length; i++) - if(potionTypes[i] == null) - return i; - - return -1; - } - @Override @SideOnly(Side.CLIENT) public int getStatusIconIndex() { diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionSoulCross.java b/src/main/java/vazkii/botania/common/brew/potion/PotionSoulCross.java index d92c8ea15..8498a6800 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionSoulCross.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionSoulCross.java @@ -14,13 +14,14 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class PotionSoulCross extends PotionMod { public PotionSoulCross() { - super(LibPotionNames.SOUL_CROSS, false, 0x47453d, 0); + super(ConfigHandler.potionIDSoulCross, LibPotionNames.SOUL_CROSS, false, 0x47453d, 0); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java index 58cd9b4ed..6996ed022 100644 --- a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java @@ -15,6 +15,7 @@ import java.io.File; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import vazkii.botania.common.lib.LibMisc; +import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -22,6 +23,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; public final class ConfigHandler { public static Configuration config; + + private static final String CATEGORY_POTIONS = "potions"; public static boolean useShaders = true; public static boolean lexiconRotatingItems = true; @@ -56,6 +59,12 @@ public final class ConfigHandler { public static int flowerQuantity = 2; public static int flowerDensity = 16; + + public static int potionIDSoulCross = 191; + public static int potionIDFeatherfeet = 192; + public static int potionIDEmptiness = 193; + public static int potionIDBloodthirst = 194; + public static int potionIDAllure = 195; public static void loadConfig(File configFile) { config = new Configuration(configFile); @@ -156,6 +165,12 @@ public final class ConfigHandler { desc = "The density of each flower patch generataed, defaults to 16, the lower the number, the less each patch will have."; flowerDensity = loadPropInt("worldgen.flower.density", desc, flowerDensity); + potionIDSoulCross = loadPropPotionId(LibPotionNames.SOUL_CROSS, potionIDSoulCross); + potionIDFeatherfeet = loadPropPotionId(LibPotionNames.FEATHER_FEET, potionIDFeatherfeet); + potionIDEmptiness = loadPropPotionId(LibPotionNames.EMPTINESS, potionIDEmptiness); + potionIDBloodthirst = loadPropPotionId(LibPotionNames.BLOODTHIRST, potionIDBloodthirst); + potionIDAllure = loadPropPotionId(LibPotionNames.ALLURE, potionIDAllure); + if(config.hasChanged()) config.save(); } @@ -184,6 +199,11 @@ public final class ConfigHandler { prop.comment = desc; return prop.getBoolean(default_); } + + public static int loadPropPotionId(String propName, int default_) { + Property prop = config.get(CATEGORY_POTIONS, propName, default_); + return prop.getInt(default_); + } public static class ChangeListener {