local genuine_ISVehicleMechanics_onRightMouseUp = ISVehicleMechanics.onRightMouseUp
function ISVehicleMechanics:onRightMouseUp(x, y)
    self.inhibitAutoMechanics_doPartContextMenu = true
    genuine_ISVehicleMechanics_onRightMouseUp(self, x, y);
    self.inhibitAutoMechanics_doPartContextMenu = false

    if not self.context then -- in cases doPart never created the menu, we do it
        self.context = ISContextMenu.get(self.playerNum, x + self:getAbsoluteX(), y + self:getAbsoluteY())
    end
    self:noEnginePart()
end

function ISVehicleMechanics:noEnginePart()
    if (self.vehicle and (GetPanzerType(self.vehicle))) then
        local option = self.context:getOptionFromName(getText("IGUI_TakeEngineParts"))
        if option then
            self.context:removeOptionByName(getText("IGUI_TakeEngineParts"))
        end
    end
end
local genuine_ISVehicleMechanics_onListRightMouseUp = ISVehicleMechanics.onListRightMouseUp
function ISVehicleMechanics:onListRightMouseUp(x, y)
    genuine_ISVehicleMechanics_onListRightMouseUp(self, x, y);

    local trueself = self.parent; -- PZ mixes ISVehicleMechanics uses between parent and children, onListRightMouseUp is called on children. but children are not initialized.
    if trueself and not trueself.context then -- in cases doPart never created the menu, we do it
        trueself.context = ISContextMenu.get(trueself.playerNum, x + self:getX() + trueself:getAbsoluteX(),
            y + self:getY() + trueself:getAbsoluteY())
        trueself:noEnginePart()
    end
end
local genuine_ISVehicleMechanics_doPartContextMenu = ISVehicleMechanics.doPartContextMenu
function ISVehicleMechanics:doPartContextMenu(part, x, y)
    genuine_ISVehicleMechanics_doPartContextMenu(self, part, x, y);
    if self.context and not self.inhibitAutoMechanics_doPartContextMenu then
        self:noEnginePart()
    end
end
