Search in sources :

Example 1 with ISoulbound

use of convenientadditions.api.item.ISoulbound in project ConvenientAdditions by Necr0.

the class EventHandlerSoulbound method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone e) {
    if (e.getEntityPlayer().getEntityWorld().isRemote || e.getEntityPlayer().getEntityWorld().getGameRules().getBoolean("keepInventory"))
        return;
    EntityPlayer original = e.getOriginal();
    EntityPlayer clone = e.getEntityPlayer();
    IItemHandler h = original.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
    for (int slot = 0; slot < h.getSlots(); slot++) {
        ItemStack stack = h.getStackInSlot(slot);
        if (stack != null && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, original)) {
            IItemHandler h2 = clone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            ItemStack out = tryInsert(stack, h2);
            if (out == null) {
                h.extractItem(slot, 64, false);
            } else {
                stack.setCount(out.getCount());
            }
        }
    }
}
Also used : ISoulbound(convenientadditions.api.item.ISoulbound) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ISoulbound

use of convenientadditions.api.item.ISoulbound in project ConvenientAdditions by Necr0.

the class EventHandlerSoulbound method onPlayerDrops.

@SubscribeEvent
public void onPlayerDrops(PlayerDropsEvent e) {
    if (e.getEntityPlayer().getEntityWorld().isRemote || e.getEntityPlayer().getEntityWorld().getGameRules().getBoolean("keepInventory"))
        return;
    Iterator<EntityItem> i = e.getDrops().iterator();
    while (i.hasNext()) {
        EntityItem ent = i.next();
        ItemStack stack = ent.getEntityItem();
        if (!stack.isEmpty() && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, e.getEntityPlayer())) {
            IItemHandler h = e.getEntityPlayer().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            ItemStack out = tryInsert(stack, h);
            if (out == null)
                i.remove();
            else
                stack.setCount(out.getCount());
        }
    }
}
Also used : ISoulbound(convenientadditions.api.item.ISoulbound) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with ISoulbound

use of convenientadditions.api.item.ISoulbound in project ConvenientAdditions by Necr0.

the class EventHandlerSoulbound method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone e) {
    EntityPlayer original = e.getOriginal();
    EntityPlayer clone = e.getEntityPlayer();
    IItemHandler h = original.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
    for (int slot = 0; slot < h.getSlots(); slot++) {
        ItemStack stack = h.getStackInSlot(slot);
        if (stack != null && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, original)) {
            IItemHandler h2 = clone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            ItemStack out = tryInsert(stack, h2);
            if (out == null) {
                h.extractItem(slot, 64, false);
            } else {
                stack.stackSize = out.stackSize;
            }
        }
    }
}
Also used : ISoulbound(convenientadditions.api.item.ISoulbound) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with ISoulbound

use of convenientadditions.api.item.ISoulbound in project ConvenientAdditions by Necr0.

the class EventHandlerSoulbound method onPlayerDrops.

@SubscribeEvent
public void onPlayerDrops(PlayerDropsEvent e) {
    Iterator<EntityItem> i = e.getDrops().iterator();
    while (i.hasNext()) {
        EntityItem ent = i.next();
        ItemStack stack = ent.getEntityItem();
        if (stack != null && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, e.getEntityPlayer())) {
            IItemHandler h = e.getEntityPlayer().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            ItemStack out = tryInsert(stack, h);
            if (out == null)
                i.remove();
            else
                stack.stackSize = out.stackSize;
        }
    }
}
Also used : ISoulbound(convenientadditions.api.item.ISoulbound) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ISoulbound (convenientadditions.api.item.ISoulbound)4 ItemStack (net.minecraft.item.ItemStack)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 IItemHandler (net.minecraftforge.items.IItemHandler)4 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2