diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaToolLeveling.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaToolLeveling.java index f9530c0..5faa615 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaToolLeveling.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaToolLeveling.java @@ -6,10 +6,14 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import iguanaman.iguanatweakstconstruct.leveling.handlers.LevelingEventHandler; import iguanaman.iguanatweakstconstruct.leveling.handlers.ToolTipHandler; import iguanaman.iguanatweakstconstruct.reference.Reference; +import iguanaman.iguanatweakstconstruct.util.HarvestLevels; import mantle.pulsar.pulse.Handler; import mantle.pulsar.pulse.Pulse; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.ModifyBuilder; /** * The Leveling Pulse. If Leveling were a separate mod instead of pulse-model, this'd be a @Mod @@ -19,10 +23,29 @@ import tconstruct.library.TConstructRegistry; @Pulse(id = Reference.PULSE_LEVELING, description = "The Iguana Tweaks Leveling System for Tinker's Tools") public class IguanaToolLeveling { + private static final int HEAD_Zombie = 2; + private static final int HEAD_Skeleton = 0; + private static final int HEAD_Creeper = 4; + private static final int HEAD_Wither = 1; + @Handler public void init(FMLInitializationEvent event) { TConstructRegistry.registerActiveToolMod(new LevelingActiveToolMod()); + + // mobhead modifiers for mining boost + ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Zombie), HarvestLevels._2_copper)); + ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Skeleton), HarvestLevels._3_iron)); + ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Creeper), HarvestLevels._4_bronze)); + // blaze + // enderman + ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Wither), HarvestLevels._7_ardite)); + ModifyBuilder.registerModifier(new ModMiningLevelBoost(new ItemStack[]{new ItemStack(Items.nether_star)}, HarvestLevels._8_cobalt)); + } + + private ItemStack[] getMobHead(int meta) + { + return new ItemStack[]{new ItemStack(Items.skull, 1, meta)}; } @Handler diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java index e1d4675..c9df8bd 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingLogic.java @@ -308,7 +308,6 @@ public abstract class LevelingLogic { public static void levelUpMiningLevel(ItemStack stack, EntityPlayer player, boolean leveled) { NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - World world = player.worldObj; // we only apply that once if(isBoosted(tags)) @@ -319,11 +318,14 @@ public abstract class LevelingLogic { tags.setLong(TAG_BOOST_EXP, 0L); // fancy message - if (!world.isRemote) - if (!leveled) - player.addChatMessage(new ChatComponentText("\u00a73Suddenly, a flash of light shines from the tip of your " + stack.getDisplayName() + "\u00a73 (+1 mining level)")); - else - player.addChatMessage(new ChatComponentText("\u00a79Suddenly, a flash of light shines from the tip of the pickaxe (+1 mining level)")); + if (player != null) { + if(!player.worldObj.isRemote) { + if (!leveled) + player.addChatMessage(new ChatComponentText("\u00a73Suddenly, a flash of light shines from the tip of your " + stack.getDisplayName() + "\u00a73 (+1 mining level)")); + else + player.addChatMessage(new ChatComponentText("\u00a79Suddenly, a flash of light shines from the tip of the pickaxe (+1 mining level)")); + } + } tags.setBoolean(TAG_IS_BOOSTED, true); // increase harvest level by 1 diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ModMiningLevelBoost.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ModMiningLevelBoost.java new file mode 100644 index 0000000..e9d1620 --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ModMiningLevelBoost.java @@ -0,0 +1,45 @@ +package iguanaman.iguanatweakstconstruct.leveling; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import tconstruct.library.modifier.ItemModifier; +import tconstruct.modifiers.tools.ModBoolean; + +public class ModMiningLevelBoost extends ModBoolean { + private int maxLvl = 0; + + public ModMiningLevelBoost(ItemStack[] recipe, int maxLvl) { + super(recipe, 0, "Mining Level Boost", EnumChatFormatting.GREEN.toString(), "MobHead"); + + this.maxLvl = maxLvl; + } + + @Override + protected boolean canModify(ItemStack input, ItemStack[] recipe) { + NBTTagCompound tags = input.getTagCompound().getCompoundTag("InfiTool"); + + // modifiers left and not yet modified? + if(!super.canModify(input, recipe)) + return false; + + // got required harvest level? + int hlvl = tags.getInteger("HarvestLevel"); + if(hlvl < maxLvl && hlvl > 0) + return true; + + return false; + } + + @Override + public void modify(ItemStack[] input, ItemStack tool) { + LevelingLogic.levelUpMiningLevel(tool, null, false); + + super.modify(input, tool); + } + + @Override + public void addMatchingEffect(ItemStack input) { + // no effect to display :( + } +}