Search in sources :

Example 1 with SummonKeyblade

use of uk.co.wehavecookies56.kk.common.network.packet.server.SummonKeyblade 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

ItemStack (net.minecraft.item.ItemStack)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 OrganizationXIIICapability (uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability)1 SummonKeybladeCapability (uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability)1 ItemKeyblade (uk.co.wehavecookies56.kk.common.item.base.ItemKeyblade)1 ItemKeychain (uk.co.wehavecookies56.kk.common.item.base.ItemKeychain)1 ItemRealKeyblade (uk.co.wehavecookies56.kk.common.item.base.ItemRealKeyblade)1 IOrgWeapon (uk.co.wehavecookies56.kk.common.item.org.IOrgWeapon)1 DeSummonKeyblade (uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade)1 DeSummonOrgWeapon (uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon)1 SummonKeyblade (uk.co.wehavecookies56.kk.common.network.packet.server.SummonKeyblade)1 SummonOrgWeapon (uk.co.wehavecookies56.kk.common.network.packet.server.SummonOrgWeapon)1