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));
}
}
}
}
}
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);
}
}
}
}
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();
}
}
}
}
}
}
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;
}
}
}
}
}
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);
}
Aggregations