Search in sources :

Example 1 with ItemSynthesisMaterial

use of uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class OpenMaterials method process.

@Override
public void process(EntityPlayer player, Side side) {
    for (int i = 0; i < 36; i++) {
        if (!ItemStack.areItemStacksEqual(player.inventory.mainInventory.get(i), ItemStack.EMPTY)) {
            if (player.inventory.mainInventory.get(i).getItem() instanceof ItemSynthesisMaterial) {
                if (player.inventory.mainInventory.get(i).hasTagCompound()) {
                    String s = player.inventory.mainInventory.get(i).getTagCompound().getString("material");
                    if (MaterialRegistry.isMaterialRegistered(s)) {
                        player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(s), player.inventory.mainInventory.get(i).getCount());
                    }
                    player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                }
            } else if (MaterialRegistry.isMaterialRegistered(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName().toString())) {
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName()), player.inventory.mainInventory.get(i).getCount());
                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
            }
            PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
        }
    }
/*for (int i = 0; i < 36; i++)
            if (player.inventory.mainInventory[i] != null) if (player.inventory.mainInventory[i].getItem() instanceof ItemSynthesisMaterial) {
                if (player.inventory.mainInventory[i].hasTagCompound()) {
                    String s = player.inventory.mainInventory[i].getTagCompound().getString("material");
                    if (MaterialRegistry.isMaterialRegistered(s)) player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(s), player.inventory.mainInventory[i].stackSize);
                    player.inventory.setInventorySlotContents(i, null);
                }

            } else if (MaterialRegistry.isMaterialRegistered(player.inventory.mainInventory[i].getItem().getUnlocalizedName().toString())) {
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(player.inventory.mainInventory[i].getItem().getUnlocalizedName()), player.inventory.mainInventory[i].stackSize);
                player.inventory.setInventorySlotContents(i, null);
            }
        PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
        */
}
Also used : ItemSynthesisMaterial(uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial) SyncMaterialData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)

Example 2 with ItemSynthesisMaterial

use of uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class TakeSoldItem method process.

@Override
public void process(EntityPlayer player, Side side) {
    int quantityRemaining = quantity;
    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
        if (player.inventory.getStackInSlot(i).getItem() instanceof ItemSynthesisMaterial) {
            ItemStack invItem = player.inventory.getStackInSlot(i);
            if (invItem.getTagCompound().getString("material").equals(soldItem.getTagCompound().getString("material"))) {
                // System.out.println(invItem.getTagCompound().getString("material")+">"+soldItem.getTagCompound().getString("material"));
                if (quantityRemaining >= player.inventory.getStackInSlot(i).getCount()) {
                    // If the amount you want to sell is bigger or equals to the amount you have
                    // Remove the item
                    player.inventory.removeStackFromSlot(i);
                    quantityRemaining -= player.inventory.getStackInSlot(i).getCount();
                } else if (quantityRemaining < player.inventory.getStackInSlot(i).getCount()) {
                    player.inventory.getStackInSlot(i).shrink(quantityRemaining);
                    quantityRemaining = 0;
                }
            }
        }
    }
    player.getCapability(ModCapabilities.MUNNY, null).addMunny(munnyToGive);
    PacketDispatcher.sendTo(new SyncMunnyData(player.getCapability(ModCapabilities.MUNNY, null)), (EntityPlayerMP) player);
}
Also used : ItemSynthesisMaterial(uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial) SyncMunnyData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMunnyData) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemSynthesisMaterial

use of uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial 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

ItemSynthesisMaterial (uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial)3 SyncMunnyData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMunnyData)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 IDriveState (uk.co.wehavecookies56.kk.common.capability.DriveStateCapability.IDriveState)1 MunnyCapability (uk.co.wehavecookies56.kk.common.capability.MunnyCapability)1 IPlayerStats (uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats)1 ItemHpOrb (uk.co.wehavecookies56.kk.common.item.ItemHpOrb)1 ItemMunny (uk.co.wehavecookies56.kk.common.item.ItemMunny)1 ShowOverlayPacket (uk.co.wehavecookies56.kk.common.network.packet.client.ShowOverlayPacket)1 SyncDriveData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData)1 SyncDriveInventory (uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveInventory)1 SyncMagicData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData)1 SyncMaterialData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)1 HpOrbPickup (uk.co.wehavecookies56.kk.common.network.packet.server.HpOrbPickup)1 MunnyPickup (uk.co.wehavecookies56.kk.common.network.packet.server.MunnyPickup)1