Search in sources :

Example 1 with TilePearlHolder

use of com.teamwizardry.wizardry.common.tile.TilePearlHolder in project Wizardry by TeamWizardry.

the class BlockPearlHolder method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = playerIn.getHeldItem(hand);
    if (!worldIn.isRemote) {
        TilePearlHolder te = getTE(worldIn, pos);
        if (!te.containsSomething()) {
            if (heldItem.getItem() == ModItems.ORB || heldItem.getItem() == ModItems.PEARL_NACRE) {
                te.setItemStack(heldItem.copy());
                te.getItemStack().setCount(1);
                heldItem.shrink(1);
            } else
                return false;
        } else {
            ItemStack stack = te.getItemStack().copy();
            CapManager manager1 = new CapManager(stack).setEntity(playerIn);
            manager1.sync();
            te.setItemStack(ItemStack.EMPTY);
            if (playerIn.inventory.addItemStackToInventory(stack))
                playerIn.openContainer.detectAndSendChanges();
            else {
                EntityItem entityItem = new EntityItem(worldIn, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
                worldIn.spawnEntity(entityItem);
            }
        }
        te.markDirty();
    }
    return true;
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) TilePearlHolder(com.teamwizardry.wizardry.common.tile.TilePearlHolder) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with TilePearlHolder

use of com.teamwizardry.wizardry.common.tile.TilePearlHolder in project Wizardry by TeamWizardry.

the class BlockPearlHolder method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TilePearlHolder holder = getTE(worldIn, pos);
    if (holder == null) {
        super.breakBlock(worldIn, pos, state);
        return;
    }
    ItemStack itemStack = holder.getItemStack();
    if (itemStack != null && !itemStack.isEmpty()) {
        InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), itemStack);
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TilePearlHolder(com.teamwizardry.wizardry.common.tile.TilePearlHolder) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TilePearlHolder (com.teamwizardry.wizardry.common.tile.TilePearlHolder)2 ItemStack (net.minecraft.item.ItemStack)2 CapManager (com.teamwizardry.wizardry.api.capability.CapManager)1 EntityItem (net.minecraft.entity.item.EntityItem)1