mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
parent
5b924bbd3a
commit
b1d0a72c4f
8 changed files with 137 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -21,5 +21,6 @@ public final class Lenses{
|
|||
ActuallyAdditionsAPI.lensDeath = new LensDeath();
|
||||
ActuallyAdditionsAPI.lensColor = new LensColor();
|
||||
ActuallyAdditionsAPI.lensDisruption = new LensDisruption();
|
||||
ActuallyAdditionsAPI.lensDisenchanting = new LensDisenchanting();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,9 @@ public final class ItemUtil{
|
|||
ench.removeTag(i);
|
||||
}
|
||||
}
|
||||
if(ench.hasNoTags() && stack.hasTagCompound()){
|
||||
stack.getTagCompound().removeTag("ench");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "actuallyadditions:item/standardItem",
|
||||
"textures": {
|
||||
"layer0": "actuallyadditions:items/itemDisenchantingLens"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 411 B |
Loading…
Reference in a new issue