Search in sources :

Example 11 with SyncMagicData

use of uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class MagicStop method process.

@Override
public void process(EntityPlayer player, Side side) {
    if (!player.getCapability(ModCapabilities.CHEAT_MODE, null).getCheatMode())
        player.getCapability(ModCapabilities.PLAYER_STATS, null).remMP(Constants.getCost(Strings.Spell_Aero));
    World world = player.world;
    if (!world.isRemote)
        switch(player.getCapability(ModCapabilities.MAGIC_STATE, null).getMagicLevel(Strings.Spell_Stop)) {
            case 1:
                world.spawnEntity(new EntityStop(world, player, player.posX, player.posY, player.posZ));
                PacketDispatcher.sendToAllAround(new SpawnStopParticles(player, 1), player, 64.0D);
                break;
            case 2:
                world.spawnEntity(new EntityStopra(world, player, player.posX, player.posY, player.posZ));
                PacketDispatcher.sendToAllAround(new SpawnStopParticles(player, 2), player, 64.0D);
                break;
            case 3:
                world.spawnEntity(new EntityStopga(world, player, player.posX, player.posY, player.posZ));
                PacketDispatcher.sendToAllAround(new SpawnStopParticles(player, 3), player, 64.0D);
                break;
        }
    PacketDispatcher.sendTo(new SyncMagicData(player.getCapability(ModCapabilities.MAGIC_STATE, null), player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) player);
}
Also used : SpawnStopParticles(uk.co.wehavecookies56.kk.common.network.packet.client.SpawnStopParticles) EntityStopra(uk.co.wehavecookies56.kk.common.entity.magic.EntityStopra) EntityStop(uk.co.wehavecookies56.kk.common.entity.magic.EntityStop) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData) World(net.minecraft.world.World) EntityStopga(uk.co.wehavecookies56.kk.common.entity.magic.EntityStopga)

Example 12 with SyncMagicData

use of uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class EntityEvents method onPlayerTick.

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
    EntityPlayer player = event.player;
    if (player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).getMember() == Utils.OrgMember.NONE) {
        if (!ItemStack.areItemStacksEqual(player.inventory.armorInventory.get(0), ItemStack.EMPTY) && player.inventory.armorInventory.get(1) != ItemStack.EMPTY && player.inventory.armorInventory.get(2) != ItemStack.EMPTY && player.inventory.armorInventory.get(3) != ItemStack.EMPTY) {
            boolean isWearingOrgArmor = player.inventory.armorInventory.get(0).getItem() instanceof ItemOrganizationRobe && player.inventory.armorInventory.get(1).getItem() instanceof ItemOrganizationRobe && player.inventory.armorInventory.get(2).getItem() instanceof ItemOrganizationRobe && player.inventory.armorInventory.get(3).getItem() instanceof ItemOrganizationRobe;
            // boolean isWearingXemnasArmor = player.inventory.armorInventory.get(0).getItem() == ModItems.Xemnas_Boots && player.inventory.armorInventory.get(1).getItem() == ModItems.Xemnas_Leggings && player.inventory.armorInventory.get(2).getItem() == ModItems.Xemnas_Chestplate && player.inventory.armorInventory.get(3).getItem() == ModItems.Xemnas_Helmet;
            if (isWearingOrgArmor) {
                if (!player.world.isRemote) {
                    if (!player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).getOpenedGUI()) {
                        player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).setOpenedGUI(true);
                        PacketDispatcher.sendTo(new OpenOrgGUI(), (EntityPlayerMP) player);
                    }
                }
            }
        } else {
            if (player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).getMember() == Utils.OrgMember.NONE)
                player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).setOpenedGUI(false);
        }
    }
    if (player.getCapability(ModCapabilities.Xemnas, null).getMember() == Utils.OrgMember.NONE) {
        if (!ItemStack.areItemStacksEqual(player.inventory.armorInventory.get(0), ItemStack.EMPTY) && player.inventory.armorInventory.get(1) != ItemStack.EMPTY && player.inventory.armorInventory.get(2) != ItemStack.EMPTY && player.inventory.armorInventory.get(3) != ItemStack.EMPTY) {
            boolean isWearingXemnasArmor = player.inventory.armorInventory.get(0).getItem() == ModItems.Xemnas_Boots && player.inventory.armorInventory.get(1).getItem() == ModItems.Xemnas_Leggings && player.inventory.armorInventory.get(2).getItem() == ModItems.Xemnas_Chestplate && player.inventory.armorInventory.get(3).getItem() == ModItems.Xemnas_Helmet;
            if (isWearingXemnasArmor) {
                if (!player.world.isRemote) {
                    if (!player.getCapability(ModCapabilities.Xemnas, null).getOpenedGUI()) {
                        player.getCapability(ModCapabilities.Xemnas, null).setOpenedGUI(true);
                        PacketDispatcher.sendTo(new OpenOrgGUI(), (EntityPlayerMP) player);
                    }
                }
            }
        } else {
            if (player.getCapability(ModCapabilities.Xemnas, null).getMember() == Utils.OrgMember.NONE)
                player.getCapability(ModCapabilities.Xemnas, null).setOpenedGUI(false);
        }
    }
    // Choices
    IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
    if (!event.player.world.isRemote) {
        if (player.dimension == ModDimensions.diveToTheHeartID) {
            if (player.getPosition().getX() == -13 && player.getPosition().getZ() == -1 && player.getPosition().getY() == 66) {
                if (!STATS.getChoice1().equals(Strings.Choice_Shield)) {
                    STATS.setChoice1(Strings.Choice_Shield);
                    TextComponentTranslation shield = new TextComponentTranslation("Shield");
                    shield.getStyle().setColor(TextFormatting.YELLOW);
                    player.sendMessage(shield);
                }
            } else if (player.getPosition().getX() == 11 && player.getPosition().getZ() == -1 && player.getPosition().getY() == 66) {
                if (!STATS.getChoice1().equals(Strings.Choice_Staff)) {
                    STATS.setChoice1(Strings.Choice_Staff);
                    TextComponentTranslation staff = new TextComponentTranslation("Staff");
                    staff.getStyle().setColor(TextFormatting.YELLOW);
                    player.sendMessage(staff);
                }
            } else if (player.getPosition().getX() == -1 && player.getPosition().getZ() == -13 && player.getPosition().getY() == 66) {
                if (!STATS.getChoice1().equals(Strings.Choice_Sword)) {
                    STATS.setChoice1(Strings.Choice_Sword);
                    TextComponentTranslation sword = new TextComponentTranslation("Sword");
                    sword.getStyle().setColor(TextFormatting.YELLOW);
                    player.sendMessage(sword);
                }
            } else if (player.getPosition().getX() == -1 && player.getPosition().getZ() == +10 && player.getPosition().getY() == 65) {
                if (((EntityPlayer) player).dimension == ModDimensions.diveToTheHeartID) {
                    if (!STATS.getChoice1().equals("") && !STATS.getChoice1().equals("door")) {
                        // if (!player.world.isRemote) {
                        switch(STATS.getChoice1()) {
                            case Strings.Choice_Shield:
                                STATS.addDefense(2);
                                break;
                            case Strings.Choice_Staff:
                                STATS.addMagic(2);
                                break;
                            case Strings.Choice_Sword:
                                STATS.addStrength(2);
                                break;
                        }
                        PacketDispatcher.sendTo(new SyncLevelData(STATS), (EntityPlayerMP) player);
                        new TeleporterOverworld(event.player.world.getMinecraftServer().getServer().getWorld(0)).teleport((player), player.world);
                    // }
                    } else {
                        if (!STATS.getChoice1().equals("door")) {
                            TextComponentTranslation needChoice = new TextComponentTranslation("You must make a choice");
                            needChoice.getStyle().setColor(TextFormatting.RED);
                            player.sendMessage(needChoice);
                            STATS.setChoice1("door");
                        }
                    }
                }
            }
        } else if (player.dimension == ModDimensions.traverseTownID) {
            if (player.getPosition().getX() == 193 && player.getPosition().getZ() == 161 && player.getPosition().getY() == 6) {
                new TeleporterOverworld(event.player.world.getMinecraftServer().getServer().getWorld(0)).teleport((player), player.world);
            }
        }
    }
    DriveStateCapability.IDriveState DS = event.player.getCapability(ModCapabilities.DRIVE_STATE, null);
    if (!DS.getInDrive())
        if (STATS.getMP() <= 0 || STATS.getRecharge()) {
            STATS.setRecharge(true);
            if (STATS.getMP() != STATS.getMaxMP()) {
                STATS.addMP(0.1);
                if (STATS.getMP() > STATS.getMaxMP())
                    STATS.setMP(STATS.getMaxMP());
            } else {
                STATS.setMP(STATS.getMaxMP());
                STATS.setRecharge(false);
                if (event.side.isServer()) {
                    PacketDispatcher.sendTo(new SyncMagicData(event.player.getCapability(ModCapabilities.MAGIC_STATE, null), event.player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) event.player);
                }
            }
        }
    if (!DS.getActiveDriveName().equals("none") && DriveFormRegistry.isDriveFormRegistered(DS.getActiveDriveName())) {
        DriveFormRegistry.get(DS.getActiveDriveName()).update(event.player);
    }
    List<Entity> entities = event.player.world.getEntitiesWithinAABBExcludingEntity(event.player, event.player.getEntityBoundingBox().grow(16.0D, 10.0D, 16.0D).offset(-8.0D, -5.0D, -8.0D));
    List<Entity> bossEntities = event.player.world.getEntitiesWithinAABBExcludingEntity(event.player, event.player.getEntityBoundingBox().grow(150.0D, 100.0D, 150.0D).offset(-75.0D, -50.0D, -75.0D));
    if (!bossEntities.isEmpty()) {
        for (int i = 0; i < bossEntities.size(); i++) {
            if (bossEntities.get(i) instanceof EntityDragon || bossEntities.get(i) instanceof EntityWither) {
                isBoss = true;
                break;
            } else {
                isBoss = false;
            }
        }
    } else {
        isBoss = false;
    }
    if (!entities.isEmpty()) {
        for (int i = 0; i < entities.size(); i++) {
            if (entities.get(i) instanceof EntityMob) {
                isHostiles = true;
                break;
            } else {
                isHostiles = false;
            }
        }
    } else {
        isHostiles = false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityDragon(net.minecraft.entity.boss.EntityDragon) OpenOrgGUI(uk.co.wehavecookies56.kk.common.network.packet.client.OpenOrgGUI) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TeleporterOverworld(uk.co.wehavecookies56.kk.common.world.dimension.TeleporterOverworld) SyncLevelData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData) IPlayerStats(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats) EntityMob(net.minecraft.entity.monster.EntityMob) DriveStateCapability(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemOrganizationRobe(uk.co.wehavecookies56.kk.common.item.ItemOrganizationRobe) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData) EntityWither(net.minecraft.entity.boss.EntityWither) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with SyncMagicData

use of uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class EntityEvents method OnEntityJoinWorld.

@SubscribeEvent
public void OnEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer) {
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.DriveRecovery.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.HighDriveRecovery.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.MagicBoost.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.PowerBoost.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.DefenseBoost.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.Elixir.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.Megalixir.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.Ether.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.MegaEther.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.Potion.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.HiPotion.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.MegaPotion.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), ModItems.Panacaea.getUnlocalizedName());
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_MythrilShard);
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_MythrilStone);
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_MythrilGem);
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_MythrilCrystal);
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_ManifestIllusion);
        FreeDevRecipeRegistry.learnFreeDevRecipe(event.getEntity().getCapability(ModCapabilities.SYNTHESIS_RECIPES, null).getFreeDevRecipes(), (EntityPlayer) event.getEntity(), Strings.SM_LostIllusion);
        if (event.getEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null).getInventoryKeychain().getSlots() != InventoryKeychain.INV_SIZE) {
            ItemStackHandler oldInv = event.getEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null).getInventoryKeychain();
            event.getEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null).setInventory(new ItemStackHandler(InventoryKeychain.INV_SIZE));
            ItemStackHandler newInv = event.getEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null).getInventoryKeychain();
            for (int i = 0; i < oldInv.getSlots(); i++) {
                newInv.setStackInSlot(i, oldInv.getStackInSlot(i));
            }
        }
        PacketDispatcher.sendTo(new SyncHudData(event.getEntity().getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncMagicInventory(event.getEntity().getCapability(ModCapabilities.MAGIC_STATE, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncItemsInventory(event.getEntity().getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncDriveInventory(event.getEntity().getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncDriveData(event.getEntity().getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncMagicData(event.getEntity().getCapability(ModCapabilities.MAGIC_STATE, null), event.getEntity().getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncKeybladeData(event.getEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncLevelData(event.getEntity().getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) event.getEntity());
        PacketDispatcher.sendTo(new SyncOrgXIIIData(event.getEntity().getCapability(ModCapabilities.ORGANIZATION_XIII, null)), (EntityPlayerMP) event.getEntity());
        FirstTimeJoinCapability.IFirstTimeJoin FTJ = event.getEntity().getCapability(ModCapabilities.FIRST_TIME_JOIN, null);
        if (!FTJ.getFirstTimeJoin()) {
            ((EntityPlayer) event.getEntity()).inventory.addItemStackToInventory(new ItemStack(ModItems.WoodenKeyblade));
            FTJ.setFirstTimeJoin(true);
            FTJ.setPosX(((EntityPlayer) event.getEntity()).getPosition().getX());
            FTJ.setPosY(((EntityPlayer) event.getEntity()).getPosition().getY());
            FTJ.setPosZ(((EntityPlayer) event.getEntity()).getPosition().getZ());
            if (((EntityPlayer) event.getEntity()).dimension != ModDimensions.diveToTheHeartID && MainConfig.worldgen.EnableStationOfAwakening)
                if (!event.getWorld().isRemote)
                    new TeleporterDiveToTheHeart(event.getWorld().getMinecraftServer().getServer().getWorld(ModDimensions.diveToTheHeartID)).teleport(((EntityPlayer) event.getEntity()));
        }
        ((EntityPlayer) event.getEntity()).getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(event.getEntity().getCapability(ModCapabilities.PLAYER_STATS, null).getHP());
        if (((EntityPlayer) event.getEntity()).getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() < 3) {
            ((EntityPlayer) event.getEntity()).getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(3);
        }
        try {
            if (event.getEntity() instanceof EntityPlayerMP) {
                EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
                GameProfile profileWehavecookies56 = player.mcServer.getPlayerProfileCache().getGameProfileForUsername("Wehavecookies56");
                UUID uuidWehavecookies56 = profileWehavecookies56.getId();
                final MunnyCapability.IMunny munny = ((EntityPlayer) event.getEntity()).getCapability(ModCapabilities.MUNNY, null);
                if (event.getEntity().getUniqueID() == uuidWehavecookies56) {
                    munny.setMunny(munny.getMunny() + 10000);
                }
                GameProfile profileAbelatox = player.mcServer.getPlayerProfileCache().getGameProfileForUsername("Abelatox");
                UUID uuidAbelatox = profileAbelatox.getId();
                if (event.getEntity().getUniqueID() == uuidAbelatox) {
                    munny.setMunny(munny.getMunny() + 10000);
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) SyncMagicInventory(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicInventory) SyncLevelData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData) SyncItemsInventory(uk.co.wehavecookies56.kk.common.network.packet.client.SyncItemsInventory) SyncHudData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncHudData) SyncKeybladeData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncKeybladeData) SyncOrgXIIIData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncOrgXIIIData) SyncDriveInventory(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveInventory) FirstTimeJoinCapability(uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability) SyncDriveData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData) GameProfile(com.mojang.authlib.GameProfile) TeleporterDiveToTheHeart(uk.co.wehavecookies56.kk.common.world.dimension.TeleporterDiveToTheHeart) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData) MunnyCapability(uk.co.wehavecookies56.kk.common.capability.MunnyCapability) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 14 with SyncMagicData

use of uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class ItemEvents method onEntityItemPickUp.

@SubscribeEvent
public void onEntityItemPickUp(EntityItemPickupEvent event) {
    IPlayerStats STATS = event.getEntityPlayer().getCapability(ModCapabilities.PLAYER_STATS, null);
    IDriveState DRIVE = event.getEntityPlayer().getCapability(ModCapabilities.DRIVE_STATE, null);
    if (event.getItem().getItem().getItem() instanceof ItemMunny) {
        final MunnyCapability.IMunny munny = event.getEntityPlayer().getCapability(ModCapabilities.MUNNY, null);
        MunnyPickup packet = new MunnyPickup(event.getItem().getItem());
        event.getItem().getItem().setCount(event.getItem().getItem().getCount() - 1);
        ;
        munny.addMunny(event.getItem().getItem().getTagCompound().getInteger("amount"));
        PacketDispatcher.sendTo(new SyncMunnyData(munny), (EntityPlayerMP) event.getEntityPlayer());
        PacketDispatcher.sendTo(new ShowOverlayPacket("munny", event.getItem().getItem().getTagCompound().getInteger("amount")), (EntityPlayerMP) event.getEntityPlayer());
    } else if (event.getItem().getItem().getItem() instanceof ItemHpOrb) {
        if (!ItemStack.areItemStacksEqual(event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND), ItemStack.EMPTY))
            if (event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.EmptyBottle)
                return;
        HpOrbPickup packet = new HpOrbPickup(event.getItem().getItem());
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
            if (event.getEntityPlayer().getHealth() >= event.getEntityPlayer().getMaxHealth()) {
                event.getItem().getItem().setCount(event.getItem().getItem().getCount() - 1);
                ;
                return;
            }
            if (event.getEntityPlayer().getHealth() < event.getEntityPlayer().getMaxHealth() - 1)
                event.getEntityPlayer().heal(2);
            else
                event.getEntityPlayer().heal(1);
            event.getItem().getItem().setCount(event.getItem().getItem().getCount() - 1);
            ;
        }
    } else if (event.getItem().getItem().getItem() == ModItems.DriveOrb) {
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
            event.getItem().getItem().setCount(event.getItem().getItem().getCount() - 1);
            ;
            DRIVE.addDP(event.getItem().getItem().getTagCompound().getInteger("amount"));
            EntityPlayer player = event.getEntityPlayer();
            PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
            PacketDispatcher.sendTo(new SyncDriveInventory(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) event.getEntityPlayer());
        }
    } else if (event.getItem().getItem().getItem() == ModItems.MagicOrb) {
        double mp = STATS.getMP();
        if (!ItemStack.areItemStacksEqual(event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND), ItemStack.EMPTY))
            if (event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.EmptyBottle)
                return;
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
            event.getItem().getItem().setCount(event.getItem().getItem().getCount() - 1);
            ;
            STATS.addMP(event.getItem().getItem().getTagCompound().getInteger("amount"));
            PacketDispatcher.sendTo(new SyncMagicData(event.getEntityPlayer().getCapability(ModCapabilities.MAGIC_STATE, null), STATS), (EntityPlayerMP) event.getEntityPlayer());
        }
    } else if (event.getItem().getItem().getItem() instanceof ItemSynthesisMaterial) {
        for (int i = 0; i < event.getEntityPlayer().inventory.getSizeInventory(); i++) {
            if (!ItemStack.areItemStacksEqual(event.getEntityPlayer().inventory.getStackInSlot(i), ItemStack.EMPTY)) {
                if (event.getEntityPlayer().inventory.getStackInSlot(i).getItem() == ModItems.SynthesisBagL) {
                    IItemHandler inv = event.getEntityPlayer().inventory.getStackInSlot(i).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
                    addSynthesisMaterialToBag(inv, event);
                } else if (event.getEntityPlayer().inventory.getStackInSlot(i).getItem() == ModItems.SynthesisBagM) {
                    IItemHandler inv = event.getEntityPlayer().inventory.getStackInSlot(i).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
                    addSynthesisMaterialToBag(inv, event);
                }
                if (event.getEntityPlayer().inventory.getStackInSlot(i).getItem() == ModItems.SynthesisBagS) {
                    IItemHandler inv = event.getEntityPlayer().inventory.getStackInSlot(i).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
                    addSynthesisMaterialToBag(inv, event);
                }
            }
        }
    }
}
Also used : MunnyPickup(uk.co.wehavecookies56.kk.common.network.packet.server.MunnyPickup) IItemHandler(net.minecraftforge.items.IItemHandler) ItemSynthesisMaterial(uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial) ShowOverlayPacket(uk.co.wehavecookies56.kk.common.network.packet.client.ShowOverlayPacket) HpOrbPickup(uk.co.wehavecookies56.kk.common.network.packet.server.HpOrbPickup) IPlayerStats(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats) SyncMunnyData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMunnyData) ItemHpOrb(uk.co.wehavecookies56.kk.common.item.ItemHpOrb) ItemMunny(uk.co.wehavecookies56.kk.common.item.ItemMunny) SyncDriveInventory(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveInventory) SyncDriveData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MunnyCapability(uk.co.wehavecookies56.kk.common.capability.MunnyCapability) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData) IDriveState(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability.IDriveState) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SyncMagicData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData)14 World (net.minecraft.world.World)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 IPlayerStats (uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats)3 SyncDriveData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData)3 SyncLevelData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData)3 Entity (net.minecraft.entity.Entity)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 MunnyCapability (uk.co.wehavecookies56.kk.common.capability.MunnyCapability)2 SyncDriveInventory (uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveInventory)2 SyncMagicInventory (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicInventory)2 GameProfile (com.mojang.authlib.GameProfile)1 List (java.util.List)1 UUID (java.util.UUID)1 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityWither (net.minecraft.entity.boss.EntityWither)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 ItemStack (net.minecraft.item.ItemStack)1