Search in sources :

Example 1 with LivingArmourUpgrade

use of WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade in project BloodMagic by WayofTime.

the class RitualUpgradeRemove method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    if (world.isRemote) {
        return;
    }
    BlockPos pos = masterRitualStone.getBlockPos();
    AreaDescriptor checkRange = getBlockRange(CHECK_RANGE);
    List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, checkRange.getAABB(pos));
    for (EntityPlayer player : playerList) {
        if (LivingArmour.hasFullSet(player)) {
            boolean removedUpgrade = false;
            ItemStack chestStack = Iterables.toArray(player.getArmorInventoryList(), ItemStack.class)[2];
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                @SuppressWarnings("unchecked") HashMap<String, LivingArmourUpgrade> upgradeMap = (HashMap<String, LivingArmourUpgrade>) armour.upgradeMap.clone();
                for (Entry<String, LivingArmourUpgrade> entry : upgradeMap.entrySet()) {
                    LivingArmourUpgrade upgrade = entry.getValue();
                    String upgradeKey = entry.getKey();
                    ItemStack upgradeStack = new ItemStack(RegistrarBloodMagicItems.UPGRADE_TOME);
                    LivingUpgrades.setKey(upgradeStack, upgradeKey);
                    LivingUpgrades.setLevel(upgradeStack, upgrade.getUpgradeLevel());
                    boolean successful = armour.removeUpgrade(player, upgrade);
                    if (successful) {
                        removedUpgrade = true;
                        world.spawnEntity(new EntityItem(world, player.posX, player.posY, player.posZ, upgradeStack));
                        for (Entry<String, StatTracker> trackerEntry : armour.trackerMap.entrySet()) {
                            StatTracker tracker = trackerEntry.getValue();
                            if (tracker != null) {
                                if (tracker.providesUpgrade(upgradeKey)) {
                                    // Resets the tracker if the upgrade corresponding to it was removed.
                                    tracker.resetTracker();
                                }
                            }
                        }
                    }
                }
                if (removedUpgrade) {
                    ((ItemLivingArmour) chestStack.getItem()).setLivingArmour(chestStack, armour, true);
                    ItemLivingArmour.setLivingArmour(chestStack, armour);
                    armour.recalculateUpgradePoints();
                    masterRitualStone.setActive(false);
                    world.spawnEntity(new EntityLightningBolt(world, pos.getX(), pos.getY() - 1, pos.getZ(), true));
                }
            }
        }
    }
}
Also used : ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) HashMap(java.util.HashMap) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) World(net.minecraft.world.World) EntityPlayer(net.minecraft.entity.player.EntityPlayer) StatTracker(WayofTime.bloodmagic.livingArmour.StatTracker) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with LivingArmourUpgrade

use of WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade 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)

Example 3 with LivingArmourUpgrade

use of WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade in project BloodMagic by WayofTime.

the class LivingArmourHandler method onJumpEvent.

// Applies: Jump
@SubscribeEvent
public static void onJumpEvent(LivingEvent.LivingJumpEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        if (LivingArmour.hasFullSet(player)) {
            ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                StatTrackerJump.incrementCounter(armour);
                if (!player.isSneaking()) {
                    LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgradeFromNBT(BloodMagic.MODID + ".upgrade.jump", chestStack);
                    if (upgrade instanceof LivingArmourUpgradeJump) {
                        player.motionY += ((LivingArmourUpgradeJump) upgrade).getJumpModifier();
                    }
                }
            }
        }
    }
}
Also used : ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with LivingArmourUpgrade

use of WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade in project BloodMagic by WayofTime.

the class LivingArmourHandler method onEntityJoinedWorld.

// Applies: Storm Trooper
@SubscribeEvent
public static void onEntityJoinedWorld(EntityJoinWorldEvent event) {
    Entity owner = null;
    if (event.getEntity() instanceof EntityArrow) {
        owner = ((EntityArrow) event.getEntity()).shootingEntity;
    } else if (event.getEntity() instanceof EntityThrowable) {
        owner = ((EntityThrowable) event.getEntity()).getThrower();
    }
    if (owner instanceof EntityPlayer) {
        Entity projectile = event.getEntity();
        EntityPlayer player = (EntityPlayer) owner;
        if (LivingArmour.hasFullSet(player)) {
            ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(BloodMagic.MODID + ".upgrade.stormTrooper", chestStack);
                if (upgrade instanceof LivingArmourUpgradeStormTrooper) {
                    float velocityModifier = (float) (((LivingArmourUpgradeStormTrooper) upgrade).getArrowJiggle(player) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
                    projectile.motionX += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    projectile.motionY += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    projectile.motionZ += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) LivingArmourUpgradeStormTrooper(WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with LivingArmourUpgrade

use of WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade in project BloodMagic by WayofTime.

the class ItemUpgradeTome method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (world.isRemote) {
        return super.onItemRightClick(world, player, hand);
    }
    LivingArmourUpgrade upgrade = LivingUpgrades.getUpgrade(stack);
    if (upgrade == null) {
        return super.onItemRightClick(world, player, hand);
    }
    ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    if (chestStack.getItem() instanceof ItemLivingArmour) {
        LivingArmour armour = ItemLivingArmour.getLivingArmourFromStack(chestStack);
        if (armour == null) {
            return super.onItemRightClick(world, player, hand);
        }
        if (armour.upgradeArmour(player, upgrade)) {
            ItemLivingArmour.setLivingArmour(chestStack, armour);
            // ((ItemLivingArmour) chestStack.getItem()).setLivingArmour(stack, armour, false);
            stack.shrink(1);
        }
    }
    return super.onItemRightClick(world, player, hand);
}
Also used : ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) ItemStack(net.minecraft.item.ItemStack)

Aggregations

LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)19 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)18 ItemStack (net.minecraft.item.ItemStack)18 ItemLivingArmour (WayofTime.bloodmagic.item.armour.ItemLivingArmour)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)12 World (net.minecraft.world.World)4 BlockPos (net.minecraft.util.math.BlockPos)3 StatTracker (WayofTime.bloodmagic.livingArmour.StatTracker)2 StatTrackerGrimReaperSprint (WayofTime.bloodmagic.livingArmour.tracker.StatTrackerGrimReaperSprint)2 LivingArmourUpgradeSelfSacrifice (WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeSelfSacrifice)2 ArrayList (java.util.ArrayList)2 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)2 EntityArrow (net.minecraft.entity.projectile.EntityArrow)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IBloodAltar (WayofTime.bloodmagic.altar.IBloodAltar)1 IUpgradeTrainer (WayofTime.bloodmagic.iface.IUpgradeTrainer)1 ItemPackSacrifice (WayofTime.bloodmagic.item.gear.ItemPackSacrifice)1 LivingArmourUpgradeBattleHungry (WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeBattleHungry)1 LivingArmourUpgradeCrippledArm (WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeCrippledArm)1