diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 16e402b42..55195fe53 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -65,6 +65,7 @@ public final class ActuallyAdditionsAPI{ public static Lens lensDeath; public static Lens lensColor; public static Lens lensDisruption; + public static Lens lensDisenchanting; /** * Adds a Recipe to the Crusher Recipe Registry diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java index d3fa4570c..0d3bc7188 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java @@ -138,6 +138,7 @@ public final class InitItems{ public static Item itemColorLens; public static Item itemExplosionLens; public static Item itemDamageLens; + public static Item itemDisenchantingLens; public static Item itemPickaxeCrystalRed; public static Item itemAxeCrystalRed; @@ -221,6 +222,7 @@ public final class InitItems{ itemColorLens = new ItemLens("itemColorLens", ActuallyAdditionsAPI.lensColor); itemExplosionLens = new ItemLens("itemExplosionLens", ActuallyAdditionsAPI.lensDetonation); itemDamageLens = new ItemLens("itemDamageLens", ActuallyAdditionsAPI.lensDeath); + itemDisenchantingLens = new ItemLens("itemDisenchantingLens", ActuallyAdditionsAPI.lensDisenchanting); itemCrystal = new ItemCrystal("itemCrystal"); itemLaserWrench = new ItemLaserWrench("itemLaserWrench"); itemChestToCrateUpgrade = new ItemChestToCrateUpgrade("itemChestToCrateUpgrade"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisenchanting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisenchanting.java new file mode 100644 index 000000000..5b7aa5a6e --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisenchanting.java @@ -0,0 +1,123 @@ +/* + * This file ("LensDisenchanting.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://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.items.lens; + +import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; +import de.ellpeck.actuallyadditions.api.lens.Lens; +import de.ellpeck.actuallyadditions.mod.util.ItemUtil; +import de.ellpeck.actuallyadditions.mod.util.Util; +import net.minecraft.block.state.IBlockState; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentData; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; + +import java.util.List; +import java.util.Map; + +public class LensDisenchanting extends Lens{ + + private static final int ENERGY_USE = 250000; + + @Override + public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){ + if(tile.getEnergy() >= ENERGY_USE){ + List items = tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX()+1, hitBlock.getY()+1, hitBlock.getZ()+1)); + if(items != null && !items.isEmpty()){ + EntityItem book = null; + EntityItem toDisenchant = null; + for(EntityItem item : items){ + if(item != null && !item.isDead){ + ItemStack stack = item.getEntityItem(); + if(stack != null){ + Item stackItem = stack.getItem(); + if(stackItem == Items.BOOK || stackItem == Items.ENCHANTED_BOOK){ + if(book == null){ + book = item; + } + else{ + return false; + } + } + else{ + Map enchants = EnchantmentHelper.getEnchantments(stack); + if(enchants != null && !enchants.isEmpty()){ + if(toDisenchant == null){ + toDisenchant = item; + } + else{ + return false; + } + } + } + } + } + } + + if(book != null && toDisenchant != null){ + ItemStack disenchantStack = toDisenchant.getEntityItem(); + ItemStack bookStack = book.getEntityItem(); + + Map enchants = EnchantmentHelper.getEnchantments(disenchantStack); + if(enchants != null && !enchants.isEmpty()){ + Enchantment enchant = enchants.keySet().iterator().next(); + int level = enchants.get(enchant); + + ItemStack newDisenchantStack = disenchantStack.copy(); + ItemStack newBookStack; + if(bookStack.getItem() == Items.BOOK){ + newBookStack = new ItemStack(Items.ENCHANTED_BOOK); + } + else{ + newBookStack = bookStack.copy(); + } + + ItemUtil.removeEnchantment(newDisenchantStack, enchant); + Items.ENCHANTED_BOOK.addEnchantment(newBookStack, new EnchantmentData(enchant, level)); + + EntityItem disenchanted = new EntityItem(toDisenchant.getEntityWorld(), toDisenchant.posX, toDisenchant.posY, toDisenchant.posZ, newDisenchantStack); + EntityItem newBook = new EntityItem(book.getEntityWorld(), book.posX, book.posY, book.posZ, newBookStack); + toDisenchant.setDead(); + book.setDead(); + tile.getWorldObject().spawnEntityInWorld(newBook); + tile.getWorldObject().spawnEntityInWorld(disenchanted); + + tile.extractEnergy(ENERGY_USE); + + return true; + } + } + } + } + return false; + } + + @Override + public float[] getColor(){ + return new float[]{234F/255F, 173F/255F, 255F/255F}; + } + + @Override + public int getDistance(){ + return 5; + } + + @Override + public boolean canInvoke(IAtomicReconstructor tile, EnumFacing sideToShootTo, int energyUsePerShot){ + return tile.getEnergy()-energyUsePerShot >= ENERGY_USE; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java index aca4cb11e..1dd121a9c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java @@ -21,5 +21,6 @@ public final class Lenses{ ActuallyAdditionsAPI.lensDeath = new LensDeath(); ActuallyAdditionsAPI.lensColor = new LensColor(); ActuallyAdditionsAPI.lensDisruption = new LensDisruption(); + ActuallyAdditionsAPI.lensDisenchanting = new LensDisenchanting(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java index 5c5c198ad..a52ad9a29 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java @@ -119,6 +119,9 @@ public final class ItemUtil{ ench.removeTag(i); } } + if(ench.hasNoTags() && stack.hasTagCompound()){ + stack.getTagCompound().removeTag("ench"); + } } } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index eca2988ca..38d822dc6 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -429,6 +429,7 @@ item.actuallyadditions.itemMiscLens.name=Lens item.actuallyadditions.itemColorLens.name=Lens of Color item.actuallyadditions.itemExplosionLens.name=Lens of Detonation item.actuallyadditions.itemDamageLens.name=Lens of Certain Death +item.actuallyadditions.itemDisenchantingLens.name=Lens of Disenchanting item.actuallyadditions.itemCrateKeeper.name=Storage Crate Keeper item.actuallyadditions.itemPickaxeCrystalRed.name=Restonia Crystal Pickaxe item.actuallyadditions.itemAxeCrystalRed.name=Restonia Crystal Axe diff --git a/src/main/resources/assets/actuallyadditions/models/item/itemDisenchantingLens.json b/src/main/resources/assets/actuallyadditions/models/item/itemDisenchantingLens.json new file mode 100644 index 000000000..0976dd96b --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/models/item/itemDisenchantingLens.json @@ -0,0 +1,6 @@ +{ + "parent": "actuallyadditions:item/standardItem", + "textures": { + "layer0": "actuallyadditions:items/itemDisenchantingLens" + } +} diff --git a/src/main/resources/assets/actuallyadditions/textures/items/itemDisenchantingLens.png b/src/main/resources/assets/actuallyadditions/textures/items/itemDisenchantingLens.png new file mode 100644 index 000000000..1a04f81ff Binary files /dev/null and b/src/main/resources/assets/actuallyadditions/textures/items/itemDisenchantingLens.png differ