diff --git a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java index 620310a9c..0572a3cb1 100644 --- a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java +++ b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java @@ -29,6 +29,7 @@ import ellpeck.actuallyadditions.inventory.GuiHandler; import ellpeck.actuallyadditions.items.InitForeignPaxels; import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.items.ItemCoffee; +import ellpeck.actuallyadditions.items.tools.table.InitToolTableTools; import ellpeck.actuallyadditions.material.InitArmorMaterials; import ellpeck.actuallyadditions.material.InitToolMaterials; import ellpeck.actuallyadditions.misc.DispenserHandlerEmptyBucket; @@ -38,7 +39,6 @@ import ellpeck.actuallyadditions.ore.InitOreDict; import ellpeck.actuallyadditions.proxy.IProxy; import ellpeck.actuallyadditions.recipe.FuelHandler; import ellpeck.actuallyadditions.recipe.HairyBallHandler; -import ellpeck.actuallyadditions.recipe.ToolTableHandler; import ellpeck.actuallyadditions.recipe.TreasureChestHandler; import ellpeck.actuallyadditions.tile.TileEntityBase; import ellpeck.actuallyadditions.update.UpdateChecker; @@ -97,9 +97,9 @@ public class ActuallyAdditions{ CrusherCrafting.init(); ItemCrafting.initMashedFoodRecipes(); HairyBallHandler.init(); - ToolTableHandler.init(); TreasureChestHandler.init(); InitForeignPaxels.init(); + InitToolTableTools.init(); proxy.postInit(event); ModUtil.LOGGER.info("PostInitialization Finished."); diff --git a/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java b/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java index 2919cb99d..a7af92f34 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java +++ b/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java @@ -11,7 +11,6 @@ package ellpeck.actuallyadditions.event; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.ReflectionHelper; import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.InitBooklet; import ellpeck.actuallyadditions.booklet.page.BookletPage; @@ -20,17 +19,12 @@ import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Slot; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.oredict.OreDictionary; import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; public class TooltipEvent{ @@ -41,46 +35,28 @@ public class TooltipEvent{ @SubscribeEvent public void onTooltipEvent(ItemTooltipEvent event){ //Booklet Access - GuiScreen screen = Minecraft.getMinecraft().currentScreen; - if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){ - GuiContainer gui = (GuiContainer)screen; - if(gui.inventorySlots != null && gui.inventorySlots.inventorySlots != null && !gui.inventorySlots.inventorySlots.isEmpty()){ - for(int i = 0; i < gui.inventorySlots.inventorySlots.size(); i++){ - Slot slot = gui.inventorySlots.getSlot(i); - - int guiLeft = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 4); - int guiTop = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 5); - int mouseX = Mouse.getEventX()*gui.width/Minecraft.getMinecraft().displayWidth-guiLeft; - int mouseY = gui.height-Mouse.getEventY()*gui.height/Minecraft.getMinecraft().displayHeight-1-guiTop; - - if(mouseX >= slot.xDisplayPosition-1 && mouseY >= slot.yDisplayPosition-1 && mouseX <= slot.xDisplayPosition+16 && mouseY <= slot.yDisplayPosition+16){ - ItemStack stack = slot.getStack(); - if(stack != null){ - for(BookletPage page : InitBooklet.pagesWithItemStackData){ - if(ItemUtil.areItemsEqual(stack, page.getItemStackForPage(), true)){ - int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode(); - if(!ConfigBoolValues.NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled() || Minecraft.getMinecraft().thePlayer.inventory.hasItem(InitItems.itemLexicon)){ - if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ - event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]")); - } - if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){ - GuiBooklet book = new GuiBooklet(); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); - Minecraft.getMinecraft().displayGuiScreen(book); - book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.BUTTONS_PER_PAGE+1, true); - book.openChapter(page.getChapter(), page); - } - } - else{ - if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ - event.toolTip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(EnumChatFormatting.DARK_RED+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".noBookletInInventory"), GuiBooklet.TOOLTIP_SPLIT_LENGTH)); - } - } - break; - } - } + if(event.itemStack != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiBooklet)){ + for(BookletPage page : InitBooklet.pagesWithItemStackData){ + if(ItemUtil.areItemsEqual(event.itemStack, page.getItemStackForPage(), true)){ + int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode(); + if(!ConfigBoolValues.NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled() || Minecraft.getMinecraft().thePlayer.inventory.hasItem(InitItems.itemLexicon)){ + if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ + event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]")); + } + if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){ + GuiBooklet book = new GuiBooklet(); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + Minecraft.getMinecraft().displayGuiScreen(book); + book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.BUTTONS_PER_PAGE+1, true); + book.openChapter(page.getChapter(), page); } } + else{ + if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ + event.toolTip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(EnumChatFormatting.DARK_RED+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".noBookletInInventory"), GuiBooklet.TOOLTIP_SPLIT_LENGTH)); + } + } + break; } } } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemBattery.java b/src/main/java/ellpeck/actuallyadditions/items/ItemBattery.java index ac0d74852..de41af0a8 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemBattery.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemBattery.java @@ -24,7 +24,7 @@ public class ItemBattery extends ItemEnergy implements INameableItem{ private String name; public ItemBattery(String name, int capacity, int transfer){ - super(capacity, transfer, 1); + super(capacity, transfer); this.setMaxStackSize(1); this.name = name; } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java index 28beb6721..60fce5026 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java @@ -20,6 +20,7 @@ import ellpeck.actuallyadditions.config.values.ConfigFloatValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.inventory.GuiHandler; import ellpeck.actuallyadditions.util.INameableItem; +import ellpeck.actuallyadditions.util.ItemUtil; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.block.Block; @@ -49,7 +50,7 @@ import java.util.Set; public class ItemDrill extends ItemEnergy implements INameableItem{ public ItemDrill(){ - super(500000, 5000, 4); + super(500000, 5000); } @Override @@ -379,15 +380,8 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ else toReturn = this.breakBlocks(stack, 0, player.worldObj, x, y, z, player); //Removes Enchantments added above - NBTTagList ench = stack.getEnchantmentTagList(); - if(ench != null){ - for(int i = 0; i < ench.tagCount(); i++){ - short id = ench.getCompoundTagAt(i).getShort("id"); - if(id == Enchantment.silkTouch.effectId || id == Enchantment.fortune.effectId){ - ench.removeTag(i); - } - } - } + ItemUtil.removeEnchantment(stack, Enchantment.silkTouch); + ItemUtil.removeEnchantment(stack, Enchantment.fortune); } return toReturn; } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemEnergy.java b/src/main/java/ellpeck/actuallyadditions/items/ItemEnergy.java index 39431d512..0ae1c6be6 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemEnergy.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemEnergy.java @@ -24,13 +24,10 @@ import java.util.List; public abstract class ItemEnergy extends ItemEnergyContainer{ - private int infoLines; - - public ItemEnergy(int maxPower, int transfer, int infoLines){ + public ItemEnergy(int maxPower, int transfer){ super(maxPower, transfer); this.setHasSubtypes(true); this.setMaxStackSize(1); - this.infoLines = infoLines; } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java b/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java index b956e55c4..a585b0d23 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java @@ -36,7 +36,7 @@ import java.util.Random; public class ItemGrowthRing extends ItemEnergy implements INameableItem{ public ItemGrowthRing(){ - super(1000000, 5000, 1); + super(1000000, 5000); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java b/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java index 5fa935779..33e3b4254 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java @@ -31,7 +31,7 @@ import java.util.ArrayList; public class ItemMagnetRing extends ItemEnergy implements INameableItem{ public ItemMagnetRing(){ - super(3000000, 5000, 1); + super(3000000, 5000); } @SuppressWarnings("unchecked") diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java b/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java index cd90d7897..f1c09eeeb 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java @@ -32,7 +32,7 @@ import net.minecraftforge.common.util.ForgeDirection; public class ItemTeleStaff extends ItemEnergy implements INameableItem{ public ItemTeleStaff(){ - super(500000, 10000, 2); + super(500000, 10000); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemWaterRemovalRing.java b/src/main/java/ellpeck/actuallyadditions/items/ItemWaterRemovalRing.java index efbd99c6e..331943563 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemWaterRemovalRing.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemWaterRemovalRing.java @@ -28,7 +28,7 @@ import net.minecraft.world.World; public class ItemWaterRemovalRing extends ItemEnergy implements INameableItem{ public ItemWaterRemovalRing(){ - super(1000000, 5000, 1); + super(1000000, 5000); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/table/InitToolTableTools.java b/src/main/java/ellpeck/actuallyadditions/items/tools/table/InitToolTableTools.java new file mode 100644 index 000000000..ae142dab1 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/table/InitToolTableTools.java @@ -0,0 +1,31 @@ +/* + * This file ("InitToolTableTools.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.tools.table; + +import ellpeck.actuallyadditions.items.tools.table.ItemPickaxeFixedEnchants.EnchantmentCombo; +import ellpeck.actuallyadditions.util.ItemUtil; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; + +public class InitToolTableTools{ + + public static Item itemMinersPickaxe; + public static Item itemSilkyMinersPickaxe; + + public static void init(){ + itemMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemMinersPickaxe", EnumRarity.rare, new EnchantmentCombo(Enchantment.fortune, 2), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1)); + ItemUtil.register(itemMinersPickaxe); + + itemSilkyMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemSilkyMinersPickaxe", EnumRarity.rare, new EnchantmentCombo(Enchantment.silkTouch, 1), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1)); + ItemUtil.register(itemSilkyMinersPickaxe); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemAxeFixedEnchants.java b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemAxeFixedEnchants.java new file mode 100644 index 000000000..730aecc9c --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemAxeFixedEnchants.java @@ -0,0 +1,82 @@ +/* + * This file ("ItemAxeFixedEnchants.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.tools.table; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.tools.ItemAxeAA; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.List; + +public class ItemAxeFixedEnchants extends ItemAxeAA{ + + public static class EnchantmentCombo{ + public Enchantment enchantment; + public int level; + + public EnchantmentCombo(Enchantment ench, int level){ + this.enchantment = ench; + this.level = level; + } + } + + private EnchantmentCombo[] enchantments; + + public ItemAxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){ + super(toolMat, "", unlocalizedName, rarity); + this.enchantments = enchantments; + } + + @Override + public boolean hasEffect(ItemStack stack, int pass){ + return false; + } + + @Override + public boolean isRepairable(){ + return false; + } + + @Override + public boolean getIsRepairable(ItemStack stack1, ItemStack stack2){ + return this.isRepairable(); + } + + @Override + public int getItemEnchantability(ItemStack stack){ + return 0; + } + + @Override + public void onCreated(ItemStack stack, World world, EntityPlayer player){ + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + } + + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list){ + ItemStack stack = new ItemStack(item); + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + list.add(stack); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemPickaxeFixedEnchants.java b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemPickaxeFixedEnchants.java new file mode 100644 index 000000000..68a2625e1 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemPickaxeFixedEnchants.java @@ -0,0 +1,82 @@ +/* + * This file ("ItemPickaxeNoEnchants.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.tools.table; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.tools.ItemPickaxeAA; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.List; + +public class ItemPickaxeFixedEnchants extends ItemPickaxeAA{ + + public static class EnchantmentCombo{ + public Enchantment enchantment; + public int level; + + public EnchantmentCombo(Enchantment ench, int level){ + this.enchantment = ench; + this.level = level; + } + } + + private EnchantmentCombo[] enchantments; + + public ItemPickaxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){ + super(toolMat, "", unlocalizedName, rarity); + this.enchantments = enchantments; + } + + @Override + public boolean hasEffect(ItemStack stack, int pass){ + return false; + } + + @Override + public boolean isRepairable(){ + return false; + } + + @Override + public boolean getIsRepairable(ItemStack stack1, ItemStack stack2){ + return this.isRepairable(); + } + + @Override + public int getItemEnchantability(ItemStack stack){ + return 0; + } + + @Override + public void onCreated(ItemStack stack, World world, EntityPlayer player){ + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + } + + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list){ + ItemStack stack = new ItemStack(item); + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + list.add(stack); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemShovelFixedEnchants.java b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemShovelFixedEnchants.java new file mode 100644 index 000000000..e81f66945 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemShovelFixedEnchants.java @@ -0,0 +1,82 @@ +/* + * This file ("ItemShovelFixedEnchants.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.tools.table; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.tools.ItemShovelAA; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.List; + +public class ItemShovelFixedEnchants extends ItemShovelAA{ + + public static class EnchantmentCombo{ + public Enchantment enchantment; + public int level; + + public EnchantmentCombo(Enchantment ench, int level){ + this.enchantment = ench; + this.level = level; + } + } + + private EnchantmentCombo[] enchantments; + + public ItemShovelFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){ + super(toolMat, "", unlocalizedName, rarity); + this.enchantments = enchantments; + } + + @Override + public boolean hasEffect(ItemStack stack, int pass){ + return false; + } + + @Override + public boolean isRepairable(){ + return false; + } + + @Override + public boolean getIsRepairable(ItemStack stack1, ItemStack stack2){ + return this.isRepairable(); + } + + @Override + public int getItemEnchantability(ItemStack stack){ + return 0; + } + + @Override + public void onCreated(ItemStack stack, World world, EntityPlayer player){ + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + } + + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list){ + ItemStack stack = new ItemStack(item); + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + list.add(stack); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemSwordFixedEnchants.java b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemSwordFixedEnchants.java new file mode 100644 index 000000000..1ce51a1fb --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/tools/table/ItemSwordFixedEnchants.java @@ -0,0 +1,82 @@ +/* + * This file ("ItemSwordFixedEnchants.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.tools.table; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.tools.ItemSwordAA; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.List; + +public class ItemSwordFixedEnchants extends ItemSwordAA{ + + public static class EnchantmentCombo{ + public Enchantment enchantment; + public int level; + + public EnchantmentCombo(Enchantment ench, int level){ + this.enchantment = ench; + this.level = level; + } + } + + private EnchantmentCombo[] enchantments; + + public ItemSwordFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){ + super(toolMat, "", unlocalizedName, rarity); + this.enchantments = enchantments; + } + + @Override + public boolean hasEffect(ItemStack stack, int pass){ + return false; + } + + @Override + public boolean isRepairable(){ + return false; + } + + @Override + public boolean getIsRepairable(ItemStack stack1, ItemStack stack2){ + return this.isRepairable(); + } + + @Override + public int getItemEnchantability(ItemStack stack){ + return 0; + } + + @Override + public void onCreated(ItemStack stack, World world, EntityPlayer player){ + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + } + + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list){ + ItemStack stack = new ItemStack(item); + for(EnchantmentCombo combo : this.enchantments){ + stack.addEnchantment(combo.enchantment, combo.level); + } + list.add(stack); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/ToolTableHandler.java b/src/main/java/ellpeck/actuallyadditions/recipe/ToolTableHandler.java index 74165f747..05c604ba2 100644 --- a/src/main/java/ellpeck/actuallyadditions/recipe/ToolTableHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/recipe/ToolTableHandler.java @@ -10,10 +10,7 @@ package ellpeck.actuallyadditions.recipe; -import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.util.ItemUtil; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import java.util.ArrayList; @@ -22,12 +19,7 @@ public class ToolTableHandler{ public static ArrayList recipes = new ArrayList(); - public static void init(){ - //TODO Actual real recipes - addRecipe(new ItemStack(InitItems.itemPhantomConnector), new ItemStack(Items.diamond_pickaxe), new ItemStack(Blocks.stone_brick_stairs), new ItemStack(Blocks.planks)); - } - - private static void addRecipe(ItemStack output, ItemStack... itemsNeeded){ + public static void addRecipe(ItemStack output, ItemStack... itemsNeeded){ recipes.add(new Recipe(output, itemsNeeded)); } diff --git a/src/main/java/ellpeck/actuallyadditions/util/ItemUtil.java b/src/main/java/ellpeck/actuallyadditions/util/ItemUtil.java index 97008407a..665388084 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/ItemUtil.java +++ b/src/main/java/ellpeck/actuallyadditions/util/ItemUtil.java @@ -12,8 +12,10 @@ package ellpeck.actuallyadditions.util; import cpw.mods.fml.common.registry.GameRegistry; import ellpeck.actuallyadditions.creative.CreativeTab; +import net.minecraft.enchantment.Enchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagList; public class ItemUtil{ @@ -78,4 +80,16 @@ public class ItemUtil{ public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2, boolean checkWildcard){ return stack1 != null && stack2 != null && (stack1.isItemEqual(stack2) || (checkWildcard && stack1.getItem() == stack2.getItem() && (stack1.getItemDamage() == Util.WILDCARD || stack2.getItemDamage() == Util.WILDCARD))); } + + public static void removeEnchantment(ItemStack stack, Enchantment e){ + NBTTagList ench = stack.getEnchantmentTagList(); + if(ench != null){ + for(int i = 0; i < ench.tagCount(); i++){ + short id = ench.getCompoundTagAt(i).getShort("id"); + if(id == e.effectId){ + ench.removeTag(i); + } + } + } + } } diff --git a/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java b/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java index 0ff3273e1..8a67716ee 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java +++ b/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java @@ -299,7 +299,7 @@ public class WorldUtil{ Block block = world.getBlock(xPos, yPos, zPos); int meta = world.getBlockMetadata(xPos, yPos, zPos); //If the Block can be harvested or not - boolean canHarvest = block.canHarvestBlock(player, meta) && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem().canHarvestBlock(block, player.getCurrentEquippedItem()); + boolean canHarvest = block.canHarvestBlock(player, meta); if(!world.isRemote){ //Server-Side only, special cases