Added lens of disenchanting.

Closes #161
This commit is contained in:
Ellpeck 2016-07-20 10:42:41 +02:00
parent 5b924bbd3a
commit b1d0a72c4f
8 changed files with 137 additions and 0 deletions

View file

@ -65,6 +65,7 @@ public final class ActuallyAdditionsAPI{
public static Lens lensDeath; public static Lens lensDeath;
public static Lens lensColor; public static Lens lensColor;
public static Lens lensDisruption; public static Lens lensDisruption;
public static Lens lensDisenchanting;
/** /**
* Adds a Recipe to the Crusher Recipe Registry * Adds a Recipe to the Crusher Recipe Registry

View file

@ -138,6 +138,7 @@ public final class InitItems{
public static Item itemColorLens; public static Item itemColorLens;
public static Item itemExplosionLens; public static Item itemExplosionLens;
public static Item itemDamageLens; public static Item itemDamageLens;
public static Item itemDisenchantingLens;
public static Item itemPickaxeCrystalRed; public static Item itemPickaxeCrystalRed;
public static Item itemAxeCrystalRed; public static Item itemAxeCrystalRed;
@ -221,6 +222,7 @@ public final class InitItems{
itemColorLens = new ItemLens("itemColorLens", ActuallyAdditionsAPI.lensColor); itemColorLens = new ItemLens("itemColorLens", ActuallyAdditionsAPI.lensColor);
itemExplosionLens = new ItemLens("itemExplosionLens", ActuallyAdditionsAPI.lensDetonation); itemExplosionLens = new ItemLens("itemExplosionLens", ActuallyAdditionsAPI.lensDetonation);
itemDamageLens = new ItemLens("itemDamageLens", ActuallyAdditionsAPI.lensDeath); itemDamageLens = new ItemLens("itemDamageLens", ActuallyAdditionsAPI.lensDeath);
itemDisenchantingLens = new ItemLens("itemDisenchantingLens", ActuallyAdditionsAPI.lensDisenchanting);
itemCrystal = new ItemCrystal("itemCrystal"); itemCrystal = new ItemCrystal("itemCrystal");
itemLaserWrench = new ItemLaserWrench("itemLaserWrench"); itemLaserWrench = new ItemLaserWrench("itemLaserWrench");
itemChestToCrateUpgrade = new ItemChestToCrateUpgrade("itemChestToCrateUpgrade"); itemChestToCrateUpgrade = new ItemChestToCrateUpgrade("itemChestToCrateUpgrade");

View file

@ -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<EntityItem> 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<Enchantment, Integer> 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<Enchantment, Integer> 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;
}
}

View file

@ -21,5 +21,6 @@ public final class Lenses{
ActuallyAdditionsAPI.lensDeath = new LensDeath(); ActuallyAdditionsAPI.lensDeath = new LensDeath();
ActuallyAdditionsAPI.lensColor = new LensColor(); ActuallyAdditionsAPI.lensColor = new LensColor();
ActuallyAdditionsAPI.lensDisruption = new LensDisruption(); ActuallyAdditionsAPI.lensDisruption = new LensDisruption();
ActuallyAdditionsAPI.lensDisenchanting = new LensDisenchanting();
} }
} }

View file

@ -119,6 +119,9 @@ public final class ItemUtil{
ench.removeTag(i); ench.removeTag(i);
} }
} }
if(ench.hasNoTags() && stack.hasTagCompound()){
stack.getTagCompound().removeTag("ench");
}
} }
} }
} }

View file

@ -429,6 +429,7 @@ item.actuallyadditions.itemMiscLens.name=Lens
item.actuallyadditions.itemColorLens.name=Lens of Color item.actuallyadditions.itemColorLens.name=Lens of Color
item.actuallyadditions.itemExplosionLens.name=Lens of Detonation item.actuallyadditions.itemExplosionLens.name=Lens of Detonation
item.actuallyadditions.itemDamageLens.name=Lens of Certain Death item.actuallyadditions.itemDamageLens.name=Lens of Certain Death
item.actuallyadditions.itemDisenchantingLens.name=Lens of Disenchanting
item.actuallyadditions.itemCrateKeeper.name=Storage Crate Keeper item.actuallyadditions.itemCrateKeeper.name=Storage Crate Keeper
item.actuallyadditions.itemPickaxeCrystalRed.name=Restonia Crystal Pickaxe item.actuallyadditions.itemPickaxeCrystalRed.name=Restonia Crystal Pickaxe
item.actuallyadditions.itemAxeCrystalRed.name=Restonia Crystal Axe item.actuallyadditions.itemAxeCrystalRed.name=Restonia Crystal Axe

View file

@ -0,0 +1,6 @@
{
"parent": "actuallyadditions:item/standardItem",
"textures": {
"layer0": "actuallyadditions:items/itemDisenchantingLens"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B