From 680f5829c85cb468757449ea26e1aa271c6c92ce Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Wed, 3 Sep 2014 19:45:25 +0100 Subject: [PATCH] Added the Timeless Ivy. --- .../client/core/handler/TooltipHandler.java | 5 ++ .../common/core/BotaniaCreativeTab.java | 1 + .../crafting/recipe/RegenIvyRecipe.java | 80 +++++++++++++++++++ .../botania/common/item/ItemRegenIvy.java | 50 ++++++++++++ .../vazkii/botania/common/item/ModItems.java | 4 +- .../botania/common/lib/LibItemNames.java | 1 + resources/assets/botania/lang/en_US.lang | 2 + 7 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 MODSRC/vazkii/botania/common/crafting/recipe/RegenIvyRecipe.java create mode 100644 MODSRC/vazkii/botania/common/item/ItemRegenIvy.java diff --git a/MODSRC/vazkii/botania/client/core/handler/TooltipHandler.java b/MODSRC/vazkii/botania/client/core/handler/TooltipHandler.java index 7676b1d89..6ed33ab7c 100644 --- a/MODSRC/vazkii/botania/client/core/handler/TooltipHandler.java +++ b/MODSRC/vazkii/botania/client/core/handler/TooltipHandler.java @@ -11,6 +11,8 @@ */ package vazkii.botania.client.core.handler; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.item.ItemRegenIvy; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.util.StatCollector; @@ -27,6 +29,9 @@ public final class TooltipHandler { event.toolTip.add(StatCollector.translateToLocal("botaniamisc.coarseDirt1")); } else if(event.itemStack.getItem() == Item.getItemFromBlock(Blocks.mob_spawner) && event.entityPlayer.capabilities.isCreativeMode) event.toolTip.add(StatCollector.translateToLocal("botaniamisc.spawnerTip")); + + if(ItemNBTHelper.getBoolean(event.itemStack, ItemRegenIvy.TAG_REGEN, false)) + event.toolTip.add(StatCollector.translateToLocal("botaniamisc.hasIvy")); } } diff --git a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java index 720a980c6..b77498621 100644 --- a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -85,6 +85,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addItem(ModItems.virus); addItem(ModItems.slingshot); addItem(ModItems.vineBall); + addItem(ModItems.regenIvy); addBlock(ModBlocks.forestDrum); addBlock(ModBlocks.forestEye); addBlock(ModBlocks.enderEye); diff --git a/MODSRC/vazkii/botania/common/crafting/recipe/RegenIvyRecipe.java b/MODSRC/vazkii/botania/common/crafting/recipe/RegenIvyRecipe.java new file mode 100644 index 000000000..15e0ef324 --- /dev/null +++ b/MODSRC/vazkii/botania/common/crafting/recipe/RegenIvyRecipe.java @@ -0,0 +1,80 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Sep 3, 2014, 6:54:18 PM (GMT)] + */ +package vazkii.botania.common.crafting.recipe; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemTool; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.item.ItemRegenIvy; +import vazkii.botania.common.item.ModItems; + +public class RegenIvyRecipe implements IRecipe { + + @Override + public boolean matches(InventoryCrafting var1, World var2) { + ItemStack tool = null; + boolean foundIvy = false; + int materialsFound = 0; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + Item item = stack.getItem(); + if(item.isRepairable()) + tool = stack; + + else if(stack.getItem() == ModItems.regenIvy) + foundIvy = true; + + else if(tool != null && tool.getItem().getIsRepairable(tool, stack)) + materialsFound++; + + else return false; // Found an invalid item, breaking the recipe + } + } + + return tool != null && foundIvy && materialsFound == 3; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) { + ItemStack tool = null; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null && stack.getItem().isDamageable()) + tool = stack; + } + + if(tool == null) + return null; + + ItemStack toolCopy = tool.copy(); + ItemNBTHelper.setBoolean(toolCopy, ItemRegenIvy.TAG_REGEN, true); + return toolCopy; + } + + @Override + public int getRecipeSize() { + return 10; + } + + @Override + public ItemStack getRecipeOutput() { + return null; + } + +} diff --git a/MODSRC/vazkii/botania/common/item/ItemRegenIvy.java b/MODSRC/vazkii/botania/common/item/ItemRegenIvy.java new file mode 100644 index 000000000..47584bbc3 --- /dev/null +++ b/MODSRC/vazkii/botania/common/item/ItemRegenIvy.java @@ -0,0 +1,50 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Sep 3, 2014, 6:31:10 PM (GMT)] + */ +package vazkii.botania.common.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.oredict.RecipeSorter.Category; +import vazkii.botania.api.mana.ManaItemHandler; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.crafting.recipe.RegenIvyRecipe; +import vazkii.botania.common.lib.LibItemNames; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.registry.GameRegistry; + +public class ItemRegenIvy extends ItemMod { + + public static final String TAG_REGEN = "Botania_regenIvy"; + private static final int MANA_PER_DAMAGE = 200; + + public ItemRegenIvy() { + setUnlocalizedName(LibItemNames.REGEN_IVY); + GameRegistry.addRecipe(new RegenIvyRecipe()); + RecipeSorter.register("botania:regenIvy", RegenIvyRecipe.class, Category.SHAPELESS, ""); + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onTick(LivingUpdateEvent event) { + if(event.entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) event.entity; + for(int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if(stack != null && ItemNBTHelper.detectNBT(stack) && ItemNBTHelper.getBoolean(stack, TAG_REGEN, false) && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, player, MANA_PER_DAMAGE, true)) + stack.setItemDamage(stack.getItemDamage() - 1); + } + } + } +} diff --git a/MODSRC/vazkii/botania/common/item/ModItems.java b/MODSRC/vazkii/botania/common/item/ModItems.java index e28774118..dc99adb40 100644 --- a/MODSRC/vazkii/botania/common/item/ModItems.java +++ b/MODSRC/vazkii/botania/common/item/ModItems.java @@ -153,6 +153,7 @@ public final class ModItems { public static Item sparkUpgrade; public static Item diviningRod; public static Item gravityRod; + public static Item regenIvy; public static void init() { lexicon = new ItemLexicon(); @@ -241,7 +242,8 @@ public final class ModItems { sparkUpgrade = new ItemSparkUpgrade(); diviningRod = new ItemDiviningRod(); gravityRod = new ItemGravityRod(); - + regenIvy = new ItemRegenIvy(); + OreDictionary.registerOre(LibOreDict.LEXICON, lexicon); for(int i = 0; i < 16; i++) { OreDictionary.registerOre(LibOreDict.PETAL[i], new ItemStack(petal, 1, i)); diff --git a/MODSRC/vazkii/botania/common/lib/LibItemNames.java b/MODSRC/vazkii/botania/common/lib/LibItemNames.java index f76b8849c..f7c4968e6 100644 --- a/MODSRC/vazkii/botania/common/lib/LibItemNames.java +++ b/MODSRC/vazkii/botania/common/lib/LibItemNames.java @@ -99,6 +99,7 @@ public final class LibItemNames { public static final String SPARK_UPGRADE = "sparkUpgrade"; public static final String DIVINING_ROD = "diviningRod"; public static final String GRAVITY_ROD = "gravityRod"; + public static final String REGEN_IVY = "regenIvy"; public static final String[] LENS_NAMES = new String[] { "lensNormal", diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 14c099eb5..eac85f029 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -48,6 +48,7 @@ botaniamisc.coarseDirt1=won't grow on it botaniamisc.spawnerTip=Tip: Use a Spawn Egg to change the mob botaniamisc.shardLevel=Shard Power %s botaniamisc.lexiconIndex=Lexicon Index +botaniamisc.hasIvy=Has Timeless Ivy # COLORS botania.color0=White @@ -706,6 +707,7 @@ item.botania:sparkUpgrade2.name=Spark Augment: Recessive item.botania:sparkUpgrade3.name=Spark Augment: Isolated item.botania:diviningRod.name=Rod of Divining item.botania:gravityRod.name=Rod of the Black Mesa +item.botania:regenIvy.name=Timeless Ivy # GUI TEXT botania.gui.lexicon.header=Lexica Botania, %s Edition Table of Contents