Search in sources :

Example 1 with DeSummonKeyblade

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

the class CommandOpenKeyInv method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
        if (args.length > 1) {
            TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
        } else {
            EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
            if (args.length == 1) {
                if (getPlayerFromUsername(args[0]) != null) {
                    player = getPlayerFromUsername(args[0]);
                }
            }
            ISummonKeyblade KEYBLADE = player.getCapability(ModCapabilities.SUMMON_KEYBLADE, null);
            GuiHelper.openInv(GuiIDs.GUI_KEYCHAIN_INV);
        /*  if (!ItemStack.areItemStacksEqual(KEYBLADE.getInventoryKeychain().getStackInSlot(slot), ItemStack.EMPTY)) {
                    PacketDispatcher.sendToServer(new RemoveItemInSlot("keychain", slot));
                    PacketDispatcher.sendToAllAround(new RemoveItemInSlot("keychain", slot), (EntityPlayer) sender.getCommandSenderEntity(), 1);

                    if (sender.getCommandSenderEntity().getCapability(ModCapabilities.SUMMON_KEYBLADE, null).getIsKeybladeSummoned(EnumHand.MAIN_HAND))
                        if (!ItemStack.areItemStacksEqual(player.getHeldItem(EnumHand.MAIN_HAND), ItemStack.EMPTY) && player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemKeyblade)
                            //player.getCapability(ModCapabilities.SUMMON_KEYBLADE, null).setIsKeybladeSummoned(EnumHand.MAIN_HAND, true);
                        PacketDispatcher.sendToServer(new DeSummonKeyblade());
                    	if(args.length == 2)
                    		TextHelper.sendFormattedChatMessage(args[1] + "'s keychain has been removed!", TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
                    	else
                    		TextHelper.sendFormattedChatMessage("Your keychain has been removed!", TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
                } else
                    TextHelper.sendFormattedChatMessage("The chain slot has no chain!", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                */
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ISummonKeyblade(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability.ISummonKeyblade)

Example 2 with DeSummonKeyblade

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

the class EntityEvents method onLivingDeathEvent.

@SubscribeEvent
public void onLivingDeathEvent(LivingDeathEvent event) {
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntity();
        SummonKeybladeCapability.ISummonKeyblade SUMMON = player.getCapability(ModCapabilities.SUMMON_KEYBLADE, null);
        IOrganizationXIII ORG = player.getCapability(ModCapabilities.ORGANIZATION_XIII, null);
        if (SUMMON.getIsKeybladeSummoned(EnumHand.MAIN_HAND)) {
            if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
                PacketDispatcher.sendToServer(new DeSummonKeyblade());
                PacketDispatcher.sendTo(new SyncKeybladeData(SUMMON), (EntityPlayerMP) player);
            } else {
                SUMMON.setIsKeybladeSummoned(EnumHand.MAIN_HAND, false);
                if (event.getEntity().world.getGameRules().getBoolean("keepInventory")) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (!ItemStack.areItemStacksEqual(player.inventory.getStackInSlot(i), ItemStack.EMPTY)) {
                            if (player.inventory.getStackInSlot(i).getItem() instanceof ItemRealKeyblade) {
                                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                            }
                        }
                    }
                }
            }
        } else if (ORG.summonedWeapon(EnumHand.MAIN_HAND)) {
            if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
                PacketDispatcher.sendToServer(new DeSummonOrgWeapon());
                PacketDispatcher.sendTo(new SyncOrgXIIIData(ORG), (EntityPlayerMP) player);
            } else {
                SUMMON.setIsKeybladeSummoned(EnumHand.MAIN_HAND, false);
                if (event.getEntity().world.getGameRules().getBoolean("keepInventory")) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (!ItemStack.areItemStacksEqual(player.inventory.getStackInSlot(i), ItemStack.EMPTY)) {
                            if (player.inventory.getStackInSlot(i).getItem() instanceof IOrgWeapon) {
                                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                            }
                        }
                    }
                }
            }
        }
    }
    if (event.getEntity() instanceof EntityDragon) {
        WorldSavedDataKingdomKeys.get(DimensionManager.getWorld(DimensionType.OVERWORLD.getId())).setSpawnHeartless(true);
    }
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityMob)
        if (event.getSource().getTrueSource() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
            EntityMob mob = (EntityMob) event.getEntity();
            player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, (int) (mob.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getAttributeValue() / 2));
            if (!player.getCapability(ModCapabilities.PLAYER_STATS, null).enderDragonDefeated()) {
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() + 1);
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
                PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
                TextComponentTranslation driMessage = new TextComponentTranslation(Strings.Chat_DriveBoost, new TextComponentTranslation("" + player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel()));
                driMessage.getStyle().setColor(TextFormatting.GREEN);
                player.sendMessage(driMessage);
                player.getCapability(ModCapabilities.PLAYER_STATS, null).setEnderDragonDefeated(true);
            }
            if (event.getEntity() instanceof EntityDragon) {
                player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, 2000);
            }
            if (event.getEntity() instanceof EntityWither) {
                player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, 1500);
            }
            PacketDispatcher.sendTo(new SyncLevelData(player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) player);
        }
}
Also used : EntityDragon(net.minecraft.entity.boss.EntityDragon) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) SyncLevelData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData) DeSummonKeyblade(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade) SyncKeybladeData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncKeybladeData) ItemRealKeyblade(uk.co.wehavecookies56.kk.common.item.base.ItemRealKeyblade) SyncOrgXIIIData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncOrgXIIIData) EntityMob(net.minecraft.entity.monster.EntityMob) SummonKeybladeCapability(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability) SyncDriveData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData) DeSummonOrgWeapon(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityWither(net.minecraft.entity.boss.EntityWither) IOrgWeapon(uk.co.wehavecookies56.kk.common.item.org.IOrgWeapon) IOrganizationXIII(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with DeSummonKeyblade

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

the class Utils method summonWeapon.

/**
 * Summon a weapon in a player's hand
 * @param player
 * @param hand
 * @param keychainSlot
 * @return
 */
public static boolean summonWeapon(EntityPlayer player, EnumHand hand, int keychainSlot) {
    SummonKeybladeCapability.ISummonKeyblade summonCap = player.getCapability(ModCapabilities.SUMMON_KEYBLADE, null);
    OrganizationXIIICapability.IOrganizationXIII organizationXIIICap = player.getCapability(ModCapabilities.ORGANIZATION_XIII, null);
    if (organizationXIIICap.getMember() == Utils.OrgMember.NONE) {
        if (ItemStack.areItemStacksEqual(summonCap.getInventoryKeychain().getStackInSlot(keychainSlot), ItemStack.EMPTY)) {
            player.sendMessage(new TextComponentTranslation(TextFormatting.RED + "Missing keychain to summon"));
            return false;
        }
        if (!summonCap.getIsKeybladeSummoned(hand) && ItemStack.areItemStacksEqual(player.getHeldItem(hand), ItemStack.EMPTY) && summonCap.getInventoryKeychain().getStackInSlot(0).getItem() instanceof ItemKeychain) {
            summonCap.setActiveSlot(player.inventory.currentItem);
            ItemStack keychain = summonCap.getInventoryKeychain().getStackInSlot(keychainSlot);
            ItemStack keyblade = new ItemStack(((ItemKeychain) (keychain.getItem())).getKeyblade());
            if (hand == EnumHand.MAIN_HAND) {
                player.inventory.setInventorySlotContents(player.inventory.currentItem, keyblade);
            } else {
                player.inventory.offHandInventory.set(0, keyblade);
            }
            if (player.world.isRemote)
                PacketDispatcher.sendToServer(new SummonKeyblade(hand, keychainSlot));
            return true;
        } else if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), ItemStack.EMPTY) && player.getHeldItem(hand).getItem() instanceof ItemRealKeyblade && summonCap.getIsKeybladeSummoned(hand)) {
            if (player.world.isRemote)
                PacketDispatcher.sendToServer(new DeSummonKeyblade(hand));
            player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
            player.inventory.offHandInventory.set(0, ItemStack.EMPTY);
            return true;
        } else {
            return false;
        }
    } else {
        if (!organizationXIIICap.summonedWeapon(hand) && ItemStack.areItemStacksEqual(player.getHeldItem(hand), ItemStack.EMPTY)) {
            if (player.world.isRemote)
                PacketDispatcher.sendToServer(new SummonOrgWeapon(hand, organizationXIIICap.currentWeapon()));
            if (hand == EnumHand.MAIN_HAND)
                player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(organizationXIIICap.currentWeapon()));
            else
                player.inventory.offHandInventory.set(0, new ItemStack(organizationXIIICap.currentWeapon()));
            organizationXIIICap.setWeaponSummoned(hand, true);
            return true;
        } else if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), ItemStack.EMPTY) && player.getHeldItem(hand).getItem() instanceof IOrgWeapon || (organizationXIIICap.getMember() == Utils.OrgMember.ROXAS && !ItemStack.areItemStacksEqual(player.getHeldItem(hand), ItemStack.EMPTY) && player.getHeldItem(hand).getItem() instanceof ItemKeyblade)) {
            if (player.world.isRemote) {
                PacketDispatcher.sendToServer(new DeSummonOrgWeapon(hand));
            }
            organizationXIIICap.setWeaponSummoned(hand, false);
            if (hand == EnumHand.MAIN_HAND)
                player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
            else
                player.inventory.offHandInventory.set(0, ItemStack.EMPTY);
            return true;
        } else {
            return false;
        }
    }
}
Also used : DeSummonOrgWeapon(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon) SummonOrgWeapon(uk.co.wehavecookies56.kk.common.network.packet.server.SummonOrgWeapon) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ItemKeychain(uk.co.wehavecookies56.kk.common.item.base.ItemKeychain) DeSummonKeyblade(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade) ItemRealKeyblade(uk.co.wehavecookies56.kk.common.item.base.ItemRealKeyblade) ItemKeyblade(uk.co.wehavecookies56.kk.common.item.base.ItemKeyblade) SummonKeybladeCapability(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability) DeSummonOrgWeapon(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon) SummonKeyblade(uk.co.wehavecookies56.kk.common.network.packet.server.SummonKeyblade) DeSummonKeyblade(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade) ItemStack(net.minecraft.item.ItemStack) IOrgWeapon(uk.co.wehavecookies56.kk.common.item.org.IOrgWeapon) OrganizationXIIICapability(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 SummonKeybladeCapability (uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability)2 ItemRealKeyblade (uk.co.wehavecookies56.kk.common.item.base.ItemRealKeyblade)2 IOrgWeapon (uk.co.wehavecookies56.kk.common.item.org.IOrgWeapon)2 DeSummonKeyblade (uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade)2 DeSummonOrgWeapon (uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon)2 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityWither (net.minecraft.entity.boss.EntityWither)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 OrganizationXIIICapability (uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability)1 IOrganizationXIII (uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII)1 ISummonKeyblade (uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability.ISummonKeyblade)1 ItemKeyblade (uk.co.wehavecookies56.kk.common.item.base.ItemKeyblade)1 ItemKeychain (uk.co.wehavecookies56.kk.common.item.base.ItemKeychain)1 SyncDriveData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData)1 SyncKeybladeData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncKeybladeData)1