blob: 231bb7a4ae19d7ec35502f7ec992fbc92305bbec [file] [log] [blame] [raw]
package com.gildedgames.the_aether.player;
import com.gildedgames.the_aether.AetherConfig;
import com.gildedgames.the_aether.inventory.AccessoriesInventory;
import com.gildedgames.the_aether.items.AetherItems;
import com.gildedgames.the_aether.registry.achievements.AetherAchievements;
import com.gildedgames.the_aether.registry.achievements.AetherAchievement;
import com.gildedgames.the_aether.network.AetherNetwork;
import com.gildedgames.the_aether.network.packets.AccessoryPacket;
import com.gildedgames.the_aether.network.packets.PacketAchievement;
import com.gildedgames.the_aether.player.abilities.RepulsionAbility;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AchievementEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed;
import net.minecraftforge.event.entity.player.PlayerEvent.Clone;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent;
public class PlayerAetherEvents {
@SubscribeEvent
public void onPlayerAetherLoggedIn(PlayerLoggedInEvent event) {
if (!event.player.worldObj.isRemote) {
PlayerAether playerAether = PlayerAether.get(event.player);
AetherNetwork.sendTo(new AccessoryPacket(playerAether), (EntityPlayerMP) event.player);
playerAether.updateShardCount(playerAether.getShardsUsed());
if (!AetherConfig.shouldAetherStart())
{
playerAether.shouldGetPortal = false;
}
else
{
playerAether.givePortalFrame();
}
}
}
@SubscribeEvent
public void onPlayerAetherClone(Clone event) {
PlayerAether original = PlayerAether.get(event.original);
PlayerAether playerAether = PlayerAether.get(event.entityPlayer);
playerAether.updateShardCount(original.getShardsUsed());
if (!event.wasDeath || event.entityPlayer.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
playerAether.setAccessoryInventory(original.getAccessoryInventory());
}
if (event.wasDeath) {
playerAether.setBedLocation(original.getBedLocation());
}
}
@SubscribeEvent
public void onPlayerAetherRespawn(PlayerRespawnEvent event) {
if (!event.player.worldObj.isRemote) {
PlayerAether playerAether = PlayerAether.get(event.player);
AetherNetwork.sendTo(new AccessoryPacket(playerAether), (EntityPlayerMP) event.player);
playerAether.updateShardCount(playerAether.getShardsUsed());
playerAether.isPoisoned = false;
playerAether.poisonTime = 0;
playerAether.isCured = false;
playerAether.cureTime = 0;
}
}
@SubscribeEvent
public void onPlayerAetherChangedDimension(PlayerChangedDimensionEvent event) {
if (!event.player.worldObj.isRemote) {
PlayerAether playerAether = PlayerAether.get(event.player);
AetherNetwork.sendTo(new AccessoryPacket(playerAether), (EntityPlayerMP)event.player);
playerAether.updateShardCount(playerAether.getShardsUsed());
}
}
@SubscribeEvent
public void onPlayerAetherDrops(LivingDropsEvent event) {
if (event.entityLiving instanceof EntityPlayer && !event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
PlayerAether.get((EntityPlayer) event.entityLiving).getAccessoryInventory().dropAccessories();
}
}
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
if (event.entityLiving instanceof EntityPlayer) {
PlayerAether playerAether = PlayerAether.get((EntityPlayer) event.entityLiving);
if (playerAether.getAccessoryInventory().isWearingObsidianSet()) {
float original = event.ammount;
event.ammount = original / 2;
}
}
}
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event) {
if (event.entityLiving instanceof EntityPlayer) {
PlayerAether playerAether = PlayerAether.get((EntityPlayer) event.entityLiving);
if (playerAether.getAccessoryInventory().isWearingPhoenixSet() && event.source.isFireDamage()) {
event.setCanceled(true);
} else if (playerAether.getAbilities().get(3).shouldExecute()) {
event.setCanceled(((RepulsionAbility)playerAether.getAbilities().get(3)).onPlayerAttacked(event.source));
}
}
}
@SubscribeEvent
public void onUpdateBreakSpeed(BreakSpeed event) {
((AccessoriesInventory)PlayerAether.get(event.entityPlayer).getAccessoryInventory()).getCurrentPlayerStrVsBlock(event.newSpeed);
}
@SubscribeEvent
public void onAchievementGet(AchievementEvent event) {
Achievement achievement = event.achievement;
EntityPlayer player = event.entityPlayer;
if (!(achievement instanceof AetherAchievement)) {
return;
}
int achievementType = achievement == AetherAchievements.defeat_bronze ? 1 : achievement == AetherAchievements.defeat_silver ? 2 : 0;
if (!player.worldObj.isRemote && ((EntityPlayerMP) player).func_147099_x().canUnlockAchievement(achievement) && !((EntityPlayerMP) player).func_147099_x().hasAchievementUnlocked(achievement)) {
if (event.achievement == AetherAchievements.enter_aether) {
if (!player.inventory.addItemStackToInventory(new ItemStack(AetherItems.lore_book))) {
player.worldObj.spawnEntityInWorld(new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, new ItemStack(AetherItems.lore_book)));
}
if (!player.inventory.addItemStackToInventory(new ItemStack(AetherItems.golden_parachute))) {
player.worldObj.spawnEntityInWorld(new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, new ItemStack(AetherItems.golden_parachute)));
}
}
AetherNetwork.sendTo(new PacketAchievement(achievementType), (EntityPlayerMP) player);
}
}
}