From d8b25235f7db356c5c4f14fd40ccb6fbdb0bcef4 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Mon, 28 Jul 2014 10:44:17 +0200 Subject: [PATCH] Change mininglevel-boost from being harvestlevel based to being NBT based. (which is much much better to handle) --- .../IguanaTweaksTConstruct.java | 2 +- .../leveling/LevelingLogic.java | 49 ++++++++++++------- .../leveling/LevelingTooltips.java | 2 +- .../leveling/handlers/ToolTipHandler.java | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java b/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java index 7ab1ce7..e014872 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java @@ -70,8 +70,8 @@ public class IguanaTweaksTConstruct { if(!isHarvestTweaksActive) HarvestLevels.adjustToVanillaLevels(); - pulsar.registerPulse(new IguanaToolLeveling()); pulsar.registerPulse(new IguanaHarvestLevelTweaks()); + pulsar.registerPulse(new IguanaToolLeveling()); pulsar.preInit(event); } diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java index f1ce796..e1d4675 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java @@ -41,15 +41,21 @@ public abstract class LevelingLogic { public static int getHarvestLevel(NBTTagCompound tags) { return tags.hasKey("HarvestLevel") ? tags.getInteger("HarvestLevel") : -1; } public static long getXp(NBTTagCompound tags) { return tags.getLong(TAG_EXP); } public static long getBoostXp(NBTTagCompound tags) { return tags.getLong(TAG_BOOST_EXP); } + public static boolean hasLevel(NBTTagCompound tags) { return tags.hasKey(TAG_LEVEL); } public static boolean hasXp(NBTTagCompound tags) { return tags.hasKey(TAG_EXP); } public static boolean hasBoostXp(NBTTagCompound tags) { return tags.hasKey(TAG_BOOST_EXP); } public static boolean isBoosted(NBTTagCompound tags) { return tags.getBoolean(TAG_IS_BOOSTED); } public static boolean isMaxLevel(NBTTagCompound tags) { return getLevel(tags) >= MAX_LEVEL; } - public static boolean canBoostMiningLevel(int hLevel) + /** + * can only be boosted if: + * - tool was created while pick boosting was active + * - tool hasn't been boosted yet + * - tool doesn't have max mining level already + */ + public static boolean canBoostMiningLevel(NBTTagCompound tags) { - return hLevel >= HarvestLevels._2_copper && - (!Config.pickaxeBoostRequired && hLevel < HarvestLevels._8_cobalt || Config.pickaxeBoostRequired && hLevel < HarvestLevels._9_manyullym); + return tags.hasKey(TAG_IS_BOOSTED) && !isBoosted(tags) && getHarvestLevel(tags) < HarvestLevels.max; } /** @@ -62,9 +68,19 @@ public abstract class LevelingLogic { tag.setInteger(TAG_LEVEL, 1); // and no xp :( tag.setLong(TAG_EXP, 0); + // mining level boost - if(Config.levelingPickaxeBoost) + int hlvl = tag.getInteger("HarvestLevel"); + // only tools with >stone level can be boosted + if(Config.levelingPickaxeBoost && hlvl > 0) { tag.setLong(TAG_BOOST_EXP, 0); + tag.setBoolean(TAG_IS_BOOSTED, false); + + // reduce harvestlevel by 1 if pickaxe boosting is required + if(Config.pickaxeBoostRequired) { + tag.setInteger("HarvestLevel", hlvl - 1); + } + } } /** @@ -76,16 +92,15 @@ public abstract class LevelingLogic { public static void updateXP(ItemStack tool, EntityPlayer player, long toolXP, long boostXP) { NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); - if (!tags.hasKey(TAG_LEVEL)) return; + if (!hasLevel(tags)) return; int level = getLevel(tags); - int hLevel = getHarvestLevel(tags); boolean leveled = false; boolean pickLeveled = false; // Update Tool XP - if (toolXP >= 0 && tags.hasKey(TAG_EXP) && level > 0 && level < MAX_LEVEL) + if (toolXP >= 0 && hasXp(tags) && level > 0 && level < MAX_LEVEL) { // set new xp value tags.setLong(TAG_EXP, toolXP); @@ -100,19 +115,17 @@ public abstract class LevelingLogic { // handle mining boost XP if(Config.levelingPickaxeBoost) { - // already got a boost? - if (hasBoostXp(tags) && !isBoosted(tags)) - // we can only if we have a proper material (>stone) and are not max mining level already - if (canBoostMiningLevel(hLevel)) { - tags.setLong(TAG_BOOST_EXP, boostXP); + // we can only if we have a proper material (>stone) and are not max mining level already + if (canBoostMiningLevel(tags)) { + tags.setLong(TAG_BOOST_EXP, boostXP); - // check for mining boost levelup! - if (boostXP >= getRequiredBoostXp(tool)) { - levelUpMiningLevel(tool, player, leveled); + // check for mining boost levelup! + if (boostXP >= getRequiredBoostXp(tool)) { + levelUpMiningLevel(tool, player, leveled); - pickLeveled = true; - } + pickLeveled = true; } + } } @@ -129,7 +142,7 @@ public abstract class LevelingLogic { NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); // only if we have a level or xp - if(!tags.hasKey(TAG_LEVEL) || !hasXp(tags)) + if(!hasLevel(tags) || !hasXp(tags)) return; // tool EXP diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingTooltips.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingTooltips.java index f994783..b3c5a7e 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingTooltips.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingTooltips.java @@ -45,7 +45,7 @@ public abstract class LevelingTooltips { if (tags == null) tags = tool.getTagCompound().getCompoundTag("InfiTool"); int requiredXp = LevelingLogic.getRequiredXp(tool, tags, boostXp); - long currentXp = boostXp ? tags.getLong(LevelingLogic.TAG_BOOST_EXP) : tags.getLong(LevelingLogic.TAG_EXP); + long currentXp = boostXp ? LevelingLogic.getBoostXp(tags) : LevelingLogic.getBoostXp(tags); float xpPercentage = (float)currentXp / (float)requiredXp * 100f; String xpPercentageString = String.format("%.2f", xpPercentage) + "%"; diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java index d9a0800..f996e2d 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java @@ -55,7 +55,7 @@ public class ToolTipHandler { int hLevel = tags.getInteger("HarvestLevel"); String mLvl = LevelingTooltips.getMiningLevelTooltip(hLevel); // is the pick applicable for mining level boosting? if yes display xp - if(LevelingLogic.hasBoostXp(tags) && LevelingLogic.canBoostMiningLevel(hLevel)) { + if(LevelingLogic.hasBoostXp(tags) && LevelingLogic.canBoostMiningLevel(tags)) { // add minimal xp if config option is set if (!advanced && Config.showMinimalTooltipXP && !LevelingLogic.isBoosted(tags)) mLvl += " (" + LevelingTooltips.getBoostXpString(stack, tags, false) + ")";