use of WayofTime.bloodmagic.livingArmour.LivingArmour in project BloodMagic by WayofTime.
the class ItemLivingArmour method getLivingArmourFromStack.
@Nullable
public static LivingArmour getLivingArmourFromStack(ItemStack stack) {
NBTTagCompound livingTag = getArmourTag(stack);
LivingArmour livingArmour = new LivingArmour();
livingArmour.readFromNBT(livingTag);
return livingArmour;
}
use of WayofTime.bloodmagic.livingArmour.LivingArmour 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.LivingArmour 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.LivingArmour 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.LivingArmour 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