Search in sources :

Example 1 with IUpgradeTrainer

use of WayofTime.bloodmagic.iface.IUpgradeTrainer in project BloodMagic by WayofTime.

the class CraftingHandler method onAnvil.

// Handles crafting of: Revealing Upgrade Tome, Elytra Upgrade Tome, Combining Upgrade Tomes, Setting Upgrade for Trainer
@SubscribeEvent
public static void onAnvil(AnvilUpdateEvent event) {
    if (event.getLeft().getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING) {
        if (event.getRight().getItem() == Items.NAME_TAG) {
            ItemStack output = event.getLeft().copy();
            if (!output.hasTagCompound())
                output.setTagCompound(new NBTTagCompound());
            output.getTagCompound().setString(Constants.NBT.COLOR, event.getRight().getDisplayName());
            event.setCost(1);
            event.setOutput(output);
            return;
        }
        if (event.getRight().getItem() == Items.DYE) {
            EnumDyeColor dyeColor = ItemBanner.getBaseColor(event.getRight());
            ItemStack output = event.getLeft().copy();
            if (!output.hasTagCompound())
                output.setTagCompound(new NBTTagCompound());
            output.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(Utils.DYE_COLOR_VALUES.getOrDefault(dyeColor, 0)));
            event.setCost(1);
            event.setOutput(output);
            return;
        }
    }
    if (event.getLeft().getItem() == Items.BOOK && event.getRight().getItem() == Items.ELYTRA && !event.getRight().isItemDamaged()) {
        ItemStack output = new ItemStack(RegistrarBloodMagicItems.UPGRADE_TOME);
        output = NBTHelper.checkNBT(output);
        ItemHelper.LivingUpgrades.setKey(output, BloodMagic.MODID + ".upgrade.elytra");
        ItemHelper.LivingUpgrades.setLevel(output, 1);
        event.setCost(30);
        event.setOutput(output);
        return;
    }
    if (event.getLeft().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME && event.getRight().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME) {
        LivingArmourUpgrade leftUpgrade = ItemHelper.LivingUpgrades.getUpgrade(event.getLeft());
        if (leftUpgrade != null && !leftUpgrade.isDowngrade() && ItemHelper.LivingUpgrades.getKey(event.getLeft()).equals(ItemHelper.LivingUpgrades.getKey(event.getRight()))) {
            int leftLevel = ItemHelper.LivingUpgrades.getLevel(event.getLeft());
            int rightLevel = ItemHelper.LivingUpgrades.getLevel(event.getRight());
            if (leftLevel == rightLevel && leftLevel < leftUpgrade.getMaxTier() - 1) {
                ItemStack outputStack = event.getLeft().copy();
                ItemHelper.LivingUpgrades.setLevel(outputStack, leftLevel + 1);
                event.setCost(leftLevel + 2);
                event.setOutput(outputStack);
                return;
            }
        }
    }
    if (event.getLeft().getItem() instanceof IUpgradeTrainer && event.getRight().getItem() == RegistrarBloodMagicItems.UPGRADE_TOME) {
        LivingArmourUpgrade rightUpgrade = ItemHelper.LivingUpgrades.getUpgrade(event.getRight());
        if (rightUpgrade != null) {
            String key = ItemHelper.LivingUpgrades.getKey(event.getRight());
            ItemStack outputStack = event.getLeft().copy();
            List<String> keyList = new ArrayList<>();
            keyList.add(key);
            if (((IUpgradeTrainer) event.getLeft().getItem()).setTrainedUpgrades(outputStack, keyList)) {
                event.setCost(1);
                event.setOutput(outputStack);
            }
        }
    }
}
Also used : LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) IUpgradeTrainer(WayofTime.bloodmagic.iface.IUpgradeTrainer) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IUpgradeTrainer (WayofTime.bloodmagic.iface.IUpgradeTrainer)1 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)1 ArrayList (java.util.ArrayList)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1