Search in sources :

Example 1 with TileEntitySecurityCamera

use of net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera in project SecurityCraft by Geforce132.

the class SCEventHandler method onBlockBroken.

@SubscribeEvent
public void onBlockBroken(BreakEvent event) {
    if (!event.world.isRemote)
        if (event.world.getTileEntity(event.pos) != null && event.world.getTileEntity(event.pos) instanceof CustomizableSCTE) {
            CustomizableSCTE te = (CustomizableSCTE) event.world.getTileEntity(event.pos);
            for (int i = 0; i < te.getNumberOfCustomizableOptions(); i++) if (te.itemStacks[i] != null) {
                ItemStack stack = te.itemStacks[i];
                EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), stack);
                event.world.spawnEntityInWorld(item);
                te.onModuleRemoved(stack, ((ItemModule) stack.getItem()).getModule());
                te.createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { stack, ((ItemModule) stack.getItem()).getModule() }, te);
                if (te instanceof TileEntitySecurityCamera)
                    te.getWorld().notifyNeighborsOfStateChange(te.getPos().offset((EnumFacing) te.getWorld().getBlockState(te.getPos()).getValue(BlockSecurityCamera.FACING), -1), te.getWorld().getBlockState(te.getPos()).getBlock());
            }
        }
}
Also used : CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with TileEntitySecurityCamera

use of net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera in project SecurityCraft by Geforce132.

the class CustomizableSCTE method decrStackSize.

@Override
public ItemStack decrStackSize(int par1, int par2) {
    if (itemStacks[par1] != null) {
        ItemStack itemstack;
        if (itemStacks[par1].stackSize <= par2) {
            itemstack = itemStacks[par1];
            itemStacks[par1] = null;
            onModuleRemoved(itemstack, ((ItemModule) itemstack.getItem()).getModule());
            createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { itemstack, ((ItemModule) itemstack.getItem()).getModule() }, this);
            if (this instanceof TileEntitySecurityCamera)
                getWorld().notifyNeighborsOfStateChange(pos.offset((EnumFacing) getWorld().getBlockState(pos).getValue(BlockSecurityCamera.FACING), -1), getWorld().getBlockState(pos).getBlock());
            return itemstack;
        } else {
            itemstack = itemStacks[par1].splitStack(par2);
            if (itemStacks[par1].stackSize == 0)
                itemStacks[par1] = null;
            onModuleRemoved(itemstack, ((ItemModule) itemstack.getItem()).getModule());
            createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { itemstack, ((ItemModule) itemstack.getItem()).getModule() }, this);
            if (this instanceof TileEntitySecurityCamera)
                getWorld().notifyNeighborsOfStateChange(pos.offset((EnumFacing) getWorld().getBlockState(pos).getValue(BlockSecurityCamera.FACING), -1), getWorld().getBlockState(pos).getBlock());
            return itemstack;
        }
    } else
        return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera)

Example 3 with TileEntitySecurityCamera

use of net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera in project SecurityCraft by Geforce132.

the class CustomizableSCTE method safeDecrStackSize.

/**
 * Copy of decrStackSize which can't be overrided by subclasses.
 */
public ItemStack safeDecrStackSize(int par1, int par2) {
    if (itemStacks[par1] != null) {
        ItemStack itemstack;
        if (itemStacks[par1].stackSize <= par2) {
            itemstack = itemStacks[par1];
            itemStacks[par1] = null;
            onModuleRemoved(itemstack, ((ItemModule) itemstack.getItem()).getModule());
            createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { itemstack, ((ItemModule) itemstack.getItem()).getModule() }, this);
            if (this instanceof TileEntitySecurityCamera)
                getWorld().notifyNeighborsOfStateChange(pos.offset((EnumFacing) getWorld().getBlockState(pos).getValue(BlockSecurityCamera.FACING), -1), getWorld().getBlockState(pos).getBlock());
            return itemstack;
        } else {
            itemstack = itemStacks[par1].splitStack(par2);
            if (itemStacks[par1].stackSize == 0)
                itemStacks[par1] = null;
            onModuleRemoved(itemstack, ((ItemModule) itemstack.getItem()).getModule());
            createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { itemstack, ((ItemModule) itemstack.getItem()).getModule() }, this);
            if (this instanceof TileEntitySecurityCamera)
                getWorld().notifyNeighborsOfStateChange(pos.offset((EnumFacing) getWorld().getBlockState(pos).getValue(BlockSecurityCamera.FACING), -1), getWorld().getBlockState(pos).getBlock());
            return itemstack;
        }
    } else
        return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera)

Example 4 with TileEntitySecurityCamera

use of net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera in project SecurityCraft by Geforce132.

the class ContainerCustomizeBlock method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer par1, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) inventorySlots.get(par2);
    if (slot != null && slot.getHasStack()) {
        ItemStack itemstack1 = slot.getStack();
        if (!(itemstack1.getItem() instanceof ItemModule))
            return null;
        itemstack = itemstack1.copy();
        if (par2 < tileEntity.getSizeInventory()) {
            if (!mergeItemStack(itemstack1, 0, 35, true))
                return null;
            else {
                tileEntity.onModuleRemoved(itemstack1, EnumCustomModules.getModuleFromStack(itemstack1));
                tileEntity.createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { itemstack1, EnumCustomModules.getModuleFromStack(itemstack1) }, tileEntity);
                if (tileEntity instanceof TileEntitySecurityCamera)
                    tileEntity.getWorld().notifyNeighborsOfStateChange(tileEntity.getPos().offset((EnumFacing) tileEntity.getWorld().getBlockState(tileEntity.getPos()).getValue(BlockSecurityCamera.FACING), -1), tileEntity.getWorld().getBlockState(tileEntity.getPos()).getBlock());
            }
        } else if (itemstack1.getItem() != null && itemstack1.getItem() instanceof ItemModule && tileEntity.getAcceptedModules().contains(EnumCustomModules.getModuleFromStack(itemstack1)) && !mergeItemStack(itemstack1, 0, tileEntity.getSizeInventory(), false))
            return null;
        if (itemstack1.stackSize == 0)
            slot.putStack((ItemStack) null);
        else
            slot.onSlotChanged();
        if (itemstack1.stackSize == itemstack.stackSize)
            return null;
        slot.onPickupFromSlot(par1, itemstack1);
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) ItemModule(net.geforcemods.securitycraft.items.ItemModule) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera)

Aggregations

TileEntitySecurityCamera (net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera)4 ItemStack (net.minecraft.item.ItemStack)4 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)1 ItemModule (net.geforcemods.securitycraft.items.ItemModule)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Slot (net.minecraft.inventory.Slot)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1