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());
}
}
}
}
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());
}
}
}
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;
}
}
}
}
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;
}
}
}
Aggregations