Search in sources :

Example 31 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemKeyPanel method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (BlockUtils.getBlock(worldIn, pos) == mod_SecurityCraft.frame) {
            Owner owner = ((IOwnable) worldIn.getTileEntity(pos)).getOwner();
            EnumFacing enumfacing = worldIn.getBlockState(pos).getValue(BlockKeypad.FACING);
            worldIn.setBlockState(pos, mod_SecurityCraft.keypad.getDefaultState().withProperty(BlockKeypad.FACING, enumfacing).withProperty(BlockKeypad.POWERED, false));
            ((IOwnable) worldIn.getTileEntity(pos)).getOwner().set(owner.getUUID(), owner.getName());
            stack.stackSize -= 1;
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) EnumFacing(net.minecraft.util.EnumFacing) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Example 32 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemMineRemoteAccessTool method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (BlockUtils.getBlock(worldIn, pos) instanceof IExplosive) {
            if (!isMineAdded(stack, worldIn, pos)) {
                int availSlot = this.getNextAvaliableSlot(stack);
                if (availSlot == 0) {
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.noSlots"), TextFormatting.RED);
                    return EnumActionResult.FAIL;
                }
                if (worldIn.getTileEntity(pos) instanceof IOwnable && !((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.cantBind"), TextFormatting.RED);
                    return EnumActionResult.FAIL;
                }
                if (stack.getTagCompound() == null) {
                    stack.setTagCompound(new NBTTagCompound());
                }
                stack.getTagCompound().setIntArray(("mine" + availSlot), new int[] { BlockUtils.fromPos(pos)[0], BlockUtils.fromPos(pos)[1], BlockUtils.fromPos(pos)[2] });
                mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
            } else {
                this.removeTagFromItemAndUpdate(stack, pos, playerIn);
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
            }
        } else {
            playerIn.openGui(mod_SecurityCraft.instance, GuiHandler.MRAT_MENU_ID, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) IExplosive(net.geforcemods.securitycraft.api.IExplosive) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)

Aggregations

IOwnable (net.geforcemods.securitycraft.api.IOwnable)32 Owner (net.geforcemods.securitycraft.api.Owner)13 TileEntity (net.minecraft.tileentity.TileEntity)10 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)8 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)6 PacketCUpdateNBTTag (net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)6 Block (net.minecraft.block.Block)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 IExplosive (net.geforcemods.securitycraft.api.IExplosive)5 EnumCustomModules (net.geforcemods.securitycraft.misc.EnumCustomModules)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemBlock (net.minecraft.item.ItemBlock)4 INameable (net.geforcemods.securitycraft.api.INameable)3 BlockReinforcedDoor (net.geforcemods.securitycraft.blocks.BlockReinforcedDoor)3 CameraView (net.geforcemods.securitycraft.misc.CameraView)3 TileEntitySCTE (net.geforcemods.securitycraft.api.TileEntitySCTE)2 BlockLaserBlock (net.geforcemods.securitycraft.blocks.BlockLaserBlock)2 EntitySecurityCamera (net.geforcemods.securitycraft.entity.EntitySecurityCamera)2 CustomHoverChecker (net.geforcemods.securitycraft.gui.components.CustomHoverChecker)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2